Пример #1
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();
                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);
        }
Пример #2
0
        void DrawRotatedTexture(FogOfWarShapeTexture shape)
        {
            if (shape.texture == null)
            {
                return;
            }

            // convert size to fog space
            float    size      = new Vector2(shape.radius, shape.radius).magnitude *_map.pixelSize;
            Vector2  sizemul   = new Vector2(size / (shape.radius * _map.pixelSize), size / (shape.radius * _map.pixelSize));
            float    fogradius = size;
            DrawInfo info      = new DrawInfo(_map, shape, size, size);

            // rotation stuff
            float sin = Mathf.Sin(info.forwardAngle);
            float cos = Mathf.Cos(info.forwardAngle);

            for (int y = info.yMin; y < info.yMax; ++y)
            {
                for (int x = info.xMin; x < info.xMax; ++x)
                {
                    // get rotated uvs
                    float u = Mathf.InverseLerp(info.xMin, info.xMax, x) - 0.5f;
                    float v = Mathf.InverseLerp(info.yMin, info.yMax, y) - 0.5f;

                    float uu = (u * cos - v * sin) * sizemul.x + 0.5f;
                    float vv = (v * cos + u * sin) * sizemul.y + 0.5f;
                    if (uu < 0 || uu >= 1 || vv < 0 || vv >= 1)
                    {
                        continue;
                    }

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

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

                    // read texture
                    Unfog(x, y, SampleTexture(shape.texture, uu, vv));
                }
            }
        }
Пример #3
0
        protected override void DrawTexture(FogOfWarShapeTexture shape)
        {
            if (shape.texture == null)
            {
                return;
            }

            if (shape.rotateToForward)
            {
                DrawRotatedTexture(shape);
                return;
            }

            // convert size to fog space
            float    fogradius = shape.radius * _map.pixelSize;
            DrawInfo info      = new DrawInfo(_map, shape, shape.radius * _map.pixelSize, shape.radius * _map.pixelSize);

            for (int y = info.yMin; y <= info.yMax; ++y)
            {
                for (int x = info.xMin; x <= info.xMax; ++x)
                {
                    // can see pixel
                    Vector2i offset = new Vector2i(x, y) - info.fogEyePos;
                    if (!LineOfSightCanSee(shape, offset.vector2, fogradius))
                    {
                        continue;
                    }

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

                    // read texture
                    float u = Mathf.InverseLerp(info.xMin, info.xMax, x);
                    float v = Mathf.InverseLerp(info.yMin, info.yMax, y);
                    Unfog(x, y, SampleTexture(shape.texture, u, v));
                }
            }
        }
Пример #4
0
 protected abstract void DrawTexture(FogOfWarShapeTexture shape);