public override void OnPreTargetMembersGUI(GUISkin skin) { if (AttachmentPair == null) { PerformRemoveFromParent(); return; } bool guiWasEnabled = UnityEngine.GUI.enabled; using (new GUI.Indent(12)) { Undo.RecordObject(AttachmentPair, "Constraint Tool"); GUILayout.Label(GUI.MakeLabel("Reference frame", true), skin.label); GUI.HandleFrame(AttachmentPair.ReferenceFrame, skin, 4 + 12); GUILayout.BeginHorizontal(); GUILayout.Space(12); if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.Synchronized.ToString(), false, "Synchronized with reference frame"), GUI.ConditionalCreateSelectedStyle(AttachmentPair.Synchronized, skin.button), new GUILayoutOption[] { GUILayout.Width(24), GUILayout.Height(14) })) { AttachmentPair.Synchronized = !AttachmentPair.Synchronized; if (AttachmentPair.Synchronized) { ConnectedFrameTool.TransformHandleActive = false; } } GUILayout.Label(GUI.MakeLabel("Connected frame", true), skin.label); GUILayout.EndHorizontal(); UnityEngine.GUI.enabled = !AttachmentPair.Synchronized; GUI.HandleFrame(AttachmentPair.ConnectedFrame, skin, 4 + 12); UnityEngine.GUI.enabled = guiWasEnabled; } }
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); } }