void OnGUI() { if (material == null) { return; } // if this was an undo, repaint it if (Event.current.type == EventType.ValidateCommand) { switch (Event.current.commandName) { case "UndoRedoPerformed": Repaint(); return; } } #if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0) Undo.RecordObject(material, "Modified Terrain Material"); #else Undo.SetSnapshotTarget(material, "Modified Terrain Material"); if (!Ferr_EditorTools.HandlesMoving()) { Undo.CreateSnapshot(); } #endif if (Ferr_EditorTools.ResetHandles()) { GUI.changed = true; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(GUILayout.Width(width)); if (EditorGUILayout.Foldout(currDir == Ferr2DT_TerrainDirection.Top, "Top", foldoutStyle)) { if (currDir != Ferr2DT_TerrainDirection.Top) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.descriptors[(int)Ferr2DT_TerrainDirection.Top]); } currDir = Ferr2DT_TerrainDirection.Top; bool showTop = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Top), "Use Top"); material.Set(Ferr2DT_TerrainDirection.Top, showTop); if (showTop) { ShowDirection(material, currDir); } } if (EditorGUILayout.Foldout(currDir == Ferr2DT_TerrainDirection.Left, "Left", foldoutStyle)) { if (currDir != Ferr2DT_TerrainDirection.Left) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.descriptors[(int)Ferr2DT_TerrainDirection.Left]); } currDir = Ferr2DT_TerrainDirection.Left; bool showLeft = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Left), "Use Left"); material.Set(Ferr2DT_TerrainDirection.Left, showLeft); if (showLeft) { ShowDirection(material, currDir); } } if (EditorGUILayout.Foldout(currDir == Ferr2DT_TerrainDirection.Right, "Right", foldoutStyle)) { if (currDir != Ferr2DT_TerrainDirection.Right) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.descriptors[(int)Ferr2DT_TerrainDirection.Right]); } currDir = Ferr2DT_TerrainDirection.Right; bool showRight = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Right), "Use Right"); material.Set(Ferr2DT_TerrainDirection.Right, showRight); if (showRight) { ShowDirection(material, currDir); } } if (EditorGUILayout.Foldout(currDir == Ferr2DT_TerrainDirection.Bottom, "Bottom", foldoutStyle)) { if (currDir != Ferr2DT_TerrainDirection.Bottom) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.descriptors[(int)Ferr2DT_TerrainDirection.Bottom]); } currDir = Ferr2DT_TerrainDirection.Bottom; bool showBottom = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Bottom), "Use Bottom"); material.Set(Ferr2DT_TerrainDirection.Bottom, showBottom); if (showBottom) { ShowDirection(material, currDir); } } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); if (currDir != Ferr2DT_TerrainDirection.None) { Ferr2DT_TerrainMaterialUtility.ShowPreview(material, currDir, simpleUVs, true, width); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); if (Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDrag) { Repaint(); } if (GUI.changed) { EditorUtility.SetDirty(material); #if (UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0) Undo.RegisterSnapshot(); #endif Ferr2DT_PathTerrain[] terrain = GameObject.FindObjectsOfType(typeof(Ferr2DT_PathTerrain)) as Ferr2DT_PathTerrain[]; for (int i = 0; i < terrain.Length; i++) { if (terrain[i].TerrainMaterial == material) { terrain[i].RecreatePath(); } } } #if (UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0) Undo.ClearSnapshotTarget(); #endif }
void OnGUI() { if (material == null) { return; } // if this was an undo, repaint it if (Event.current.type == EventType.ValidateCommand) { switch (Event.current.commandName) { case "UndoRedoPerformed": Repaint(); return; } } Undo.RecordObject(material, "Modified Terrain Material"); if (Ferr.EditorTools.ResetHandles()) { GUI.changed = true; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(GUILayout.Width(width)); Ferr.EditorTools.Box(5, () => { if (currDir != Ferr2DT_TerrainDirection.None) { Ferr2DT_TerrainMaterialUtility.ShowSample(material, currDir, width - 10); } Ferr.EditorTools.Box(2, () => { if (GUILayout.Button("Top")) { currDir = Ferr2DT_TerrainDirection.Top; } if (currDir == Ferr2DT_TerrainDirection.Top) { if (prevDir != currDir) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor(currDir)); } bool showTop = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Top), "Use Top"); material.Set(Ferr2DT_TerrainDirection.Top, showTop); if (showTop) { ShowDirection(material, currDir); } } }, width - 10, 0); Ferr.EditorTools.Box(2, () => { if (GUILayout.Button("Left")) { currDir = Ferr2DT_TerrainDirection.Left; } if (currDir == Ferr2DT_TerrainDirection.Left) { if (prevDir != currDir) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor(currDir)); } bool showLeft = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Left), "Use Left"); material.Set(Ferr2DT_TerrainDirection.Left, showLeft); if (showLeft) { ShowDirection(material, currDir); } } }, width - 10, 0); Ferr.EditorTools.Box(2, () => { if (GUILayout.Button("Right")) { currDir = Ferr2DT_TerrainDirection.Right; } if (currDir == Ferr2DT_TerrainDirection.Right) { if (prevDir != currDir) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor(currDir)); } bool showRight = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Right), "Use Right"); material.Set(Ferr2DT_TerrainDirection.Right, showRight); if (showRight) { ShowDirection(material, currDir); } } }, width - 10, 0); Ferr.EditorTools.Box(2, () => { if (GUILayout.Button("Bottom")) { currDir = Ferr2DT_TerrainDirection.Bottom; } if (currDir == Ferr2DT_TerrainDirection.Bottom) { if (prevDir != currDir) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor(currDir)); } bool showBottom = GUILayout.Toggle(material.Has(Ferr2DT_TerrainDirection.Bottom), "Use Bottom"); material.Set(Ferr2DT_TerrainDirection.Bottom, showBottom); if (showBottom) { ShowDirection(material, currDir); } } }, width - 10, 0); }, 0, (int)this.position.height); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); scroll = EditorGUILayout.BeginScrollView(scroll); if (currDir != Ferr2DT_TerrainDirection.None) { Ferr2DT_TerrainMaterialUtility.ShowPreview(material, currDir, simpleUVs, true, width); } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); if (Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDrag) { Repaint(); } if (GUI.changed) { EditorUtility.SetDirty(material); Ferr2DT_PathTerrain[] terrain = GameObject.FindObjectsOfType(typeof(Ferr2DT_PathTerrain)) as Ferr2DT_PathTerrain[]; for (int i = 0; i < terrain.Length; i++) { if (terrain[i].TerrainMaterial == material) { terrain[i].Build(true); } } } prevDir = currDir; }
void OnGUI() { if (_selectedMaterial == null) { return; } // if this was an undo, repaint it if (Event.current.type == EventType.ValidateCommand) { switch (Event.current.commandName) { case "UndoRedoPerformed": GUI.changed = true; Repaint(); break; } } Undo.RecordObject((UnityEngine.Object)material, "Modified Terrain Material"); if (Ferr.EditorTools.ResetHandles()) { GUI.changed = true; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(GUILayout.Width(width)); GUI.Box(new Rect(0, 0, width, position.height), GUIContent.none); bool delete = false; List <string> segments = new List <string>(); for (int i = 0; i < material.descriptorCount; i++) { if (i == 0) { segments.Add("Top"); } else if (i == 1) { segments.Add("Left"); } else if (i == 2) { segments.Add("Right"); } else if (i == 3) { segments.Add("Bottom"); } else { segments.Add((i - 3).ToString()); } } segments.Add("+New edge"); currDir = EditorGUILayout.Popup(currDir, segments.ToArray()); // new edge was selected! if (currDir == segments.Count - 1) { segments.Insert(segments.Count - 1, currDir.ToString()); material.Add(); } if (currDir != (int)Ferr2DT_TerrainDirection.None) { Ferr2DT_TerrainMaterialUtility.ShowSample(material, (Ferr2DT_TerrainDirection)currDir, width - 10); } if (prevDir != currDir) { simpleUVs = Ferr2DT_TerrainMaterialUtility.IsSimple(material.GetDescriptor((Ferr2DT_TerrainDirection)currDir)); } EditorGUILayout.BeginHorizontal(); bool show = GUILayout.Toggle(material.Has((Ferr2DT_TerrainDirection)currDir), "Use " + segments[currDir]); delete = GUILayout.Button("Delete"); EditorGUILayout.EndHorizontal(); material.Set((Ferr2DT_TerrainDirection)currDir, show); if (show) { ShowDirection(material, (int)currDir); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); scroll = EditorGUILayout.BeginScrollView(scroll); if (currDir != (int)Ferr2DT_TerrainDirection.None) { Ferr2DT_TerrainMaterialUtility.ShowPreview(material, (Ferr2DT_TerrainDirection)currDir, simpleUVs, true, width); } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); if (Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDrag) { Repaint(); } if (GUI.changed) { Ferr2DT_PathTerrainEditor.cachedColliders = null; EditorUtility.SetDirty((UnityEngine.Object)material); bool updatedTerrain = false; Ferr2DT_PathTerrain[] terrain = GameObject.FindObjectsOfType(typeof(Ferr2DT_PathTerrain)) as Ferr2DT_PathTerrain[]; for (int i = 0; i < terrain.Length; i++) { if (terrain[i].TerrainMaterial == material) { terrain[i].Build(true); updatedTerrain = true; } } if (updatedTerrain && !Application.isPlaying) { EditorSceneManager.MarkAllScenesDirty(); } } prevDir = currDir; if (delete) { material.Remove((Ferr2DT_TerrainDirection)currDir); if (currDir > 3) { currDir -= 1; } } }