123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using UnityEngine;
- namespace COM3D2.MeidoPhotoStudio.Plugin
- {
- internal class FogEffectManager : IEffectManager
- {
- public const string header = "EFFECT_FOG";
- private GlobalFog Fog { get; set; }
- public bool Ready { get; private set; }
- public bool Active { get; private set; }
- public static float InitialDistance { get; private set; } = 4f;
- public static float InitialDensity { get; private set; } = 1f;
- public static float InitialHeightScale { get; private set; } = 1f;
- public static float InitialHeight { get; private set; } = 0f;
- public static Color InitialColour { get; private set; } = Color.white;
- private float distance;
- public float Distance
- {
- get => distance;
- set => distance = Fog.startDistance = value;
- }
- private float density;
- public float Density
- {
- get => density;
- set => density = Fog.globalDensity = value;
- }
- private float heightScale;
- public float HeightScale
- {
- get => heightScale;
- set => heightScale = Fog.heightScale = value;
- }
- private float height;
- public float Height
- {
- get => height;
- set => height = Fog.height = value;
- }
- public float FogColourRed
- {
- get => FogColour.r;
- set
- {
- Color fogColour = FogColour;
- FogColour = new Color(value, fogColour.g, fogColour.b);
- }
- }
- public float FogColourGreen
- {
- get => FogColour.g;
- set
- {
- Color fogColour = FogColour;
- FogColour = new Color(fogColour.r, value, fogColour.b);
- }
- }
- public float FogColourBlue
- {
- get => FogColour.b;
- set
- {
- Color fogColour = FogColour;
- FogColour = new Color(fogColour.r, fogColour.g, value);
- }
- }
- private Color fogColour;
- public Color FogColour
- {
- get => fogColour;
- set => fogColour = Fog.globalFogColor = value;
- }
- public void Serialize(System.IO.BinaryWriter binaryWriter)
- {
- binaryWriter.Write(header);
- binaryWriter.Write(Distance);
- binaryWriter.Write(Density);
- binaryWriter.Write(HeightScale);
- binaryWriter.Write(Height);
- binaryWriter.WriteColour(FogColour);
- binaryWriter.Write(Active);
- }
- public void Deserialize(System.IO.BinaryReader binaryReader)
- {
- Distance = binaryReader.ReadSingle();
- Density = binaryReader.ReadSingle();
- HeightScale = binaryReader.ReadSingle();
- Height = binaryReader.ReadSingle();
- FogColour = binaryReader.ReadColour();
- SetEffectActive(binaryReader.ReadBoolean());
- }
- public void Activate()
- {
- if (Fog == null)
- {
- Fog = GameMain.Instance.MainCamera.GetOrAddComponent<GlobalFog>();
- if (Fog.fogShader == null) Fog.fogShader = Shader.Find("Hidden/GlobalFog");
- Distance = InitialDistance;
- Density = InitialDensity;
- HeightScale = InitialHeightScale;
- Height = InitialHeight;
- FogColour = InitialColour;
- }
- }
- public void Deactivate()
- {
- Distance = InitialDistance;
- Density = InitialDensity;
- HeightScale = InitialHeightScale;
- Height = InitialHeight;
- FogColour = InitialColour;
- Fog.enabled = false;
- Active = false;
- }
- public void Reset()
- {
- Fog.startDistance = InitialDistance;
- Fog.globalDensity = InitialDensity;
- Fog.heightScale = InitialHeightScale;
- Fog.height = InitialHeight;
- Fog.globalFogColor = InitialColour;
- }
- public void SetEffectActive(bool active)
- {
- Fog.enabled = active;
- this.Active = active;
- if (this.Active)
- {
- Fog.startDistance = Distance;
- Fog.globalDensity = Density;
- Fog.heightScale = HeightScale;
- Fog.height = Height;
- Fog.globalFogColor = FogColour;
- }
- else Reset();
- }
- public void Update() { }
- }
- }
|