/// <summary> /// Broadcast a profile update to all the shaders using it in the scene /// </summary> /// <param name="profile">Profile being updated</param> public void BroadcastProfileUpdate(CTSProfile profile) { //Make sure shaders are registered RegisterAllShaders(); //Also make sure weather is registered RegisterAllControllers(); //Can not do this on a null profile if (profile == null) { Debug.LogWarning("Cannot update shader on null profile."); return; } //Broadcast the update CompleteTerrainShader shader = null; for (int idx = 0; idx < m_shaderList.Count; idx++) { shader = m_shaderList[idx]; if (shader != null && shader.Profile != null) { if (shader.Profile.GetInstanceID() == profile.GetInstanceID()) { shader.UpdateMaterialAndShader(); } } } }
/// <summary> /// Broadcast a message to select this profile on all the specific terrain provided /// </summary> /// <param name="profile">Profile being selected</param> /// <param name="terrain">Terrain being selected</param> public void BroadcastProfileSelect(CTSProfile profile, Terrain terrain) { if (profile == null || terrain == null) { return; } CompleteTerrainShader shader = terrain.gameObject.GetComponent <CompleteTerrainShader>(); if (shader != null) { shader.Profile = profile; shader.UpdateMaterialAndShader(); } }
/// <summary> /// Editor UX /// </summary> public override void OnInspectorGUI() { //Set the target m_shader = (CompleteTerrainShader)target; if (m_shader == null) { return; } #region Setup and introduction //Set up the box style 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; } //Setup the wrap style 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.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. 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.Space(5); GUILayout.BeginVertical(m_boxStyle); CTSProfile profile = (CTSProfile)EditorGUILayout.ObjectField(GetLabel("Profile"), m_shader.Profile, typeof(CTSProfile), false); DrawHelpLabel("Profile"); EditorGUILayout.LabelField(GetLabel("Global NormalMap")); DrawHelpLabel("Global NormalMap"); EditorGUI.indentLevel++; bool autobakeNormalMap = EditorGUILayout.Toggle(GetLabel("AutoBake"), m_shader.AutoBakeNormalMap); DrawHelpLabel("AutoBake"); Texture2D globalNormal = (Texture2D)EditorGUILayout.ObjectField(GetLabel("Normal Map"), m_shader.NormalMap, typeof(Texture2D), false, GUILayout.Height(16f)); DrawHelpLabel("NormalMap"); EditorGUI.indentLevel--; EditorGUILayout.LabelField(GetLabel("Global ColorMap")); DrawHelpLabel("Global ColorMap"); EditorGUI.indentLevel++; bool autobakeColorMap = EditorGUILayout.Toggle(GetLabel("AutoBake"), m_shader.AutoBakeColorMap); DrawHelpLabel("AutoBake"); bool autoBakeGrassIntoColorMap = m_shader.AutoBakeGrassIntoColorMap; float autoBakeGrassMixStrength = m_shader.AutoBakeGrassMixStrength; float autoBakeGrassDarkenAmount = m_shader.AutoBakeGrassDarkenAmount; autoBakeGrassIntoColorMap = EditorGUILayout.Toggle(GetLabel("Bake Grass"), autoBakeGrassIntoColorMap); DrawHelpLabel("Bake Grass"); if (autoBakeGrassIntoColorMap) { EditorGUI.indentLevel++; autoBakeGrassMixStrength = EditorGUILayout.Slider(GetLabel("Grass Strength"), autoBakeGrassMixStrength, 0f, 1f); DrawHelpLabel("Grass Strength"); autoBakeGrassDarkenAmount = EditorGUILayout.Slider(GetLabel("Darken Strength"), autoBakeGrassDarkenAmount, 0f, 1f); DrawHelpLabel("Darken Strength"); EditorGUI.indentLevel--; } Texture2D globalColorMap = (Texture2D)EditorGUILayout.ObjectField(GetLabel("Color Map"), m_shader.ColorMap, typeof(Texture2D), false, GUILayout.Height(16f)); DrawHelpLabel("ColorMap"); EditorGUI.indentLevel--; bool useCutout = EditorGUILayout.Toggle(GetLabel("Use Cutout"), m_shader.UseCutout); DrawHelpLabel("Use Cutout"); float heightCutout = m_shader.CutoutHeight; Texture2D globalCutoutMask = m_shader.CutoutMask; if (useCutout) { EditorGUI.indentLevel++; heightCutout = EditorGUILayout.FloatField(GetLabel("Cutout Below"), heightCutout); DrawHelpLabel("Cutout Below"); globalCutoutMask = (Texture2D)EditorGUILayout.ObjectField(GetLabel("Cutout Mask"), globalCutoutMask, typeof(Texture2D), false, GUILayout.Height(16f)); DrawHelpLabel("Cutout Mask"); EditorGUI.indentLevel--; } GUILayout.BeginHorizontal(); if (GUILayout.Button(GetLabel("Bake NormalMap"))) { m_shader.BakeTerrainNormals(); globalNormal = m_shader.NormalMap; } if (GUILayout.Button(GetLabel("Bake ColorMap"))) { if (!autoBakeGrassIntoColorMap) { m_shader.BakeTerrainBaseMap(); } else { m_shader.BakeTerrainBaseMapWithGrass(); } globalColorMap = m_shader.ColorMap; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.Space(5); #region Handle changes //Check for changes, make undo record, make changes and let editor know we are dirty if (EditorGUI.EndChangeCheck()) { CompleteTerrainShader.SetDirty(m_shader, false, false); m_shader.Profile = profile; m_shader.NormalMap = globalNormal; m_shader.AutoBakeNormalMap = autobakeNormalMap; m_shader.ColorMap = globalColorMap; m_shader.AutoBakeColorMap = autobakeColorMap; m_shader.AutoBakeGrassIntoColorMap = autoBakeGrassIntoColorMap; m_shader.AutoBakeGrassMixStrength = autoBakeGrassMixStrength; m_shader.AutoBakeGrassDarkenAmount = autoBakeGrassDarkenAmount; m_shader.UseCutout = useCutout; m_shader.CutoutMask = globalCutoutMask; m_shader.CutoutHeight = heightCutout; m_shader.UpdateMaterialAndShader(); } #endregion }