Exemple #1
0
        /// <summary>
        /// Fills a circle centered on spherePos location with fog using alpha (transparency) and custom width.
        /// </summary>
        /// <param name="spherePos">Sphere position.</param>
        /// <param name="alpha">Alpha in the range 0..1.</param>
        /// <param name="radius">Width in the range 0..1.</param>
        /// <param name="strength">Strength of the brush in the range 0..1.</param>
        public void SetFogOfWarAlpha(Vector3 spherePos, float alpha, float radius, float strength)
        {
            Vector2 latLon = Conversion.GetLatLonFromSpherePoint(spherePos);
            Vector2 uv     = Conversion.GetUVFromLatLon(latLon.x, latLon.y);

            SetFowAlpha(uv, alpha, radius, strength);
        }
Exemple #2
0
        /// <summary>
        /// Fills a region with fog using alpha (transparency) and custom width.
        /// </summary>
        /// <param name="spherePos">Sphere position.</param>
        /// <param name="alpha">Alpha in the range 0..1.</param>
        /// <param name="strength">Strength of the brush in the range 0..1.</param>
        public void SetFogOfWarAlpha(Region region, float alpha, float strength)
        {
            if (region == null)
            {
                return;
            }

            Rect rect = region.latlonRect2D;

            float   stepX  = rect.width * 0.2f;
            float   stepY  = rect.height * 0.2f;
            Vector2 pos    = new Vector2(rect.xMin, rect.yMin);
            float   radius = Mathf.Max(Mathf.Max(stepX, stepY) / overlayHeight, 0.001f);

            while (pos.y < rect.yMax)
            {
                if (region.Contains(pos))
                {
                    Vector2 uv = Conversion.GetUVFromLatLon(pos.x, pos.y);
                    SetFowAlpha(uv, alpha, radius, strength);
                }
                pos.x += stepX;
                if (pos.x > rect.xMax)
                {
                    pos.x  = rect.xMin;
                    pos.y += stepY;
                }
            }
        }
        Texture2D GetWorldTexture()
        {
            if (worldRect.x == latMin && worldRect.y == lonMin && worldRect.z == latMax && worldRect.w == lonMax || worldColors == null)
            {
                return(worldTex);
            }
            worldRect.x = latMin;
            worldRect.y = lonMin;
            worldRect.z = latMax;
            worldRect.w = lonMax;

            Vector2 uv0 = Conversion.GetUVFromLatLon(latMin, lonMin);
            Vector2 uv1 = Conversion.GetUVFromLatLon(latMax, lonMax);
            int     tx0 = (int)(uv0.x * tw);
            int     tx1 = (int)(uv1.x * tw);
            int     ty0 = (int)(uv0.y * th);
            int     ty1 = (int)(uv1.y * th);

            Array.Copy(worldColors, tmp, tmp.Length);
            for (int j = ty0; j <= ty1; j++)
            {
                for (int k = tx0; k <= tx1; k++)
                {
                    tmp [j * tw + k].g = (byte)(255 - tmp [j * tw + k].g);
                }
            }

            worldTex.SetPixels32(tmp);
            worldTex.Apply();
            return(worldTex);
        }
        IEnumerator Spread(int cityIndex)
        {
            City    city   = map.cities [cityIndex];
            Vector2 latlon = city.latlon;
            float   radius = 0.002f;

            switch (city.cityClass)
            {
            case CITY_CLASS.REGION_CAPITAL:
                radius += 0.004f;
                break;

            case CITY_CLASS.COUNTRY_CAPITAL:
                radius += 0.007f;
                break;
            }
            radius += Random.value * 0.005f;

            WaitForEndOfFrame w         = new WaitForEndOfFrame();
            Vector2           uv        = Conversion.GetUVFromLatLon(latlon.x, latlon.y);
            float             startTime = Time.time;
            float             t         = 0;
            const float       duration  = 4f;

            do
            {
                t = (Time.time - startTime) / duration;
                if (t > 1f)
                {
                    t = 1f;
                }
                rtVirusMap.Circle(uv, t * radius, circleMat);
                yield return(w);


                if (Random.value > 0.97f && bounces < MAX_BOUNCES)
                {
                    Bounce(latlon);
                }
            } while(t < 1f);
            Bounce(latlon);
            bounces--;
        }