private void HandleEvents() { Rect position = new Rect(NodePosition, BTEditorStyle.GetNodeSize(m_node)); Vector2 mousePosition = BTEditorCanvas.Current.WindowSpaceToCanvasSpace(BTEditorCanvas.Current.Event.mousePosition); if (BTEditorCanvas.Current.Event.type == EventType.MouseDown && BTEditorCanvas.Current.Event.button == SELECT_MOUSE_BUTTON) { if (position.Contains(mousePosition)) { if (!m_isSelected) { m_graph.OnNodeSelect(this); } if (m_lastClickTime > 0) { if (Time.realtimeSinceStartup <= m_lastClickTime + DOUBLE_CLICK_THRESHOLD) { OnDoubleClicked(); } } m_lastClickTime = Time.realtimeSinceStartup; m_canBeginDragging = !IsRoot; BTEditorCanvas.Current.Event.Use(); } } else if (BTEditorCanvas.Current.Event.type == EventType.MouseDown && BTEditorCanvas.Current.Event.button == CONTEXT_MOUSE_BUTTON) { if (position.Contains(mousePosition)) { ShowContextMenu(); BTEditorCanvas.Current.Event.Use(); } } else if (BTEditorCanvas.Current.Event.type == EventType.MouseUp && BTEditorCanvas.Current.Event.button == SELECT_MOUSE_BUTTON) { if (m_isDragging) { m_graph.OnNodeEndDrag(this); BTEditorCanvas.Current.Event.Use(); } m_canBeginDragging = false; } else if (BTEditorCanvas.Current.Event.type == EventType.MouseDrag && BTEditorCanvas.Current.Event.button == DRAG_MOUSE_BUTTON) { if (!m_graph.ReadOnly && !m_isDragging && m_canBeginDragging && position.Contains(mousePosition)) { m_graph.OnNodeBeginDrag(this, mousePosition); BTEditorCanvas.Current.Event.Use(); } else if (m_isDragging) { m_graph.OnNodeDrag(this, mousePosition); BTEditorCanvas.Current.Event.Use(); } } else if (m_graph.SelectionBox.HasValue) { if (m_graph.SelectionBox.Value.Contains(position.center)) { if (!m_isSelected) { m_graph.OnNodeSelect(this); } } else { if (m_isSelected) { m_graph.OnNodeDeselect(this); } } } }