private void DrawSelf() { string label = string.IsNullOrEmpty(m_node.Name) ? m_node.Title : m_node.Name; BTGraphNodeStyle nodeStyle = BTEditorStyle.GetNodeStyle(m_node); Vector2 nodeSize = BTEditorStyle.GetNodeSize(m_node); Rect position = new Rect(NodePositon + BTEditorCanvas.Current.Position, nodeSize); BehaviourNodeStatus status = BTEditorCanvas.Current.IsDebuging ? m_node.Status : BehaviourNodeStatus.None; EditorGUI.LabelField(position, label, nodeStyle.GetStyle(status, m_isSelected)); if (m_node.Breakpoint != Breakpoint.None) { Rect imgPosition; if (m_node is NodeGroup) { imgPosition = new Rect(position.x + 2, position.y + 2, 12, 12); } else { imgPosition = new Rect(position.x - 14, position.y + 2, 12, 12); } GUI.DrawTexture(imgPosition, BTEditorStyle.Breakpoint); } }
public BTEditorGraphNode OnInsertChild(int index, Type type) { if (type != null) { BehaviourNode node = BTUtils.CreateNode(type); if (node != null) { Vector2 nodeSize = BTEditorStyle.GetNodeSize(node); Vector2 nodePos = NodePositon + nodeSize * 1.5f; nodePos.x = Mathf.Max(nodePos.x, 0.0f); nodePos.y = Mathf.Max(nodePos.y, 0.0f); node.Position = nodePos; return(OnInsertChild(index, node)); } } return(null); }
private void DrawTransitions() { Vector2 nodeSize = BTEditorStyle.GetNodeSize(m_node); Rect position = new Rect(NodePositon + BTEditorCanvas.Current.Position, nodeSize); BTEditorTreeLayout treeLayout = BTEditorStyle.TreeLayout; foreach (var child in m_children) { Vector2 childNodeSize = BTEditorStyle.GetNodeSize(child.Node); Rect childPosition = new Rect(child.Node.Position + BTEditorCanvas.Current.Position, childNodeSize); BehaviourNodeStatus childStatus = BTEditorCanvas.Current.IsDebuging ? child.Node.Status : BehaviourNodeStatus.None; Color color = BTEditorStyle.GetTransitionColor(childStatus); Vector2 nodeCenter = position.center; Vector2 childCenter = childPosition.center; if (treeLayout == BTEditorTreeLayout.Vertical) { if (Mathf.Approximately(nodeCenter.y, childCenter.y) || Mathf.Approximately(nodeCenter.x, childCenter.x)) { BTEditorUtils.DrawLine(nodeCenter, childCenter, color); } else { BTEditorUtils.DrawLine(nodeCenter, nodeCenter + Vector2.up * (childCenter.y - nodeCenter.y) / 2, color); BTEditorUtils.DrawLine(nodeCenter + Vector2.up * (childCenter.y - nodeCenter.y) / 2, childCenter + Vector2.up * (nodeCenter.y - childCenter.y) / 2, color); BTEditorUtils.DrawLine(childCenter, childCenter + Vector2.up * (nodeCenter.y - childCenter.y) / 2, color); } } else if (treeLayout == BTEditorTreeLayout.Horizontal) { BTEditorUtils.DrawBezier(nodeCenter, childCenter, color); } else { BTEditorUtils.DrawLine(nodeCenter, childCenter, color); } } }
private void HandleEvents() { Rect position = new Rect(NodePositon, 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.HasValue) { if (Time.realtimeSinceStartup <= m_lastClickTime.Value + DOUBLE_CLICK_THRESHOLD) { OnDoubleClicked(); } m_lastClickTime = null; } else { 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.control); 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); } } } }