public override void OnInspectorGUI() { #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(target, "Modified Path"); #else Undo.SetSnapshotTarget(target, "Modified Path"); #endif Ferr2D_Path path = (Ferr2D_Path)target; path.closed = EditorGUILayout.Toggle("Closed", path.closed); // display the path verts list info showVerts = EditorGUILayout.Foldout(showVerts, "Path Vertices"); EditorGUI.indentLevel = 2; if (showVerts) { int size = EditorGUILayout.IntField("Count: ", path.pathVerts.Count); while (path.pathVerts.Count > size) { path.pathVerts.RemoveAt(path.pathVerts.Count - 1); } while (path.pathVerts.Count < size) { path.pathVerts.Add(new Vector2(0, 0)); } } // draw all the verts! Long list~ for (int i = 0; showVerts && i < path.pathVerts.Count; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("#" + i, GUILayout.Width(60)); path.pathVerts[i] = new Vector2( EditorGUILayout.FloatField(path.pathVerts[i].x), EditorGUILayout.FloatField(path.pathVerts[i].y)); EditorGUILayout.EndHorizontal(); } // button for updating the origin of the object if (GUILayout.Button("Center Position")) { path.ReCenter(); } // update dependants when it changes if (GUI.changed) { Ferr2DT_PathTerrain terrain = path.GetComponent <Ferr2DT_PathTerrain>(); if (!path.closed && terrain != null && (terrain.fill == Ferr2DT_FillMode.Closed || terrain.fill == Ferr2DT_FillMode.InvertedClosed || terrain.fill == Ferr2DT_FillMode.FillOnlyClosed)) { path.closed = true; } path.UpdateDependants(); EditorUtility.SetDirty(target); } }
public override void OnInspectorGUI() { Ferr2D_Path path = (Ferr2D_Path)target; bool updateMesh = false; // if this was an undo, refresh stuff too if (Event.current.type == EventType.ValidateCommand) { switch (Event.current.commandName) { case "UndoRedoPerformed": path.UpdateDependants(true); if (OnChanged != null) { OnChanged(); } return; } } EditorGUILayout.PropertyField(closed); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(pathVerts, true); if (EditorGUI.EndChangeCheck() && PrefabUtility.GetPrefabParent(target) != null) { NudgeArray(pathVerts); } // button for updating the origin of the object if (GUILayout.Button("Center Position")) { Undo.RecordObject(target, "Modified Path"); path.ReCenter(); updateMesh = true; } Ferr2DT_PathTerrain terrain = path.GetComponent <Ferr2DT_PathTerrain>(); if (!path.closed && (terrain.fill == Ferr2DT_FillMode.Closed || terrain.fill == Ferr2DT_FillMode.InvertedClosed || terrain.fill == Ferr2DT_FillMode.FillOnlyClosed)) { Undo.RecordObject(target, "Modified Path"); path.closed = true; updateMesh = true; } if (path.closed && (terrain.fill == Ferr2DT_FillMode.FillOnlySkirt || terrain.fill == Ferr2DT_FillMode.Skirt)) { Undo.RecordObject(target, "Modified Path"); path.closed = false; updateMesh = true; } // update dependants when it changes if (updateMesh || serializedObject.ApplyModifiedProperties()) { if (OnChanged != null) { OnChanged(); } path.UpdateDependants(true); EditorUtility.SetDirty(target); } }
public override void OnInspectorGUI() { Undo.RecordObject(target, "Modified Path"); Ferr2D_Path path = (Ferr2D_Path)target; // if this was an undo, refresh stuff too if (Event.current.type == EventType.ValidateCommand) { switch (Event.current.commandName) { case "UndoRedoPerformed": path.UpdateDependants(true); if (OnChanged != null) { OnChanged(); } return; } } path.closed = EditorGUILayout.Toggle("Closed", path.closed); if (path) { // display the path verts list info showVerts = EditorGUILayout.Foldout(showVerts, "Path Vertices"); } EditorGUI.indentLevel = 2; if (showVerts) { int size = EditorGUILayout.IntField("Count: ", path.pathVerts.Count); while (path.pathVerts.Count > size) { path.pathVerts.RemoveAt(path.pathVerts.Count - 1); } while (path.pathVerts.Count < size) { path.pathVerts.Add(new Vector2(0, 0)); } } // draw all the verts! Long list~ for (int i = 0; showVerts && i < path.pathVerts.Count; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("#" + i, GUILayout.Width(60)); path.pathVerts[i] = new Vector2( EditorGUILayout.FloatField(path.pathVerts[i].x), EditorGUILayout.FloatField(path.pathVerts[i].y)); EditorGUILayout.EndHorizontal(); } // button for updating the origin of the object if (GUILayout.Button("Center Position")) { path.ReCenter(); } bool updateClosed = false; Ferr2DT_PathTerrain terrain = path.GetComponent <Ferr2DT_PathTerrain>(); if (!path.closed && terrain != null && (terrain.fill == Ferr2DT_FillMode.Closed || terrain.fill == Ferr2DT_FillMode.InvertedClosed || terrain.fill == Ferr2DT_FillMode.FillOnlyClosed)) { path.closed = true; updateClosed = true; } if (terrain != null && path.closed && (terrain.fill == Ferr2DT_FillMode.FillOnlySkirt || terrain.fill == Ferr2DT_FillMode.Skirt)) { path.closed = false; updateClosed = true; } // update dependants when it changes if (GUI.changed || updateClosed) { path.UpdateDependants(false); EditorUtility.SetDirty(target); } }
public override void OnInspectorGUI() { EditorTools.TitleField("地板編輯工具"); Undo.RecordObject(target, "Modified Path"); Ferr2D_Path path = (Ferr2D_Path)target; // if this was an undo, refresh stuff too if (Event.current.type == EventType.ValidateCommand) { switch (Event.current.commandName) { case "UndoRedoPerformed": path.UpdateDependants(true); if (OnChanged != null) { OnChanged(); } return; } } path.closed = EditorGUILayout.Toggle("封閉地面", path.closed); if (path) { // display the path verts list info showVerts = EditorGUILayout.Foldout(showVerts, "頂點座標"); } EditorGUI.indentLevel = 2; if (showVerts) { int size = EditorGUILayout.IntField("數量: ", path.pathVerts.Count); while (path.pathVerts.Count > size) { path.pathVerts.RemoveAt(path.pathVerts.Count - 1); } while (path.pathVerts.Count < size) { path.pathVerts.Add(new Vector2(0, 0)); } } // draw all the verts! Long list~ for (int i = 0; showVerts && i < path.pathVerts.Count; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("#" + i, GUILayout.Width(60)); path.pathVerts[i] = new Vector2( EditorGUILayout.FloatField(path.pathVerts[i].x), EditorGUILayout.FloatField(path.pathVerts[i].y)); EditorGUILayout.EndHorizontal(); } // button for updating the origin of the object if (GUILayout.Button("座標重置")) { path.ReCenter(); } bool updateClosed = false; Ferr2DT_PathTerrain terrain = path.GetComponent <Ferr2DT_PathTerrain>(); if (!path.closed && terrain != null && (terrain.fill == Ferr2DT_FillMode.Closed || terrain.fill == Ferr2DT_FillMode.InvertedClosed || terrain.fill == Ferr2DT_FillMode.FillOnlyClosed)) { path.closed = true; updateClosed = true; } if (terrain != null && path.closed && (terrain.fill == Ferr2DT_FillMode.FillOnlySkirt || terrain.fill == Ferr2DT_FillMode.Skirt)) { path.closed = false; updateClosed = true; } // update dependants when it changes if (GUI.changed || updateClosed) { path.UpdateDependants(false); EditorUtility.SetDirty(target); } sizeX = EditorTools.IntField(sizeX, "寬"); sizeY = EditorTools.IntField(sizeY, "長"); if (GUILayout.Button("地板格式化")) { path.pathVerts = new List <Vector2>(); path.pathVerts.Add(new Vector2(sizeX, sizeY) * 0.5F); path.pathVerts.Add(new Vector2(sizeX, -sizeY) * 0.5F); path.pathVerts.Add(new Vector2(-sizeX, -sizeY) * 0.5F); path.pathVerts.Add(new Vector2(-sizeX, sizeY) * 0.5F); UpdateDependentsSmart(path, false, false); EditorUtility.SetDirty(target); prevChanged = true; BoxCollider2D box2D = path.GetComponent <BoxCollider2D>(); if (box2D) { path.GetComponent <BoxCollider2D>().size = new Vector2(sizeX, sizeY); EditorUtility.SetDirty(path.GetComponent <BoxCollider2D>()); } } if (GUILayout.Button("進階地板設定")) { GroundBase groundBase = path.GetComponent <GroundBase>(); if (!groundBase) { path.gameObject.AddComponent <GroundBase>(); } } EditorTools.Mig(); }