Esempio n. 1
0
        public SecondaryLineOfSight(LineOfSightInfo info, PrimaryLineOfSight parent)
        {
            this.info   = info;
            this.parent = parent;
            this.alpha  = parent.alpha;

            this.x = parent.x;
            this.y = parent.y;
        }
        public SecondaryLineOfSight(LineOfSightInfo info, PrimaryLineOfSight parent)
        {
            this.info = info;
            this.parent = parent;
            this.alpha = parent.alpha;

            this.x = parent.x;
            this.y = parent.y;
        }
Esempio 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();
                }
            }
        }