FogOfWarShape CreateShape(FogOfWar fow) { if (shapeType == FogOfWarShapeType.Circle) { FogOfWarShapeCircle shape = new FogOfWarShapeCircle(); FillShape(fow, shape); shape.innerRadius = innerRadius; shape.angle = angle; return(shape); } else if (shapeType == FogOfWarShapeType.Box) { FogOfWarShapeBox shape = new FogOfWarShapeBox(); FillShape(fow, shape); return(shape); } else if (shapeType == FogOfWarShapeType.Texture) { if (texture == null) { return(null); } FogOfWarShapeTexture shape = new FogOfWarShapeTexture(); FillShape(fow, shape); shape.texture = texture; shape.rotateToForward = rotateToForward; return(shape); } return(null); }
protected override void DrawCircle(FogOfWarShapeCircle shape) { int fogradius = Mathf.RoundToInt(shape.radius * _map.pixelSize); int fogradiussqr = fogradius * fogradius; DrawInfo info = new DrawInfo(_map, shape, fogradius, fogradius); // view angle stuff float dotangle = 1 - shape.angle / 90; for (int y = info.yMin; y <= info.yMax; ++y) { for (int x = info.xMin; x <= info.xMax; ++x) { // is pixel within circle radius Vector2 centeroffset = new Vector2(x, y) - info.fogCenterPos; if (shape.visibleCells == null && centeroffset.sqrMagnitude >= fogradiussqr) { continue; } // check if in view angle if (dotangle > -0.99f && Vector2.Dot(centeroffset.normalized, info.fogForward) <= dotangle) { continue; } // can see pixel Vector2i offset = new Vector2i(x, y) - info.fogEyePos; if (!LineOfSightCanSee(shape, offset.vector2, fogradius)) { continue; } if (!LineOfSightCanSeeCell(shape, offset)) { continue; } Unfog(x, y, shape.GetFalloff(centeroffset.magnitude / (_map.pixelSize * shape.radius))); } } }
protected abstract void DrawCircle(FogOfWarShapeCircle shape);