Exemplo n.º 1
0
 public SecondaryLineOfSight(LineOfSightInfo info, PrimaryLineOfSight parent)
 {
     Info   = info;
     Parent = parent;
     alpha  = parent.alpha;
     X      = parent.x;
     Y      = parent.y;
 }
 public SecondaryLineOfSight(LineOfSightInfo info, PrimaryLineOfSight parent)
 {
     Info = info;
     Parent = parent;
     alpha = parent.alpha;
     X = parent.x;
     Y = parent.y;
 }
Exemplo n.º 3
0
        void ModifyFog(float[,] alphaMap, Vector3 position, float minRadius, float maxRadius, float cone, float angle, float strength, float preFalloff, float falloff, bool invert)
        {
            Vector2 texturePosition = WorldToPixel(position);
            float minPixelRadius = Mathf.Min(minRadius * Definition, Mathf.Floor(mapDiagonal / 2 - 1));
            float maxPixelRadius = Mathf.Min(maxRadius * Definition, Mathf.Floor(mapDiagonal / 2 - 1));
            float adjustedPrefalloff = preFalloff.Pow(1F / Definition);
            float adjustedFalloff = falloff.Pow(1F / Definition);
            bool insideRect = Area.Contains(position);
            int x = (int)texturePosition.x.Round();
            int y = (int)texturePosition.y.Round();

            if (maxPixelRadius <= 0 || cone <= 0 || strength <= 0 || FadeSpeed <= 0)
                return;

            if (x >= 0 && x < alphaMap.GetLength(0) && y >= 0 && y < alphaMap.GetLength(1))
            {
                alphaMap[(int)texturePosition.x.Round(), (int)texturePosition.y.Round()] = invert ? 1 - strength : strength;
            }

            List<LineOfSightInfo> centerInfos = currentLineInfos[0, 0];
            float halfCone = cone / 2;

            for (int i = 0; i < centerInfos.Count; i++)
            {
                float lineAngle = i * 45;
                float deltaAngle = Mathf.Abs(Mathf.DeltaAngle(lineAngle, angle));
                float difference = deltaAngle - halfCone;
                float adjustedStrength = strength * (1 - Mathf.Clamp01(difference / 45)) * Mathf.Clamp01(halfCone / 45);

                PrimaryLineOfSight lineOfSight = new PrimaryLineOfSight(centerInfos[i], x, y, minPixelRadius, maxPixelRadius, adjustedStrength, adjustedPrefalloff, adjustedFalloff, invert, alphaMap, currentHeightMap, currentLineInfos);

                if (insideRect || (position.x < Area.xMin && lineOfSight.info.DirectionX >= 0) || (position.x > Area.xMax && lineOfSight.info.DirectionX <= 0) || (position.y < Area.yMin && lineOfSight.info.DirectionY >= 0) || (position.y > Area.yMax && lineOfSight.info.DirectionY <= 0))
                    lineOfSight.Complete();
            }
        }