public void BroadcastWeatherUpdate(CTSWeatherManager manager) { foreach (CTSWeatherController controller in this.m_controllerSet) { controller.ProcessWeatherUpdate(manager); } }
/// <summary> /// Process a weather update /// </summary> /// <param name="manager">The manager providing the update</param> public void ProcessWeatherUpdate(CTSWeatherManager manager) { //Make sure we have a terrain if (m_terrain == null) { m_terrain = GetComponent <Terrain>(); if (m_terrain == null) { Debug.Log("CTS Weather Controller must be connected to a terrain to work."); return; } } //Make sure we have a custom controller if (m_terrain.materialType != Terrain.MaterialType.Custom) { Debug.Log("CTS Weather Controller needs a CTS Material to work with."); return; } Material material = m_terrain.materialTemplate; if (material == null) { Debug.Log("CTS Weather Controller needs a Custom Material to work with."); return; } //Now update it material.SetFloat("_Snow_Amount", manager.SnowPower * 2f); material.SetFloat("_Snow_Min_Height", manager.SnowMinHeight); float shinyness = manager.RainPower * manager.MaxRainSmoothness; material.SetFloat("_Snow_Smoothness", shinyness); Color tint = Color.white; if (manager.Season < 1f) { tint = Color.Lerp(manager.WinterTint, manager.SpringTint, manager.Season); } else if (manager.Season < 2f) { tint = Color.Lerp(manager.SpringTint, manager.SummerTint, manager.Season - 1f); } else if (manager.Season < 3f) { tint = Color.Lerp(manager.SummerTint, manager.AutumnTint, manager.Season - 2f); } else { tint = Color.Lerp(manager.AutumnTint, manager.WinterTint, manager.Season - 3f); } for (int idx = 0; idx < 16; idx++) { material.SetVector(string.Format("_Texture_{0}_Color", idx), new Vector4(tint.r, tint.g, tint.b, shinyness)); } }
/// <summary> /// Called when we select this object /// </summary> void OnEnable() { //Check for target if (target == null) { return; } //Setup target m_manager = (CTSWeatherManager)target; }
/// <summary> /// Broadcast a weather update /// </summary> /// <param name="manager">The manager with the update</param> public void BroadcastWeatherUpdate(CTSWeatherManager manager) { //Periodically update this list RegisterAllControllers(); //And then broadcast to it for (int idx = 0; idx < m_controllerList.Count; idx++) { m_controllerList[idx].ProcessWeatherUpdate(manager); } }
/// <summary> /// Handle updates from world api /// </summary> /// <param name="changeArgs">Change arguements</param> public void OnWorldChanged(WorldChangeArgs changeArgs) { if (m_weatherManager == null) { m_weatherManager = GetComponent <CTSWeatherManager>(); } if (m_updateSnow && changeArgs.HasChanged(WorldConstants.WorldChangeEvents.SnowChanged)) { m_weatherManager.SnowPower = WorldManager.Instance.SnowPowerTerrain; m_weatherManager.SnowMinHeight = WorldManager.Instance.SnowMinHeight; } if (m_updateWetness && changeArgs.HasChanged(WorldConstants.WorldChangeEvents.RainChanged)) { m_weatherManager.RainPower = WorldManager.Instance.RainPowerTerrain; } if (m_updateSeasons && changeArgs.HasChanged(WorldConstants.WorldChangeEvents.SeasonChanged)) { m_weatherManager.Season = WorldManager.Instance.Season; } }
/// <summary> /// Set up connection to WAPI to drive CTS /// </summary> void Start() { CTSTerrainManager.Instance.RegisterAllShaders(true); CTSTerrainManager.Instance.RegisterAllControllers(true); m_weatherManager = GetComponent <CTSWeatherManager>(); ConnectToWorldAPI(); if (m_updateSnow) { m_weatherManager.SnowPower = WorldManager.Instance.SnowPowerTerrain; m_weatherManager.SnowMinHeight = WorldManager.Instance.SnowMinHeight; } if (m_updateWetness) { m_weatherManager.RainPower = WorldManager.Instance.RainPower; } if (m_updateSeasons) { m_weatherManager.Season = WorldManager.Instance.Season; } }
public void ProcessWeatherUpdate(CTSWeatherManager manager) { if (Object.op_Equality((Object)this.m_terrain, (Object)null)) { this.m_terrain = (Terrain)((Component)this).GetComponent <Terrain>(); if (Object.op_Equality((Object)this.m_terrain, (Object)null)) { Debug.Log((object)"CTS Weather Controller must be connected to a terrain to work."); return; } } if (this.m_terrain.get_materialType() != 3) { Debug.Log((object)"CTS Weather Controller needs a CTS Material to work with."); } else { Material materialTemplate = this.m_terrain.get_materialTemplate(); if (Object.op_Equality((Object)materialTemplate, (Object)null)) { Debug.Log((object)"CTS Weather Controller needs a Custom Material to work with."); } else { materialTemplate.SetFloat(CTSShaderID.Snow_Amount, manager.SnowPower * 2f); materialTemplate.SetFloat(CTSShaderID.Snow_Min_Height, manager.SnowMinHeight); float num = manager.RainPower * manager.MaxRainSmoothness; materialTemplate.SetFloat(CTSShaderID.Snow_Smoothness, num); Color.get_white(); Color color = (double)manager.Season >= 1.0 ? ((double)manager.Season >= 2.0 ? ((double)manager.Season >= 3.0 ? Color.Lerp(manager.AutumnTint, manager.WinterTint, manager.Season - 3f) : Color.Lerp(manager.SummerTint, manager.AutumnTint, manager.Season - 2f)) : Color.Lerp(manager.SpringTint, manager.SummerTint, manager.Season - 1f)) : Color.Lerp(manager.WinterTint, manager.SpringTint, manager.Season); for (int index = 0; index < 16; ++index) { materialTemplate.SetVector(CTSShaderID.Texture_X_Color[index], new Vector4((float)color.r, (float)color.g, (float)color.b, num)); } } } }
void Awake() { weatherModule = (CTS.CTSWeatherManager)FindObjectOfType(typeof(CTS.CTSWeatherManager)); tenkokuModule = (Tenkoku.Core.TenkokuModule)FindObjectOfType(typeof(Tenkoku.Core.TenkokuModule)); }
/// <summary> /// Editor UX /// </summary> public override void OnInspectorGUI() { #region Setup and introduction //Get the target m_manager = (CTSWeatherManager)target; //Set up the styles if (m_boxStyle == null) { m_boxStyle = new GUIStyle(GUI.skin.box); m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor; m_boxStyle.fontStyle = FontStyle.Bold; m_boxStyle.alignment = TextAnchor.UpperLeft; } if (m_wrapStyle == null) { m_wrapStyle = new GUIStyle(GUI.skin.label); m_wrapStyle.fontStyle = FontStyle.Normal; m_wrapStyle.wordWrap = true; } if (m_wrapHelpStyle == null) { m_wrapHelpStyle = new GUIStyle(GUI.skin.label); m_wrapHelpStyle.richText = true; m_wrapHelpStyle.wordWrap = true; } //Text intro GUILayout.BeginVertical(string.Format("CTS ({0}.{1})", CTSConstants.MajorVersion, CTSConstants.MinorVersion), m_boxStyle); if (m_globalHelp) { Rect rect = EditorGUILayout.BeginVertical(); //rect.y -= 10f; rect.x = rect.width - 10; rect.width = 25; rect.height = 20; if (GUI.Button(rect, "?-")) { m_globalHelp = !m_globalHelp; } EditorGUILayout.EndVertical(); } else { Rect rect = EditorGUILayout.BeginVertical(); //rect.y -= 10f; rect.x = rect.width - 10; rect.width = 25; rect.height = 20; if (GUI.Button(rect, "?+")) { m_globalHelp = !m_globalHelp; } EditorGUILayout.EndVertical(); } GUILayout.Space(20); EditorGUILayout.LabelField("Welcome to CTS Weather Manager. Click ? for help.", m_wrapStyle); DrawHelpSectionLabel("Overview"); if (m_globalHelp) { if (GUILayout.Button(GetLabel("View Online Tutorials & Docs"))) { Application.OpenURL("http://www.procedural-worlds.com/cts/"); } } GUILayout.EndVertical(); #endregion //Monitor for changes EditorGUI.BeginChangeCheck(); GUILayout.BeginVertical("Control", m_boxStyle); GUILayout.Space(20f); DrawHelpSectionLabel("Control"); GUILayout.BeginVertical(m_boxStyle); float rainPower = EditorGUILayout.Slider(GetLabel("Rain Power"), m_manager.RainPower, 0f, 1f); DrawHelpLabel("Rain Power"); float snowPower = EditorGUILayout.Slider(GetLabel("Snow Power"), m_manager.SnowPower, 0f, 1f); DrawHelpLabel("Snow Power"); float season = EditorGUILayout.Slider(GetLabel("Season"), m_manager.Season, 0f, 3.9999f); DrawHelpLabel("Season"); EditorGUI.indentLevel++; if (season < 1f) { EditorGUILayout.LabelField(string.Format("{0:0}% Winter {1:0}% Spring", (1f - season) * 100f, season * 100f)); } else if (season < 2f) { EditorGUILayout.LabelField(string.Format("{0:0}% Spring {1:0}% Summer", (2f - season) * 100f, (season - 1f) * 100f)); } else if (season < 3f) { EditorGUILayout.LabelField(string.Format("{0:0}% Summer {1:0}% Autumn", (3f - season) * 100f, (season - 2f) * 100f)); } else { EditorGUILayout.LabelField(string.Format("{0:0}% Autumn {1:0}% Winter", (4f - season) * 100f, (season - 3f) * 100f)); } EditorGUI.indentLevel--; GUILayout.EndVertical(); GUILayout.EndVertical(); GUILayout.BeginVertical("Settings", m_boxStyle); GUILayout.Space(20f); DrawHelpSectionLabel("Settings"); GUILayout.BeginVertical(m_boxStyle); float minSnowHeight = EditorGUILayout.FloatField(GetLabel("Min Snow Height"), m_manager.SnowMinHeight); DrawHelpLabel("Min Snow Height"); float maxSmoothness = EditorGUILayout.Slider(GetLabel("Max Smoothness"), m_manager.MaxRainSmoothness, 0f, 30f); DrawHelpLabel("Max Smoothness"); Color winterTint = EditorGUILayout.ColorField(GetLabel("Winter Tint"), m_manager.WinterTint, true, false, false, null); DrawHelpLabel("Winter Tint"); Color springTint = EditorGUILayout.ColorField(GetLabel("Spring Tint"), m_manager.SpringTint, true, false, false, null); DrawHelpLabel("Spring Tint"); Color summerTint = EditorGUILayout.ColorField(GetLabel("Summer Tint"), m_manager.SummerTint, true, false, false, null); DrawHelpLabel("Summer Tint"); Color autumnTint = EditorGUILayout.ColorField(GetLabel("Autumn Tint"), m_manager.AutumnTint, true, false, false, null); DrawHelpLabel("Autumn Tint"); GUILayout.EndVertical(); GUILayout.EndVertical(); //Handle changes if (EditorGUI.EndChangeCheck()) { CompleteTerrainShader.SetDirty(m_manager, false, false); //UX Settings m_manager.SnowPower = snowPower; m_manager.SnowMinHeight = minSnowHeight; m_manager.RainPower = rainPower; m_manager.Season = season; m_manager.MaxRainSmoothness = maxSmoothness; m_manager.WinterTint = winterTint; m_manager.SpringTint = springTint; m_manager.SummerTint = summerTint; m_manager.AutumnTint = autumnTint; } }