private void RouteGUI(GUISkin skin) { GUIStyle invalidNodeStyle = new GUIStyle(skin.label); invalidNodeStyle.normal.background = GUI.CreateColoredTexture(4, 4, Color.Lerp(UnityEngine.GUI.color, Color.red, 0.75f)); bool addNewPressed = false; bool insertBeforePressed = false; bool insertAfterPressed = false; bool erasePressed = false; NodeT listOpNode = null; Undo.RecordObject(Route, "Route changed"); GUI.Separator(); if (GUI.Foldout(EditorData.Instance.GetData(Parent, "Route", (entry) => { entry.Bool = true; }), GUI.MakeLabel("Route", true), skin)) { GUI.Separator(); Route <NodeT> .ValidatedRoute validatedRoute = Route.GetValidated(); foreach (var validatedNode in validatedRoute) { var node = validatedNode.Node; using (new GUI.Indent(12)) { if (validatedNode.Valid) { GUILayout.BeginVertical(); } else { GUILayout.BeginVertical(invalidNodeStyle); } if (GUI.Foldout(GetFoldoutData(node), GUI.MakeLabel(GetNodeTypeString(node) + " | " + SelectGameObjectDropdownMenuTool.GetGUIContent(node.Parent).text, !validatedNode.Valid, validatedNode.ErrorString), skin, (newState) => { Selected = newState ? node : null; EditorUtility.SetDirty(Parent); })) { OnPreFrameGUI(node, skin); GUI.HandleFrame(node, skin, 12); OnPostFrameGUI(node, skin); GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.green, 0.1f))) { insertBeforePressed = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListInsertElementBefore.ToString(), 16, false, "Insert a new node before this node"), skin.button, GUILayout.Width(20), GUILayout.Height(16)) || insertBeforePressed; insertAfterPressed = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListInsertElementAfter.ToString(), 16, false, "Insert a new node after this node"), skin.button, GUILayout.Width(20), GUILayout.Height(16)) || insertAfterPressed; } using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.red, 0.1f))) erasePressed = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListEraseElement.ToString(), 16, false, "Erase this node"), skin.button, GUILayout.Width(20), GUILayout.Height(16)) || erasePressed; if (listOpNode == null && (insertBeforePressed || insertAfterPressed || erasePressed)) { listOpNode = node; } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUI.Separator(); } if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown && Event.current.button == 0) { Selected = node; } } GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.green, 0.1f))) addNewPressed = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListInsertElementAfter.ToString(), 16, false, "Add new node to route"), skin.button, GUILayout.Width(20), GUILayout.Height(16)); if (listOpNode == null && addNewPressed) { listOpNode = Route.LastOrDefault(); } } GUILayout.EndHorizontal(); } GUI.Separator(); if (addNewPressed || insertBeforePressed || insertAfterPressed) { NodeT newRouteNode = null; // Clicking "Add" will not copy data from last node. newRouteNode = listOpNode != null? addNewPressed? RouteNode.Create <NodeT>(null, listOpNode.Position, listOpNode.Rotation) : RouteNode.Create <NodeT>(listOpNode.Parent, listOpNode.LocalPosition, listOpNode.LocalRotation) : RouteNode.Create <NodeT>(); OnNodeCreate(newRouteNode, listOpNode, addNewPressed); if (addNewPressed) { Route.Add(newRouteNode); } if (insertBeforePressed) { Route.InsertBefore(newRouteNode, listOpNode); } if (insertAfterPressed) { Route.InsertAfter(newRouteNode, listOpNode); } if (newRouteNode != null) { CreateRouteNodeTool(newRouteNode); Selected = newRouteNode; } } else if (listOpNode != null && erasePressed) { Selected = null; Route.Remove(listOpNode); } }