コード例 #1
0
    public void AddFaction()
    {
        System.Array revealFactions = System.Enum.GetValues(typeof(FogOfWar.Players));

        if (Factions.Count >= revealFactions.Length)
        {
            Debug.LogWarning("[UFoW] Cant add more Factions because the limit of " + revealFactions.Length + " is reached. Check the Documentation on how to add more Factions. (Default = 8)");
            return;
        }

        int     LevelSize = LevelWidth * LevelHeight;
        Faction f         = new Faction(LevelSize, Factions.Count);

        for (int i = 0; i < LevelSize; i++)
        {
            f.FogOfWarMapData[i] = new Color(0.0f, RevealOpacities.b, 0.0f, 0.0f);
        }

        f.FogTexture            = new Texture2D(LevelWidth, LevelHeight, TextureFormat.RGBA32, false);
        f.FogTexture.filterMode = FogTextureFilterMode;

        //Create a new RenderTexture to Blur the Fog
        f.BluredRenderTexture            = new RenderTexture(LevelWidth * UpSample, LevelHeight * UpSample, 0);
        f.BluredRenderTexture.filterMode = FogTextureFilterMode;

        f.ID             = Mathf.FloorToInt(Mathf.Pow(2, Factions.Count));
        f.RevealFactions = (FogOfWar.Players)f.ID;
        Factions.Add(f);
        FogOfWar.InitializeFogOfWar(LevelWidth, LevelHeight, Factions, RevealFaction);
    }
コード例 #2
0
    public void InitializeMaps()
    {
        SetUpShaderKeywords();

        FogOfWar.Reset();

        if (Factions.Count == 0)
        {
            AddFaction();
        }

        //1. FogOfWar Data
        FogOfWar.InitializeFogOfWar(LevelWidth, LevelHeight, Factions, RevealFaction);
        ShowFaction(RevealFaction);

        //Pass Reveal opacities
        FogOfWar.RevealOpacities = RevealOpacities;

        //2. ResistanceMap Data
        SetResistanceMap(ResitenceMapPath);

        foreach (Faction f in Factions)
        {
            f.BluredRenderTexture            = new RenderTexture(LevelWidth * UpSample, LevelHeight * UpSample, 0);
            f.BluredRenderTexture.filterMode = FogTextureFilterMode;
        }

        if (BlurFog == FogOfWar.FogQuality.Off)
        {
            Shader.SetGlobalTexture("FogOfWar", FogOfWar.Factions[FogOfWar.RevealFactionInt].FogTexture);
        }
        else
        {
            if (fogOfWarBlur == null)
            {
                fogOfWarBlur = gameObject.AddComponent <FogOfWarBlur>();
            }

            Shader.SetGlobalTexture("FogOfWar", FogOfWar.Factions[FogOfWar.RevealFactionInt].BluredRenderTexture);
        }

        //Pass Level width and height to Shaders
        Shader.SetGlobalFloat("LevelWidth", (float)LevelWidth);
        Shader.SetGlobalFloat("LevelHeight", (float)LevelHeight);
        Shader.SetGlobalFloat("Scale", PatchScale);
        Shader.SetGlobalVector("Origin", new Vector4(Origin.x, Origin.y, Origin.z, 0f));
        Shader.SetGlobalColor("FogColor", FogColor);
        Shader.SetGlobalFloat("FogSpeed", AnimatedFogSpeed);
        Shader.SetGlobalFloat("FogTiling", AnimatedFogTiling);
        Shader.SetGlobalFloat("FogIntensity", AnimatedFogIntensity);
        Shader.SetGlobalTexture("FogNoise", FogNoise);
    }
コード例 #3
0
    public void RemoveFaction(int i)
    {
        if (Factions.Count - 1 <= 0)
        {
            Debug.LogWarning("[UFoW] Could not remove Faction. Less than 1 Faction is not allowed.");
            return;
        }

        if (i < Factions.Count && Factions.Count > 0)
        {
            Factions.RemoveAt(i);
        }
        FogOfWar.InitializeFogOfWar(LevelWidth, LevelHeight, Factions, RevealFaction);
    }