Esempio n. 1
0
        FogOfWarShape CreateShape()
        {
            if (shapeType == FogOfWarShapeType.Circle)
            {
                FogOfWarShapeCircle shape = new FogOfWarShapeCircle();
                FillShape(shape);
                shape.innerRadius = innerRadius;
                shape.angle       = angle;
                return(shape);
            }
            else if (shapeType == FogOfWarShapeType.Box)
            {
                FogOfWarShapeBox shape = new FogOfWarShapeBox();
                FillShape(shape);
                return(shape);
            }
            else if (shapeType == FogOfWarShapeType.Texture)
            {
                if (texture == null)
                {
                    return(null);
                }

                FogOfWarShapeTexture shape = new FogOfWarShapeTexture();
                FillShape(shape);
                shape.texture         = texture;
                shape.rotateToForward = rotateToForward;
                return(shape);
            }
            return(null);
        }
Esempio n. 2
0
        protected override void DrawCircle(FogOfWarShapeCircle shape)
        {
            int      fogradius         = Mathf.RoundToInt(shape.radius * _map.pixelSize);
            int      fogradiussqr      = fogradius * fogradius;
            DrawInfo info              = new DrawInfo(_map, shape);
            float    lineofsightradius = shape.CalculateMaxLineOfSightDistance() * _map.pixelSize;

            // view angle stuff
            float dotangle    = 1 - shape.angle / 90;
            bool  usedotangle = dotangle > -0.99f;

            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 (usedotangle && Vector2.Dot(centeroffset.normalized, info.fogForward) <= dotangle)
                    {
                        continue;
                    }

                    // can see pixel
                    Vector2i offset = new Vector2i(x, y) - info.fogEyePos;
                    if (!LineOfSightCanSee(shape, offset.vector2, lineofsightradius))
                    {
                        continue;
                    }

                    if (!LineOfSightCanSeeCell(shape, offset))
                    {
                        continue;
                    }

                    Unfog(x, y, shape.GetFalloff(centeroffset.magnitude / lineofsightradius));
                }
            }
        }
Esempio n. 3
0
 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();
         shape.texture         = texture;
         shape.hasTexture      = texture != null;
         shape.rotateToForward = rotateToForward;
         FillShape(fow, shape);
         return(shape);
     }
     return(null);
 }
Esempio n. 4
0
 protected abstract void DrawCircle(FogOfWarShapeCircle shape);