Exemplo n.º 1
0
        void Update()
        {
            FogOfWar fow = FogOfWar.GetFogOfWarTeam(team);

            if (fow == null)
            {
                Debug.LogWarning("There is no Fog Of War team for team #" + team.ToString());
                return;
            }

            bool visible = fow.GetFogValue(_transform.position) < minFogStrength;

            if (_renderer != null)
            {
                _renderer.enabled = visible;
            }
            if (_graphic != null)
            {
                _graphic.enabled = visible;
            }
            if (_canvas != null)
            {
                _canvas.enabled = visible;
            }
        }
Exemplo n.º 2
0
        void OnGUI()
        {
            if (!showGui || _fog.fogTexture == null)
            {
                return;
            }

            bool minimal = Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer;

            if (_texture == null)
            {
                _texture          = new Texture2D(_fog.fogTexture.width, _fog.fogTexture.height);
                _texture.wrapMode = TextureWrapMode.Clamp;
            }

            if (_panelStyle == null)
            {
                Texture2D panelTex = new Texture2D(1, 1);
                panelTex.SetPixels32(new Color32[] { new Color32(255, 255, 255, 64) });
                panelTex.Apply();
                _panelStyle = new GUIStyle();
                _panelStyle.normal.background = panelTex;
            }

            byte[]    original = _fog.fogTexture.GetRawTextureData();
            Color32[] pixels   = new Color32[original.Length];
            for (int i = 0; i < pixels.Length; ++i)
            {
                pixels[i] = original[i] < 255 ? new Color32(0, 255, 50, 255) : new Color32(0, 0, 0, 255);
            }
            _texture.SetPixels32(pixels);
            _texture.Apply();

            int panelwidth = (minimal ? 128 : 256) + 20;

            // draw panel
            GUI.Box(new Rect(0, 0, panelwidth, Screen.height), "", _panelStyle);
            GUILayout.BeginArea(new Rect(10, 10, panelwidth - 20, Screen.height - panelwidth - 20));

            if (!minimal)
            {
                GUILayout.Label("Partial Fog Amount:");
                _fog.partialFogAmount = GUILayout.HorizontalSlider(_fog.partialFogAmount, 0.0f, 1.0f);

                _fog.pointFiltering = GUILayout.Toggle(_fog.pointFiltering, "Point Filtering");

                GUILayout.Label("Fog Color:");
                _fog.fogColor.r = GUILayout.HorizontalSlider(_fog.fogColor.r, 0.0f, 1.0f);
                _fog.fogColor.g = GUILayout.HorizontalSlider(_fog.fogColor.g, 0.0f, 1.0f);
                _fog.fogColor.b = GUILayout.HorizontalSlider(_fog.fogColor.b, 0.0f, 1.0f);
            }

            if (GUILayout.Button("Reset Fog"))
            {
                _fog.SetAll(255);
            }

            if (_units.Count > 0)
            {
                GUILayout.Label("Selected Unit Vision Radius:");
                _units[_units.Count - 1].unit.circleRadius = GUILayout.HorizontalSlider(_units[_units.Count - 1].unit.circleRadius, 3.0f, 20.0f);
            }

            if (!minimal)
            {
                GUILayout.Label("\n-- Controls --");
                GUILayout.Label("Move Camera:\tWASD/Arrow Keys");
                GUILayout.Label("Select Unit:\tLeft Mouse Button");
                GUILayout.Label("Move Unit:\t\tMiddle/Right Mouse Button");
            }

            GUILayout.Label("\n-- Stats --");
            GUILayout.Label("Explored :\t" + Mathf.RoundToInt(_fog.ExploredArea() * 100) + "%");
            GUILayout.Label("Visible Enemies:\t" + _visibleEnemies);

            GUILayout.EndArea();

            // draw map
            GUI.DrawTexture(new Rect(10, Screen.height - panelwidth + 10, panelwidth - 20, panelwidth - 20), _texture);

            DrawOnMap("C", _cameraTransform.position, panelwidth);
            for (int i = 0; i < originalUnits.Length; ++i)
            {
                DrawOnMap("U", originalUnits[i].transform.position, panelwidth);
            }

            _visibleEnemies = 0;
            for (int i = 0; i < enemyUnits.Length; ++i)
            {
                if (_fog.GetFogValue(enemyUnits[i].position) < 128)
                {
                    ++_visibleEnemies;
                    DrawOnMap("E", enemyUnits[i].position, panelwidth);
                }
            }
        }