/// <summary> /// Creates a draggable zone that selects all nodes it contains. /// </summary> /// <param name="position">Zone start position.</param> private void DragSelection(Rect position) { int controlID = GUIUtility.GetControlID (FocusType.Passive); Event current = Event.current; switch (current.GetTypeForControl (controlID)){ case EventType.MouseDown:{ if (position.Contains (current.mousePosition) && current.button == 0 && current.clickCount != 2 && !current.alt){ if(_linkingNode){ _linkingNode = false; _nodeToLink = null; } GUIUtility.hotControl = controlID; _dragStartPoint = current.mousePosition; _oldSelection = new List<Node>(); _selection = new List<Node>(); _dragType = SelectionDragType.pick; current.Use (); } break; } case EventType.MouseUp:{ if (GUIUtility.hotControl == controlID){ GUIUtility.hotControl = 0; _oldSelection = new List<Node>(); this.UpdateUnitySelection (); if(Selection.objects.Length == 0){ Selection.objects = new Object[1]{(_selected as MonoBehaviour).gameObject}; } _dragType = SelectionDragType.None; current.Use (); } break; } case EventType.MouseDrag:{ if (GUIUtility.hotControl == controlID){ _dragType = SelectionDragType.Rect; _selection = new List<Node>(); _selection = GetNodesInSelectionRect (GetRectBetweenPoints(_dragStartPoint, current.mousePosition)); current.Use (); } break; } case EventType.KeyDown:{ if (_dragType != SelectionDragType.None && current.keyCode == KeyCode.Escape){ _selection = _oldSelection; GUIUtility.hotControl = 0; _dragType = SelectionDragType.None; current.Use (); } break; } case EventType.Repaint:{ if (_dragType == SelectionDragType.Rect){ UnityEditor.Graphs.Styles.selectionRect.Draw (GetRectBetweenPoints(_dragStartPoint, current.mousePosition), false, false, false, false); } break; } } }
/// <summary> /// Resets important values for the AnyGraph window. /// </summary> private void Reset() { _zoomArea = new Rect(); _zoom = 1.0f; _zoomCoordsOrigin = Vector2.zero; _nodeDragDistance = new Vector2(); _initMousePos = new Vector2(); _scrollPos = new Vector2(); _graphExtents = new Rect(); _lastGraphExtents = new Rect(); _dragStartPoint = new Vector2(); _dragType = SelectionDragType.None; _toolbarRect = new Rect(); _optionWindowScrollPos = new Vector2(); _initialDragNodePosition = new Dictionary<Node, Rect>(); _allNodePos = new List<Rect>(); _cachedNodes = new List<IAnyGraphNode>(); _selected = null; _linkingNode = false; _nodeToLink = null; _allNodes = new List<Node>(); _selection = new List<Node>(); _oldSelection = new List<Node>(); _needRearrange = false; _rearrange = null; _searchString = ""; // Call on the garbage collector to free up resources. System.GC.Collect (); }