/** * Called when a property on a Ferr2D component is changed by another user. Rebuilds the Ferr2D mesh. * * @param SerializedProperty property that changed. */ private static void OnPropertyChange(SerializedProperty property) { Component component = property.serializedObject.targetObject as Component; if (component == null) { return; } Ferr2DT_PathTerrain terrain = component.GetComponent <Ferr2DT_PathTerrain>(); if (terrain == null || terrain.Path == null) { return; } Ferr2D_Path path = terrain.Path; if (!m_rebuiltPaths.Add(path)) { // We've already rebuilt the mesh this frame. return; } sfFerr2DAdaptor adaptor = path.GetComponent <sfFerr2DAdaptor>(); if (adaptor != null && !adaptor.HasControlledMesh) { // The mesh on this object was not generated by the Ferr2D components on this object. If we // rebuild it will replace the existing mesh which we do not want. return; } MeshFilter filter = path.GetComponent <MeshFilter>(); if (filter != null && filter.sharedMesh != null) { // Ensure the mesh name is what Ferr2D expects so Ferr2D will update the existing mesh instead of // creating a new one. filter.sharedMesh.name = terrain.GetMeshName(); } // Rebuild the mesh path.UpdateDependants(true); // Rebuild the collider in play mode if (EditorApplication.isPlaying) { path.UpdateColliders(); } }
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); } }
private void DoHandles(Ferr2D_Path path, GUIStyle iconStyle) { Transform transform = path.transform; Matrix4x4 mat = transform.localToWorldMatrix; Matrix4x4 invMat = transform.worldToLocalMatrix; Transform camTransform = SceneView.lastActiveSceneView.camera.transform; Ferr2DT_PathTerrain terrain = path.GetComponent <Ferr2DT_PathTerrain>(); terrain.MatchOverrides(); Handles.color = new Color(1, 1, 1, 1); for (int i = 0; i < path.pathVerts.Count; i++) { // check if we want to remove points if (Event.current.alt) { DoResetModeHandles(path, terrain, i, mat, invMat, camTransform); } else { DoNormalModeHandles(path, terrain, i, mat, invMat, camTransform); } } if (Ferr2DT_SceneOverlay.segmentLockMode) { DoCutOverrideModeHandles(path, terrain, mat, camTransform); } if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Delete && selectedPoints.Count > 0) { deleteSelected = true; GUI.changed = true; Event.current.Use(); } if (deleteSelected) { DeleteSelected(path, terrain); deleteSelected = false; } }
private void DoHandles (Ferr2D_Path path, GUIStyle iconStyle) { Vector3 snap = Event.current.control ? new Vector3(EditorPrefs.GetFloat("MoveSnapX"), EditorPrefs.GetFloat("MoveSnapY"), EditorPrefs.GetFloat("MoveSnapZ")) : Vector3.zero; Transform transform = path.transform; Matrix4x4 mat = transform.localToWorldMatrix; Matrix4x4 invMat = transform.worldToLocalMatrix; Transform camTransform = SceneView.lastActiveSceneView.camera.transform; Ferr2DT_PathTerrain terrain = path.GetComponent<Ferr2DT_PathTerrain>(); if (terrain) terrain.MatchOverrides(); Handles.color = new Color(1, 1, 1, 1); for (int i = 0; i < path.pathVerts.Count; i++) { Vector3 pos = mat.MultiplyPoint3x4(path.pathVerts[i]); Vector3 posStart = pos; bool isSelected = false; if (selectedPoints!= null) isSelected = selectedPoints.Contains(i); // check if we want to remove points if (Event.current.alt) { float handleScale = HandleScale(posStart); Handles.DrawCapFunction cap = (isSelected || selectedPoints.Count <= 0) ? (Handles.DrawCapFunction)CapDotMinusSelected : (Handles.DrawCapFunction)CapDotMinus; if (Handles.Button(posStart, camTransform.rotation, handleScale, handleScale, cap)) { if (!isSelected) { selectedPoints.Clear(); selectedPoints.Add(i); } for (int s = 0; s < selectedPoints.Count; s++) { if (terrain) terrain.RemovePoint(selectedPoints[s]); else path.pathVerts.RemoveAt (selectedPoints[s]); if (selectedPoints[s] <= i) i--; for (int u = 0; u < selectedPoints.Count; u++) { if (selectedPoints[u] > selectedPoints[s]) selectedPoints[u] -= 1; } } selectedPoints.Clear(); GUI.changed = true; } else if (Ferr2DT_SceneOverlay.editMode != Ferr2DT_EditMode.None) { if (terrain && i+1 < path.pathVerts.Count) { float scale = handleScale * 0.5f; Vector3 dirOff = GetTickerOffset(path, pos, i); Vector3 posDirOff = posStart + dirOff; if (IsVisible(posDirOff)) { cap = null; if (Ferr2DT_SceneOverlay.editMode == Ferr2DT_EditMode.Override) cap = GetDirIcon(terrain.directionOverrides[i]); else if (Ferr2DT_SceneOverlay.editMode == Ferr2DT_EditMode.Scale ) cap = CapDotScale; if (Event.current.alt) cap = CapDotReset; if (Handles.Button(posDirOff, camTransform.rotation, scale, scale, cap)) { if (selectedPoints.Count < 2 || isSelected == false) { selectedPoints.Clear(); selectedPoints.Add(i); isSelected = true; } for (int s = 0; s < selectedPoints.Count; s++) { if (Ferr2DT_SceneOverlay.editMode == Ferr2DT_EditMode.Override) terrain.directionOverrides[selectedPoints[s]] = Ferr2DT_TerrainDirection.None; else if (Ferr2DT_SceneOverlay.editMode == Ferr2DT_EditMode.Scale) terrain.vertScales [selectedPoints[s]] = 1; } GUI.changed = true; } } } } } else { // check for moving the point Handles.DrawCapFunction cap = CapDot; if (Event.current.control) cap = isSelected ? (Handles.DrawCapFunction)CapDotSelectedSnap : (Handles.DrawCapFunction)CapDotSnap; else cap = isSelected ? (Handles.DrawCapFunction)CapDotSelected : (Handles.DrawCapFunction)CapDot; Vector3 result = Handles.FreeMoveHandle( posStart, camTransform.rotation, HandleScale(pos), snap, cap); if (result != posStart) { if (selectedPoints.Count < 2 || isSelected == false) { selectedPoints.Clear(); selectedPoints.Add(i); isSelected = true; } if (!(Event.current.control && Ferr2DT_Menu.SnapMode == Ferr2DT_Menu.SnapType.SnapRelative)) result = GetRealPoint(result, transform); Vector3 global = result; if (Event.current.control && Ferr2DT_Menu.SnapMode == Ferr2DT_Menu.SnapType.SnapGlobal) global = SnapVector(global, snap); Vector3 local = invMat.MultiplyPoint3x4(global); if (Event.current.control && Ferr2DT_Menu.SnapMode == Ferr2DT_Menu.SnapType.SnapLocal ) local = SnapVector(local, snap); if (!Event.current.control && Ferr2DT_SceneOverlay.smartSnap) { local = SmartSnap(local, path.pathVerts, selectedPoints, Ferr2DT_Menu.SmartSnapDist); } Vector2 relative = new Vector2( local.x, local.y) - path.pathVerts[i]; for (int s = 0; s < selectedPoints.Count; s++) { path.pathVerts[selectedPoints[s]] += relative; } } // if using terrain, check to see for any edge overrides if (Ferr2DT_SceneOverlay.showIndices) { Vector3 labelPos = posStart + (Vector3)Ferr2D_Path.GetNormal(path.pathVerts, i, path.closed); Handles.color = Color.white; Handles.Label(labelPos, "" + i); Handles.color = new Color(1, 1, 1, 0); } if (terrain) { float scale = HandleScale (pos) * 0.5f; Vector3 dirOff = GetTickerOffset (path, pos, i); Vector3 posDirOff = posStart + dirOff; if (Ferr2DT_SceneOverlay.editMode == Ferr2DT_EditMode.Override && i+1 < path.pathVerts.Count) { if (IsVisible(posDirOff) && terrain.directionOverrides != null) { cap = Event.current.alt ? (Handles.DrawCapFunction)CapDotReset : GetDirIcon(terrain.directionOverrides[i]); if (Handles.Button(posDirOff, camTransform.rotation, scale, scale, cap)) { if (selectedPoints.Count < 2 || isSelected == false) { selectedPoints.Clear(); selectedPoints.Add(i); isSelected = true; } Ferr2DT_TerrainDirection dir = NextDir(terrain.directionOverrides[i]); for (int s = 0; s < selectedPoints.Count; s++) { terrain.directionOverrides[selectedPoints[s]] = dir; } GUI.changed = true; } } } else if (Ferr2DT_SceneOverlay.editMode == Ferr2DT_EditMode.Scale) { if (IsVisible(posDirOff)) { cap = Event.current.alt ? (Handles.DrawCapFunction)CapDotReset : (Handles.DrawCapFunction)CapDotScale; Vector3 scaleMove = Handles.FreeMoveHandle(posDirOff, camTransform.rotation, scale, Vector3.zero, cap); float scaleAmt = scaleMove.y - posDirOff.y; if (Mathf.Abs(scaleAmt) > 0.01f ) { if (selectedPoints.Count < 2 || isSelected == false) { selectedPoints.Clear(); selectedPoints.Add(i); isSelected = true; } float vertScale = terrain.vertScales[i] - Event.current.delta.y / 100f; vertScale = Mathf.Clamp(vertScale, 0.2f, 3f); for (int s = 0; s < selectedPoints.Count; s++) { terrain.vertScales[selectedPoints[s]] = vertScale; } GUI.changed = true; } } } } // make sure we can add new point at the midpoints! if (i + 1 < path.pathVerts.Count || path.closed == true) { int index = path.closed && i + 1 == path.pathVerts.Count ? 0 : i + 1; Vector3 pos2 = mat.MultiplyPoint3x4(path.pathVerts[index]); Vector3 mid = (pos + pos2) / 2; float handleScale = HandleScale(mid); if (Handles.Button(mid, camTransform.rotation, handleScale, handleScale, CapDotPlus)) { Vector2 pt = invMat.MultiplyPoint3x4(mid); if (terrain) terrain.AddPoint(pt, index); else path.pathVerts.Insert(index, pt); } } } } if (Event.current.type == EventType.keyDown && Event.current.keyCode == KeyCode.Delete && selectedPoints.Count > 0) { for (int s = 0; s < selectedPoints.Count; s++) { if (terrain) terrain.RemovePoint(selectedPoints[s]); else path.pathVerts.RemoveAt (selectedPoints[s]); for (int u = 0; u < selectedPoints.Count; u++) { if (selectedPoints[u] > selectedPoints[s]) selectedPoints[u] -= 1; } } selectedPoints.Clear(); GUI.changed = true; Event.current.Use(); } }
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); } }
private void DoHandles(Ferr2D_Path path, GUIStyle iconStyle) { Vector3 snap = Event.current.control ? new Vector3(EditorPrefs.GetFloat("MoveSnapX"), EditorPrefs.GetFloat("MoveSnapY"), EditorPrefs.GetFloat("MoveSnapZ")) : Vector3.zero; Transform transform = path.transform; Matrix4x4 mat = transform.localToWorldMatrix; Matrix4x4 invMat = transform.worldToLocalMatrix; Transform camTransform = SceneView.lastActiveSceneView.camera.transform; Ferr2DT_PathTerrain terrain = path.GetComponent <Ferr2DT_PathTerrain>(); if (terrain) { terrain.MatchOverrides(); } Handles.color = new Color(1, 1, 1, 1); for (int i = 0; i < path.pathVerts.Count; i++) { Vector3 pos = mat.MultiplyPoint3x4(path.pathVerts[i]); Vector3 posStart = pos; bool isSelected = false; if (selectedPoints != null) { isSelected = selectedPoints.Contains(i); } // check if we want to remove points if (Event.current.alt) { float handleScale = HandleScale(posStart); Handles.DrawCapFunction cap = (isSelected || selectedPoints.Count <= 0) ? (Handles.DrawCapFunction)CapDotMinusSelected : (Handles.DrawCapFunction)CapDotMinus; if (Handles.Button(posStart, camTransform.rotation, handleScale, handleScale, cap)) { if (!isSelected) { selectedPoints.Clear(); selectedPoints.Add(i); } for (int s = 0; s < selectedPoints.Count; s++) { if (terrain) { terrain.RemovePoint(selectedPoints[s]); } else { path.pathVerts.RemoveAt(selectedPoints[s]); } if (selectedPoints[s] <= i) { i--; } for (int u = 0; u < selectedPoints.Count; u++) { if (selectedPoints[u] > selectedPoints[s]) { selectedPoints[u] -= 1; } } } selectedPoints.Clear(); GUI.changed = true; } else if (Ferr2DT_SceneOverlay.editMode != Ferr2DT_EditMode.None) { if (terrain && i + 1 < path.pathVerts.Count) { float scale = handleScale * 0.5f; Vector3 dirOff = GetTickerOffset(path, pos, i); Vector3 posDirOff = posStart + dirOff; if (IsVisible(posDirOff)) { cap = null; if (Ferr2DT_SceneOverlay.editMode == Ferr2DT_EditMode.Override) { cap = GetDirIcon(terrain.directionOverrides[i]); } else if (Ferr2DT_SceneOverlay.editMode == Ferr2DT_EditMode.Scale) { cap = CapDotScale; } if (Event.current.alt) { cap = CapDotReset; } if (Handles.Button(posDirOff, camTransform.rotation, scale, scale, cap)) { if (selectedPoints.Count < 2 || isSelected == false) { selectedPoints.Clear(); selectedPoints.Add(i); isSelected = true; } for (int s = 0; s < selectedPoints.Count; s++) { if (Ferr2DT_SceneOverlay.editMode == Ferr2DT_EditMode.Override) { terrain.directionOverrides[selectedPoints[s]] = Ferr2DT_TerrainDirection.None; } else if (Ferr2DT_SceneOverlay.editMode == Ferr2DT_EditMode.Scale) { terrain.vertScales [selectedPoints[s]] = 1; } } GUI.changed = true; } } } } } else { // check for moving the point Handles.DrawCapFunction cap = CapDot; if (Event.current.control) { cap = isSelected ? (Handles.DrawCapFunction)CapDotSelectedSnap : (Handles.DrawCapFunction)CapDotSnap; } else { cap = isSelected ? (Handles.DrawCapFunction)CapDotSelected : (Handles.DrawCapFunction)CapDot; } Vector3 result = Handles.FreeMoveHandle( posStart, camTransform.rotation, HandleScale(pos), snap, cap); if (result != posStart) { if (selectedPoints.Count < 2 || isSelected == false) { selectedPoints.Clear(); selectedPoints.Add(i); isSelected = true; } if (!(Event.current.control && Ferr2DT_Menu.SnapMode == Ferr2DT_Menu.SnapType.SnapRelative)) { result = GetRealPoint(result, transform); } Vector3 global = result; if (Event.current.control && Ferr2DT_Menu.SnapMode == Ferr2DT_Menu.SnapType.SnapGlobal) { global = SnapVector(global, snap); } Vector3 local = invMat.MultiplyPoint3x4(global); if (Event.current.control && Ferr2DT_Menu.SnapMode == Ferr2DT_Menu.SnapType.SnapLocal) { local = SnapVector(local, snap); } if (!Event.current.control && Ferr2DT_SceneOverlay.smartSnap) { local = SmartSnap(local, path.pathVerts, selectedPoints, Ferr2DT_Menu.SmartSnapDist); } Vector2 relative = new Vector2(local.x, local.y) - path.pathVerts[i]; for (int s = 0; s < selectedPoints.Count; s++) { path.pathVerts[selectedPoints[s]] += relative; } } // if using terrain, check to see for any edge overrides if (Ferr2DT_SceneOverlay.showIndices) { Vector3 labelPos = posStart + (Vector3)Ferr2D_Path.GetNormal(path.pathVerts, i, path.closed); Handles.color = Color.white; Handles.Label(labelPos, "" + i); Handles.color = new Color(1, 1, 1, 0); } if (terrain) { float scale = HandleScale(pos) * 0.5f; Vector3 dirOff = GetTickerOffset(path, pos, i); Vector3 posDirOff = posStart + dirOff; if (Ferr2DT_SceneOverlay.editMode == Ferr2DT_EditMode.Override && i + 1 < path.pathVerts.Count) { if (IsVisible(posDirOff) && terrain.directionOverrides != null) { cap = Event.current.alt ? (Handles.DrawCapFunction)CapDotReset : GetDirIcon(terrain.directionOverrides[i]); if (Handles.Button(posDirOff, camTransform.rotation, scale, scale, cap)) { if (selectedPoints.Count < 2 || isSelected == false) { selectedPoints.Clear(); selectedPoints.Add(i); isSelected = true; } Ferr2DT_TerrainDirection dir = NextDir(terrain.directionOverrides[i]); for (int s = 0; s < selectedPoints.Count; s++) { terrain.directionOverrides[selectedPoints[s]] = dir; } GUI.changed = true; } } } else if (Ferr2DT_SceneOverlay.editMode == Ferr2DT_EditMode.Scale) { if (IsVisible(posDirOff)) { cap = Event.current.alt ? (Handles.DrawCapFunction)CapDotReset : (Handles.DrawCapFunction)CapDotScale; Vector3 scaleMove = Handles.FreeMoveHandle(posDirOff, camTransform.rotation, scale, Vector3.zero, cap); float scaleAmt = scaleMove.y - posDirOff.y; if (Mathf.Abs(scaleAmt) > 0.01f) { if (selectedPoints.Count < 2 || isSelected == false) { selectedPoints.Clear(); selectedPoints.Add(i); isSelected = true; } float vertScale = terrain.vertScales[i] - Event.current.delta.y / 100f; vertScale = Mathf.Clamp(vertScale, 0.2f, 3f); for (int s = 0; s < selectedPoints.Count; s++) { terrain.vertScales[selectedPoints[s]] = vertScale; } GUI.changed = true; } } } } // make sure we can add new point at the midpoints! if (i + 1 < path.pathVerts.Count || path.closed == true) { int index = path.closed && i + 1 == path.pathVerts.Count ? 0 : i + 1; Vector3 pos2 = mat.MultiplyPoint3x4(path.pathVerts[index]); Vector3 mid = (pos + pos2) / 2; float handleScale = HandleScale(mid); if (Handles.Button(mid, camTransform.rotation, handleScale, handleScale, CapDotPlus)) { Vector2 pt = invMat.MultiplyPoint3x4(mid); if (terrain) { terrain.AddPoint(pt, index); } else { path.pathVerts.Insert(index, pt); } } } } } if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Delete && selectedPoints.Count > 0) { for (int s = 0; s < selectedPoints.Count; s++) { if (terrain) { terrain.RemovePoint(selectedPoints[s]); } else { path.pathVerts.RemoveAt(selectedPoints[s]); } for (int u = 0; u < selectedPoints.Count; u++) { if (selectedPoints[u] > selectedPoints[s]) { selectedPoints[u] -= 1; } } } selectedPoints.Clear(); GUI.changed = true; Event.current.Use(); } }
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); } }
private void OnSceneGUI() { if (!Ferr2DT_PathTerrain.showGUI) { return; } Ferr2D_Path path = (Ferr2D_Path)target; Ferr2DT_PathTerrain terrain = path.GetComponent <Ferr2DT_PathTerrain>(); GUIStyle iconStyle = new GUIStyle(); iconStyle.alignment = TextAnchor.MiddleCenter; snap = new Vector3(EditorPrefs.GetFloat("MoveSnapX", 1), EditorPrefs.GetFloat("MoveSnapY", 1), EditorPrefs.GetFloat("MoveSnapZ", 1)); // setup undoing things Undo.RecordObject(target, "Modified Path"); if (Event.current.type == EventType.Repaint && terrain != null) { Ferr2DT_PathTerrainEditor.DrawColliderEdge(terrain); } // draw the path line if (Event.current.type == EventType.Repaint) { DoPath(path); } // Check for drag-selecting multiple points DragSelect(path); // do adding verts in when the shift key is down! if (Event.current.shift && !Event.current.control) { DoShiftAdd(path, iconStyle); } // draw and interact with all the path handles DoHandles(path, iconStyle); // if this was an undo, refresh stuff too if (Event.current.type == EventType.ValidateCommand) { switch (Event.current.commandName) { case "UndoRedoPerformed": // Only rebuild this from an undo if the inspector is not visible. UnityEngine.Object[] objs = Resources.FindObjectsOfTypeAll(Type.GetType("UnityEditor.InspectorWindow, UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", true)); if (objs == null || objs.Length == 0) { path.UpdateDependants(true); if (OnChanged != null) { OnChanged(); } } break; } } // update everything that relies on this path, if the GUI changed if (GUI.changed) { if (PrefabUtility.GetCorrespondingObjectFromSource(target) != null) { NudgeArray(pathVerts); serializedObject.ApplyModifiedProperties(); } UpdateDependentsSmart(path, false, false); EditorUtility.SetDirty(target); prevChanged = true; } else if (Event.current.type == EventType.Used) { if (prevChanged == true) { UpdateDependentsSmart(path, false, true); } prevChanged = false; } }
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(); }