/// <summary> /// Handles all mouse & keyboard events for the node. /// </summary> /// <param name="node"></param> public virtual void OnHandleEvents(T node) { node.editorPosition.x = Mathf.Max(node.editorPosition.x, 0f); node.editorPosition.y = Mathf.Max(node.editorPosition.y, 0f); Rect contentRect = GetContentRect(node); EditorGUIUtility.AddCursorRect(contentRect, MouseCursor.MoveArrow); if (contentRect.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.ContextClick) { // Begin Expose default method if (NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.auto_create_default_method_anchor_dor_node", 303))) { Expose defaultExposed = null; foreach (Expose exposedElement in node.GetExposed()) { if (exposedElement.isDefault) { defaultExposed = exposedElement; } } if (defaultExposed == null) { defaultExposed = node.GetExposedByName("OnComplete"); } if (defaultExposed != null) { GameObject exposed = new GameObject(defaultExposed.exposedName); exposed.hideFlags = HideFlags.HideInHierarchy; Anchor anchor = exposed.AddComponent <Anchor>(); anchor.displayName = defaultExposed.exposedName; if (defaultExposed.exposedType == ExposedType.FIELD || defaultExposed.exposedType == ExposedType.PROPERTY) { anchor.type = AnchorType.VARIABLE; } else { anchor.type = AnchorType.METHOD; } anchor.editorPosition.y = -25; exposed.transform.parent = node.transform; } } else { if (NodifyEditorUtilities.currentConnectingAnchor == null) { GenericMenu menu = new GenericMenu(); this.OnDrawTopContextMenu(node, menu); this.OnDrawBottomContextMenu(node, menu); menu.ShowAsContext(); } else { if (NodifyEditorUtilities.currentConnectingAnchor.type == AnchorType.METHOD) { NodifyEditorUtilities.currentConnectingAnchor.ConnectToNode(node); NodifyEditorUtilities.currentConnectingAnchor = null; } } } Event.current.Use(); } if (Event.current.type == EventType.MouseDrag && NodifyEditorUtilities.currentDraggingAnchor == null) { Event.current.Use(); } if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { // Handle Hot Control for input manipulation if (IsSelected(node)) { if (NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.multiple_select_and_deselect", 303))) { NodifyEditorWindow.RemoveFromSelectedObjects(node.gameObject); NodifyEditorWindow.ForceRepaint(); } else { NodifyEditorUtilities.currentManipulatingNode = node; NodifyEditorUtilities.currentManipulatingNodeOffset = node.editorPosition - Event.current.mousePosition; } } else { NodifyEditorUtilities.currentManipulatingNode = node; NodifyEditorUtilities.currentManipulatingNodeOffset = node.editorPosition - Event.current.mousePosition; if (NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.multiple_select_and_deselect", 303))) { NodifyEditorWindow.AddToSelectedObjects(node.gameObject); NodifyEditorWindow.ForceRepaint(); } else { Selection.activeGameObject = node.gameObject; } } Event.current.Use(); } } if (NodifyEditorUtilities.currentManipulatingNode == node) { Vector2 lastPosition = node.editorPosition; node.editorPosition = Event.current.mousePosition + NodifyEditorUtilities.currentManipulatingNodeOffset; Vector2 moveDelta = node.editorPosition - lastPosition; NodifyEditorWindow.MovedNodeSelectionDelta(node, moveDelta); } if (Event.current.type == EventType.MouseUp) { if (NodifyEditorUtilities.currentManipulatingNode == node) { NodifyEditorUtilities.currentManipulatingNode = null; } } }
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 virtual void OnHandleEvents(T anchor) { Rect contentRect = GetContentRect(anchor); EditorGUIUtility.AddCursorRect(contentRect, MouseCursor.MoveArrow); if (contentRect.Contains(Event.current.mousePosition) && NodifyEditorUtilities.currentManipulatingNode == null) { if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { Selection.activeGameObject = anchor.gameObject; NodifyEditorUtilities.currentDraggingAnchor = anchor; Event.current.Use(); } if (Event.current.type == EventType.ContextClick) { bool bringUpAnchorMenu = NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.bring_up_anchors_menu", 303)); if (bringUpAnchorMenu) { GenericMenu menu = new GenericMenu(); this.OnDrawTopContextMenu(anchor, menu); this.OnDrawBottomContextMenu(anchor, menu); menu.ShowAsContext(); } else { if (NodifyEditorUtilities.currentConnectingAnchor == null) { NodifyEditorUtilities.currentConnectingAnchor = anchor; } else { if (NodifyEditorUtilities.currentConnectingAnchor.parent != anchor.parent) { if (NodifyEditorUtilities.currentConnectingAnchor.type == AnchorType.VARIABLE && anchor.type == AnchorType.VARIABLE) { NodifyEditorUtilities.currentConnectingAnchor.ConnectToAnchor(anchor); NodifyEditorUtilities.currentConnectingAnchor = null; } } } } Event.current.Use(); } } if (Event.current.type == EventType.MouseDrag && NodifyEditorUtilities.currentDraggingAnchor == anchor) { anchor.editorPosition += Event.current.delta; Event.current.Use(); } if (Event.current.type == EventType.MouseUp && NodifyEditorUtilities.currentDraggingAnchor == anchor) { NodifyEditorUtilities.currentDraggingAnchor = null; Event.current.Use(); } }