void SaveChunks()
        {
            // save all visible chunks
            byte[] currentdata = new byte[_valuesPerMap];
            _fogOfWar.GetCurrentFogValues(ref currentdata);

            byte[] totaldata = new byte[_valuesPerMap];
            _fogOfWar.GetTotalFogValues(ref totaldata);

            for (int y = 0; y < 2; ++y)
            {
                for (int x = 0; x < 2; ++x)
                {
                    SaveChunk(currentdata, totaldata, x, y);
                }
            }
        }
Exemplo n.º 2
0
        void LateUpdate()
        {
            FogOfWarTeam fow = FogOfWarTeam.GetTeam(team);

            if (fow == null)
            {
                return;
            }

            // setup texture
            if (_texture == null || _texture.width != fow.mapResolution.x || _texture.height != fow.mapResolution.y)
            {
                if (_texture != null)
                {
                    Destroy(_texture);
                }

                _texture      = new Texture2D(fow.mapResolution.x, fow.mapResolution.y, TextureFormat.ARGB32, false, false);
                _texture.name = "FogOfWarMinimap";
                _fogValues    = new byte[fow.mapResolution.x * fow.mapResolution.y];
                _pixels       = new Color32[fow.mapResolution.x * fow.mapResolution.y];

                GetComponent <RawImage>().texture = _texture;
                if (aspectRatioFitter != null)
                {
                    aspectRatioFitter.aspectRatio = (float)fow.mapResolution.x / fow.mapResolution.y;
                }
            }

            // fog
            fow.GetTotalFogValues(ref _fogValues);
            for (int i = 0; i < _fogValues.Length; ++i)
            {
                int r = (fogColor.r - nonFogColor.r) * _fogValues[i] / 255 + nonFogColor.r;
                int g = (fogColor.g - nonFogColor.g) * _fogValues[i] / 255 + nonFogColor.g;
                int b = (fogColor.b - nonFogColor.b) * _fogValues[i] / 255 + nonFogColor.b;
                int a = (fogColor.a - nonFogColor.a) * _fogValues[i] / 255 + nonFogColor.a;
                _pixels[i] = new Color32((byte)r, (byte)g, (byte)b, (byte)a);
            }

            // units
            byte opponentminvisibility = (byte)(opponentMinFogStrength * 255);

            for (int i = 0; i < FogOfWarUnit.registeredUnits.Count; ++i)
            {
                FogOfWarUnit unit = FogOfWarUnit.registeredUnits[i];
                if (unit.team == team)
                {
                    DrawIconOnMap(fow, unit.transform.position, unitColor);
                }
                else
                {
                    DrawIconOnMap(fow, unit.transform.position, enemyColor, opponentminvisibility);
                }
            }

            // camera
            if (camera != null)
            {
                DrawIconOnMap(fow, camera.transform.position, cameraColor);
            }

            // apply to texture
            _texture.SetPixels32(_pixels);
            _texture.Apply(false, false);
        }