Files
2026-02-21 16:45:37 +08:00

115 lines
2.9 KiB
C#

using UnityEngine;
namespace VolumetricFogAndMist
{
public class DemoFogOfWar : MonoBehaviour
{
private bool fogCuttingOn = true;
private VolumetricFog fog;
private void Start()
{
fog = VolumetricFog.instance;
fog.fogOfWarEnabled = fogCuttingOn;
fog.ResetFogOfWar();
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.F))
{
switch (fog.preset)
{
case FOG_PRESET.Clear:
fog.preset = FOG_PRESET.Mist;
break;
case FOG_PRESET.Mist:
fog.preset = FOG_PRESET.WindyMist;
break;
case FOG_PRESET.WindyMist:
fog.preset = FOG_PRESET.GroundFog;
break;
case FOG_PRESET.GroundFog:
fog.preset = FOG_PRESET.FrostedGround;
break;
case FOG_PRESET.FrostedGround:
fog.preset = FOG_PRESET.FoggyLake;
break;
case FOG_PRESET.FoggyLake:
fog.preset = FOG_PRESET.Fog;
break;
case FOG_PRESET.Fog:
fog.preset = FOG_PRESET.HeavyFog;
break;
case FOG_PRESET.HeavyFog:
fog.preset = FOG_PRESET.LowClouds;
break;
case FOG_PRESET.LowClouds:
fog.preset = FOG_PRESET.SeaClouds;
break;
case FOG_PRESET.SeaClouds:
fog.preset = FOG_PRESET.Smoke;
break;
case FOG_PRESET.Smoke:
fog.preset = FOG_PRESET.ToxicSwamp;
break;
case FOG_PRESET.ToxicSwamp:
fog.preset = FOG_PRESET.SandStorm1;
break;
case FOG_PRESET.SandStorm1:
fog.preset = FOG_PRESET.SandStorm2;
break;
case FOG_PRESET.SandStorm2:
fog.preset = FOG_PRESET.Mist;
break;
}
}
else if (Input.GetKeyDown(KeyCode.T))
{
fog.enabled = !fog.enabled;
}
else if (Input.GetKeyDown(KeyCode.C))
{
fogCuttingOn = !fogCuttingOn;
fog.fogOfWarEnabled = fogCuttingOn;
fog.ResetFogOfWar();
}
else if (Input.GetKeyDown(KeyCode.R))
{
fog.ResetFogOfWar();
}
if (fogCuttingOn)
{
fog.SetFogOfWarAlpha(Camera.main.transform.position, 4f, 0f);
}
}
private void AssignCustomTexture()
{
VolumetricFog instance = VolumetricFog.instance;
Texture2D texture2D = Resources.Load<Texture2D>("Textures/alphaDemo");
Color32[] pixels = texture2D.GetPixels32();
instance.fogOfWarTextureSize = 64;
instance.fogOfWarTextureData = pixels;
}
private void OnGUI()
{
Rect position = new Rect(10f, 10f, Screen.width - 20, 30f);
GUI.Label(position, "Move around with WASD or cursor keys, space to jump");
position = new Rect(10f, 30f, Screen.width - 20, 30f);
GUI.Label(position, "F key to change fog style, T to toggle fog on/off, C to toggle fog cutting");
position = new Rect(10f, 50f, Screen.width - 20, 30f);
GUI.Label(position, "R to reset fog.");
position = new Rect(10f, 75f, Screen.width - 20, 30f);
GUI.Label(position, "Current fog preset: " + VolumetricFog.instance.GetCurrentPresetName());
if (fogCuttingOn)
{
position = new Rect(10f, 95f, Screen.width - 20, 30f);
GUI.Label(position, "*** FOG CUTTING ON ***");
}
}
}
}