private void HandleEditorEvents(NodeGroup group) { int multi_select_nodes = EditorPrefs.GetInt("nodify.hotkeys.multi_select_nodes", 303); // Begin Context Menu Controls if (Event.current.type == EventType.ContextClick) { if (NodifyEditorUtilities.currentConnectingAnchor != null) { NodifyEditorUtilities.currentConnectingAnchor = null; Event.current.Use(); } else { ShowNodeCreationMenu(); Event.current.Use(); } } if (Event.current.type == EventType.KeyDown) { // Begin Focus Element Control if (Event.current.keyCode == (KeyCode)EditorPrefs.GetInt("nodify.hotkeys.focus_on_selected_node2", 102) && NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.focus_on_selected_node", 0))) { if (Selection.activeGameObject != null) { if (Selection.activeGameObject.GetComponent <Node>()) { FocusNode(group, Selection.activeGameObject.GetComponent <Node>()); } if (Selection.activeGameObject.GetComponent <Anchor>()) { FocusNode(group, Selection.activeGameObject.GetComponent <Anchor>().parent); } } ForceRepaint(); } if (Event.current.keyCode == KeyCode.Delete || Event.current.keyCode == KeyCode.Backspace) { for (int i = Selection.gameObjects.Length - 1; i >= 0; i--) { GameObject obj = Selection.gameObjects[i]; if (obj != NodifyEditorUtilities.currentSelectedGroup.gameObject && (obj.GetComponent <Node>() || obj.GetComponent <Anchor>())) { if (EditorUtility.DisplayDialog("Are you sure?", "Do you wish to delete the node: " + obj.name, "Delete", "Cancel")) { NodifyEditorUtilities.SafeDestroy(obj); } } } } } // Begin Mouse Selection Events if (NodifyEditorUtilities.currentManipulatingNode == null && NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.multi_select_nodes", 303))) { switch (Event.current.type) { case EventType.MouseDown: if (Event.current.button == 0) { MouseSelectionStartPoint = Event.current.mousePosition; MouseSelection = true; ForceRepaint(); } break; case EventType.MouseUp: if (MouseSelection == true) { SelectNodesInRect(RectExtensions.GetRectFromPoints(MouseSelectionStartPoint, Event.current.mousePosition)); MouseSelection = false; } ForceRepaint(); break; case EventType.MouseDrag: if (Event.current.button == 0) { ForceRepaint(); } else if (Event.current.button == 2) // Begin Mouse Drag Controls { if (new Rect(0, 0, position.width, position.height).Contains(Event.current.mousePosition)) { Vector2 mouseDelta = Event.current.delta; Vector2 mouseZoomDelta = (1f / group.editorZoomAmount) * mouseDelta; group.editorWindowOffset += mouseZoomDelta; Event.current.Use(); } } break; } } if (Event.current.type == EventType.MouseDrag && multi_select_nodes != 0 && !NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.multi_select_nodes", 303))) { if (new Rect(0, 0, position.width, position.height).Contains(Event.current.mousePosition)) { Vector2 mouseDelta = Event.current.delta; Vector2 mouseZoomDelta = (1f / group.editorZoomAmount) * mouseDelta; group.editorWindowOffset += mouseZoomDelta; } } // Begin Zoom Controls if (Event.current.type == EventType.ScrollWheel) { group.editorZoomAmount -= Event.current.delta.y / 80; group.editorZoomAmount = (float)System.Math.Round((double)Mathf.Clamp(group.editorZoomAmount, minimumZoomFactor, maximumZoomFactor), 2); Event.current.Use(); } if (Event.current.type == EventType.MouseDown && multi_select_nodes != 0 && NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.deselect_all", 303))) { Selection.objects = new UnityEngine.Object[0]; Event.current.Use(); } // Begin Drag & Drop Components into Variables if (Event.current.type == EventType.DragPerform || Event.current.type == EventType.DragUpdated) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; if (Event.current.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); foreach (UnityEngine.Object obj in DragAndDrop.objectReferences) { foreach (CreateMenu nodeMenu in NodifyEditorUtilities.FindNodeTypes()) { if (nodeMenu.type.BaseType.IsGenericType) { if (nodeMenu.type.BaseType.GetGenericArguments()[0] == obj.GetType()) { GameObject nodeObj = new GameObject(obj.GetType().Name); #if UNITY_5 Node nodeClass = (Node)nodeObj.AddComponent(nodeMenu.type); #else Node nodeClass = (Node)UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(nodeObj, "Assets/Nodify/Editor/NodifyEditorWindow.cs (635,32)", nodeMenu.type.Name); #endif nodeClass.editorPosition = Event.current.mousePosition - group.editorWindowOffset; nodeClass.editorResourceIcon = nodeMenu.iconResourcePath; nodeClass.OnEditorNodeCreated(); nodeObj.transform.parent = group.transform; nodeClass.GetType().GetField("value").SetValue(nodeClass, obj); } } } } } } }
public void OnGUI() { AssignSelectedGroup(); NodeGroup selectedGroup = NodifyEditorUtilities.currentSelectedGroup; if (selectedGroup != null) { selectedGroup.SetHideStateChildrenNonNodes(HideFlags.None); OnDrawEditorBackground(); NodifyEditorUtilities.BeginZoomArea(selectedGroup.editorZoomAmount, new Rect(0, 0, Screen.width, Screen.height)); this.RemoveNotification(); selectedGroup.editorWindowOffset.x = Mathf.Min(selectedGroup.editorWindowOffset.x, 0); selectedGroup.editorWindowOffset.y = Mathf.Min(selectedGroup.editorWindowOffset.y, 0); this.OnDrawEditorGrid(); if (selectedGroup != null) { if (NodifyEditorUtilities.currentConnectingAnchor != null) { DrawCurrentConnectingAnchor(NodifyEditorUtilities.currentConnectingAnchor); } /// Begin Node Anchor Rendering (Anchors rendered behind everything) foreach (Node node in selectedGroup.childNodes) { foreach (Anchor anchor in node.anchors) { for (int i = 0; i < anchor.anchorConnections.Count; i++) { if (anchor.anchorConnections[i] == null) { continue; } DrawAnchorConnection(anchor.anchorConnections[i]); } for (int i = 0; i < anchor.nodeConnections.Count; i++) { if (anchor.nodeConnections[i] == null) { continue; } DrawNodeConnection(anchor.nodeConnections[i]); } } } // End Node Anchor Rendering //Begin Node Group Anchor Rendering foreach (NodeGroup nodeGroup in selectedGroup.childGroups) { foreach (Anchor anchor in nodeGroup.anchors) { foreach (AnchorConnection connection in anchor.anchorConnections) { DrawAnchorConnection(connection); } foreach (NodeConnection connection in anchor.nodeConnections) { DrawNodeConnection(connection); } } } // End Node Group Anchor Rendering // Node Rendering foreach (Node node in selectedGroup.childNodes) { if (node.GetComponent <NodeGroup>()) { continue; } foreach (Anchor anchor in node.anchors) { DrawAnchor(anchor); } DrawNode(node); } // End Node Rendering // Node Group Rendering foreach (NodeGroup nodeGroup in selectedGroup.childGroups) { if (nodeGroup == selectedGroup) { continue; } foreach (Anchor anchor in nodeGroup.anchors) { DrawAnchor(anchor); } DrawNodeGroup(nodeGroup); } // End Node Group Rendering } NodifyEditorUtilities.EndZoomArea(); HandleEditorEvents(selectedGroup); if (MouseSelection == true && Event.current.type == EventType.Repaint) { editorSelectionRect.Draw(RectExtensions.GetRectFromPoints(MouseSelectionStartPoint, Event.current.mousePosition), false, false, false, false); } } else { ShowNotification(new GUIContent("Create or Select a Node Group")); } DrawToolbar(); DrawBreadcrumbs(); DrawLogo(); if (ShouldRepaint()) { this.Repaint(); } }