internal void Init(LevelSegmentCustomPathEditor e) { editor = e; originalPoints = new SplinePoint[editor.path.localPoints.Length]; editor.path.localPoints.CopyTo(originalPoints, 0); titleContent = new GUIContent("Modify " + editor.path.name); }
void CustomPathUI() { LevelSegment segment = (LevelSegment)target; showCustomPaths = EditorGUILayout.Foldout(showCustomPaths, "Custom Paths (" + segment.customPaths.Length + ")"); if (showCustomPaths) { Undo.RecordObject(segment, "Edit Custom Paths"); if (segment.type == LevelSegment.Type.Custom) { if (laneIndices.Length != segment.customPaths.Length + 1) { laneIndices = new int[segment.customPaths.Length + 1]; laneNames = new string[segment.customPaths.Length + 1]; } laneIndices[0] = -1; laneNames[0] = "None"; for (int i = 0; i < segment.customPaths.Length; i++) { laneNames[i + 1] = (i + 1) + " - " + segment.customPaths[i].name; laneIndices[i + 1] = i; } segment.customMainPath = EditorGUILayout.IntPopup("Main Path", segment.customMainPath, laneNames, laneIndices); } input.Update(); GUI.backgroundColor = DreamteckEditorGUI.lightColor; for (int i = 0; i < segment.customPaths.Length; i++) { GUILayout.BeginVertical(boxStyle); EditorGUILayout.BeginHorizontal(); segment.customPaths[i].color = EditorGUILayout.ColorField(segment.customPaths[i].color, GUILayout.Width(40)); if (renameCustomPath == i) { if (input.enterDown) { input.Use(); renameCustomPath = -1; } segment.customPaths[i].name = EditorGUILayout.TextField(segment.customPaths[i].name); } else { GUIStyle style = i == segment.customMainPath ? EditorStyles.boldLabel : EditorStyles.label; EditorGUILayout.LabelField(segment.customPaths[i].name, style); } EditorGUILayout.EndHorizontal(); Rect lastRect = GUILayoutUtility.GetLastRect(); if (input.mouseRightDown) { if (lastRect.Contains(Event.current.mousePosition)) { int index = i; GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Close"), false, delegate { selectedPath = -1; pathEditor = null; Repaint(); SceneView.RepaintAll(); }); menu.AddItem(new GUIContent("Rename"), false, delegate { renameCustomPath = index; Repaint(); SceneView.RepaintAll(); }); menu.AddItem(new GUIContent("Duplicate"), false, delegate { ArrayUtility.Insert(ref segment.customPaths, index + 1, segment.customPaths[index].Copy()); Repaint(); SceneView.RepaintAll(); }); menu.AddSeparator(""); if (i == 0) { menu.AddDisabledItem(new GUIContent("Move Up")); } else { menu.AddItem(new GUIContent("Move Up"), false, delegate { LevelSegment.LevelSegmentPath temp = segment.customPaths[index]; segment.customPaths[index] = segment.customPaths[index - 1]; segment.customPaths[index - 1] = temp; if (selectedPath == index) { selectedPath--; } Repaint(); SceneView.RepaintAll(); }); } if (i == segment.customPaths.Length - 1) { menu.AddDisabledItem(new GUIContent("Move Down")); } else { menu.AddItem(new GUIContent("Move Down"), false, delegate { LevelSegment.LevelSegmentPath temp = segment.customPaths[index]; segment.customPaths[index] = segment.customPaths[index + 1]; segment.customPaths[index + 1] = temp; if (selectedPath == index) { selectedPath++; } Repaint(); SceneView.RepaintAll(); }); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Delete"), false, delegate { segment.RemoveCustomPath(index); selectedPath = -1; pathEditor = null; Repaint(); SceneView.RepaintAll(); }); menu.ShowAsContext(); } } if (selectedPath == i && pathEditor != null) { EditorGUILayout.Space(); pathEditor.DrawInspector(); } GUILayout.EndVertical(); lastRect = GUILayoutUtility.GetLastRect(); if (input.mouseLeftDown) { if (lastRect.Contains(Event.current.mousePosition)) { selectedPath = i; pathEditor = new LevelSegmentCustomPathEditor(this, segment, segment.customPaths[i]); Repaint(); SceneView.RepaintAll(); } } } GUI.backgroundColor = Color.white; if (GUILayout.Button("Add Path")) { segment.AddCustomPath("Lane " + (segment.customPaths.Length + 1)); Repaint(); SceneView.RepaintAll(); } } else { renameCustomPath = -1; selectedPath = -1; if (pathEditor != null) { pathEditor.Close(); } pathEditor = null; } }
void OnUndoRedo() { selectedPath = -1; pathEditor = null; LevelSegment segment = (LevelSegment)target; }