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); } }
private void OnGUI() { if (m_btAsset != null) { // 顶部导航 Rect navHistoryRect = new Rect(0.0f, 0.0f, position.width, 20.0f); // 顶部导航的设置按钮 Rect optionsRect = new Rect(position.width - 20.0f, 0.0f, 20.0f, 20.0f); // 底部显示路径的位置 Rect footerRect = new Rect(0.0f, position.height - 18.0f, position.width, 20.0f); // 显示树的画布 Rect canvasRect = new Rect(0.0f, navHistoryRect.yMax, position.width, position.height - (footerRect.height + navHistoryRect.height)); // 元素GUI风格设置 BTEditorStyle.EnsureStyle(); m_grid.DrawGUI(position.size); m_graph.DrawGUI(canvasRect); m_canvas.HandleEvents(canvasRect, position.size); DrawNavigationHistory(navHistoryRect); DrawFooter(footerRect); DrawOptions(optionsRect); if (m_canvas.IsDebuging) { OnRepaint(); } } }
public override void OnInspectorGUI() { LogicObject lo = (LogicObject)target; if (EditorApplication.isPlaying) { if (!lo.ShowAttrs && GUILayout.Button("ShowAttributes")) { lo.ShowAttrs = true; } if (lo.ShowAttrs && GUILayout.Button("HideAttributes")) { lo.ShowAttrs = false; } } serializedObject.Update(); GUI.enabled = !EditorApplication.isPlaying; GUI.color = Color.white; serializedObject.ApplyModifiedProperties(); var agent = lo.so.GetComponent <AIAgent>(); if (agent != null) { BTAsset btAsset = agent.BehaviourTree as BTAsset; BehaviourTree btInstance = agent.GetBehaviourTree(); GUI.enabled = btAsset != null; if (EditorApplication.isPlaying && btInstance != null) { if (GUILayout.Button("Preview", GUILayout.Height(24.0f))) { BehaviourTreeEditor.OpenDebug(btAsset, btInstance); } } else { if (GUILayout.Button("Edit", GUILayout.Height(24.0f))) { BehaviourTreeEditor.Open(btAsset); } } } if (m_inspector != null) { BTEditorStyle.EnsureStyle(); m_inspector.DrawGUI(); Repaint(); } else { EditorGUILayout.HelpBox("There are no values to display!", MessageType.Error); } GUI.enabled = true; }
public override void OnInspectorGUI() { if (m_inspector != null) { BTEditorStyle.EnsureStyle(); m_inspector.DrawGUI(); Repaint(); } else { EditorGUILayout.HelpBox("There are no values to display!", MessageType.Error); } }
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); } } } }