public void ProcessMainWindowEvents(Event e) { if (BTEditorManager.ProcessEvents(Event.current)) { return; } switch (e.type) { case EventType.MouseDown: break; case EventType.MouseUp: if (e.button == 0) { BTEditorManager.ClearConnectionSelection(); } if (e.button == 1) { ProcessContextMenu(e.mousePosition); } break; case EventType.MouseDrag: if (e.button == 0) { BTEditorManager.OnDrag(e.delta); } break; } }
public void DrawSubUI(int id) { if (BTEditorManager.selectedNode == null && BTEditorManager.selectedConnection == null) { GUILayout.Label("没有选中任何节点", GUILayout.MaxWidth(180)); return; } m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition, GUILayout.Width(subWindow_Rect.width - 15), GUILayout.Height(400)); switch (_curSubView) { case SubViewType.Node: DrawProperties(); var node = BTEditorManager.selectedNode; if (node.properties != null) { BTEditorManager.SaveCurrentNode(); } break; case SubViewType.Connection: DrawSlots(); var connection = BTEditorManager.selectedConnection; if (connection.slotList != null) { BTEditorManager.SaveCurrentConnection(); } break; default: break; } GUI.changed = true; GUILayout.EndScrollView(); }
private void DrawMenuBar() { menuBar = new Rect(0, 0, position.width, menuBarHeight); GUILayout.BeginArea(menuBar, EditorStyles.toolbar); GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Save"), EditorStyles.toolbarButton, GUILayout.Width(35))) { BTEditorManager.Save(); } GUILayout.Space(5); if (GUILayout.Button(new GUIContent("Load"), EditorStyles.toolbarButton, GUILayout.Width(35))) { BTEditorManager.Load(); } if (GUILayout.Button(new GUIContent("Clear"), EditorStyles.toolbarButton, GUILayout.Width(35))) { BTEditorManager.Clear(); } if (GUILayout.Button(new GUIContent("Print"), EditorStyles.toolbarButton, GUILayout.Width(35))) { BTUtils.DumpTree(BTEditorManager.rootNode); } GUILayout.EndHorizontal(); GUILayout.EndArea(); }
public bool ProcessEvents(Event e) { float distance = Vector3.Distance(this._centerPos, e.mousePosition); if (distance < 6.0f) { //Debug.Log("distance " + distance); if (e.type != EventType.Layout && e.type != EventType.Repaint) { if (e.button == 0) { BTEditorManager.OnClickConnection(this); GUI.changed = true; return(true); } else if (e.button == 1) { ProcessContextMenu(e.mousePosition); GUI.changed = true; return(true); } } } return(false); }
public virtual void Init(Vector2 position, Action <BaseNode> OnClickSelf) { this.name = type + "_" + id; this.rect = new Rect(position.x, position.y, node_width, node_height); this.inPoint = BTEditorManager.CreateConnectionPoint(this, ConnectionPointType.In); this.outPoint = BTEditorManager.CreateConnectionPoint(this, ConnectionPointType.Out); this.onClickSelf = OnClickSelf; }
private void DrawWindowUI() { DrawMenuBar(); BeginWindows();//Begin Render DrawNodeWindow(); BTEditorManager.Draw(); EndWindows();//End Render }
public void SetupConnect(ConnectionData connectionData) { int index = connectionData.slotList.Count + 1; this.out_slot = "out_" + index; this.node = "node_" + index; this.in_slot = "in_" + index; BaseNode baseNode = BTEditorManager.GetObject <BaseNode>(connectionData.targetNodeId); this.node = baseNode.name; }
public void Import(string configName) { BTEditorManager.Clear(); //string configPath = BTUtils.GetGenPath() + configName + ".json"; //string fullConfigPath = BTUtils.GetGenPath() + configName + "_full.json"; //BaseNodeData rootNodeData = BTUtils.GetJsonFromFile<BaseNodeData>(fullConfigPath); string nodeMapPath = BTUtils.GetGenPath() + configName + "_node_map.json"; nodeMap = BTUtils.GetJsonFromFile <Dictionary <string, BaseNodeData> >(nodeMapPath); BaseNodeData rootNodeData = GetNodeMapData(0); CreateTree(0, null, rootNodeData, null); }
public static void ProcessContextMenu(Vector2 mousePosition) { GenericMenu genericMenu = new GenericMenu(); //genericMenu.AddItem(new GUIContent("Add RootNode"), false, () => BTEditorManager.AddRootNode(mousePosition)); genericMenu.AddItem(new GUIContent("Add ExcelNode"), false, () => BTEditorManager.AddNode <ExcelNode>(mousePosition)); genericMenu.AddItem(new GUIContent("Add ActionNode"), false, () => BTEditorManager.AddNode <ActionNode>(mousePosition)); genericMenu.AddItem(new GUIContent("Add ConditionNode"), false, () => BTEditorManager.AddNode <ConditionNode>(mousePosition)); genericMenu.AddItem(new GUIContent("Add WaitNode"), false, () => BTEditorManager.AddNode <WaitNode>(mousePosition)); genericMenu.AddItem(new GUIContent("Add SequenceNode"), false, () => BTEditorManager.AddNode <SequenceNode>(mousePosition)); genericMenu.AddItem(new GUIContent("Add SelectorNode"), false, () => BTEditorManager.AddNode <SelectorNode>(mousePosition)); genericMenu.AddItem(new GUIContent("Add LoopNode"), false, () => BTEditorManager.AddNode <LoopNode>(mousePosition)); genericMenu.ShowAsContext(); }
public static void ShowWindow() { if (_window == null) { _window = EditorWindow.GetWindow <BTEditorWindow>(); } Reset(); Vector2 initPosition = new Vector2(10, _window.position.height / 2 - 25); //BaseNode root = BTEditorManager.AddRootNode(initPosition); NodeDataManager.Reset(); BTEditorManager.Reset(); }
private void CreateTree(int deepth, BaseNodeData lastNodeData, BaseNodeData nodeDummyData, ConnectionData connectionData) { if (deepth >= 10) { return; } //创建当前节点 BaseNode node = null; if (nodeDummyData != null) { node = BTEditorManager.AddNode <ExcelNode>(new Vector2(nodeDummyData.x, nodeDummyData.y)); nodeDummyData.DeSerialize(ref node); } //创建connection连线 if (lastNodeData != null && connectionData != null) { BaseNode lastNode = BTEditorManager.GetObject <BaseNode>(lastNodeData.id); Connection connection = BTEditorManager.CreateConnection(lastNode.outPoint, node.inPoint); connectionData.DeSerialize(ref connection); } //遍历下一个connection for (int i = 0; i < nodeDummyData.connectionList.Count; i++) { ConnectionData nextConnectionData = nodeDummyData.connectionList[i]; BaseNodeData targetNodeData = GetNodeMapData(nextConnectionData.targetNodeId); if (targetNodeData == null) { Debug.LogError(string.Format("找不到{0}的节点!", nextConnectionData.targetNodeId)); return; } CreateTree( deepth + 1, //deepth nodeDummyData, //last targetNodeData, //this nextConnectionData ); } }
public bool ProcessEvents(Event e) { switch (e.type) { case EventType.Used: if (rect.Contains(e.mousePosition)) { if (e.button == 0) { switch (type) { case ConnectionPointType.In: BTEditorManager.OnClickInPoint(this); break; case ConnectionPointType.Out: BTEditorManager.OnClickOutPoint(this); break; } GUI.changed = true; } } else { GUI.changed = true; } break; case EventType.MouseUp: break; case EventType.MouseDrag: break; } return(false); }
public static void Reset() { BTEditorManager.Clear(); }