using UnityEngine; /// /// 全局昼夜着色参数(由 CECSunMoon 在刷新 m_fDNFactor 后调用 Apply)。 /// Global day/night shader globals; CECSunMoon calls Apply after updating m_fDNFactor. /// [System.Serializable] public class GlobalShaderVariableSetting { [Range(0.0f, 1.0f)] public float nightControl; public Color ambientDayColor = Color.white; public Color dirLtColorDayColor = Color.white; public Color ambientNightColor = new Color(0.113f, 0.113f, 0.113f, 1f); public Color dirLtColorNightColor = new Color(0.123f, 0.123f, 0.123f, 1f); static readonly int AmbientDayColorHash = Shader.PropertyToID("_AmbientDayColor"); static readonly int DirLtColorDayColorHash = Shader.PropertyToID("_DirLtColorDayColor"); static readonly int AmbientNightColorHash = Shader.PropertyToID("_AmbientNightColor"); static readonly int DirLtColorNightColorHash = Shader.PropertyToID("_DirLtColorNightColor"); static readonly int NightColorControlHash = Shader.PropertyToID("_NightColorControl"); /// 0=昼 1=夜,与 PC m_fDNFactor 一致 // 0=day, 1=night, same as PC m_fDNFactor public void Apply(float nightColorControl) { nightControl = Mathf.Clamp01(nightColorControl); Shader.SetGlobalColor(AmbientDayColorHash, ambientDayColor); Shader.SetGlobalColor(DirLtColorDayColorHash, dirLtColorDayColor); Shader.SetGlobalColor(AmbientNightColorHash, ambientNightColor); Shader.SetGlobalColor(DirLtColorNightColorHash, dirLtColorNightColor); Shader.SetGlobalFloat(NightColorControlHash, nightControl); } }