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 static void DrawConnectionLine(Event e) { //click inPoint if (selectedInPoint != null && selectedOutPoint == null) { BTUtils.DrawBezier( selectedInPoint.rect.center, e.mousePosition, selectedInPoint.rect.center + Vector2.left * 50f, e.mousePosition - Vector2.left * 50f ); GUI.changed = true; } //click outPoint if (selectedOutPoint != null && selectedInPoint == null) { BTUtils.DrawBezier( selectedOutPoint.rect.center, e.mousePosition, selectedOutPoint.rect.center - Vector2.left * 50f, e.mousePosition + Vector2.left * 50f ); GUI.changed = true; } }
public static void Clear() { if (nodes_list != null) { nodes_list.Clear(); } if (connection_list != null) { connection_list.Clear(); } curObjectId = 0; selectedNode = null; selectedConnection = null; if (rootNode != null) { BTUtils.RemoveTree(rootNode); RemoveNode(rootNode); } rootNode = null; }
public void OnCopyNode(BTEditorGraphNode source) { if (CanCopy(source)) { BTEditorCanvas.Current.Clipboard = BTUtils.SerializeNode(source.Node); } }
public void Export(BaseNode rootNode, string configName) { string configPath = BTUtils.GetGenPath() + configName + ".json"; string fullConfigPath = BTUtils.GetGenPath() + configName + "_full.json"; string nodeMapPath = BTUtils.GetGenPath() + configName + "_node_map.json"; Dictionary <string, BaseNodeData> baseNodeDataDict = new Dictionary <string, BaseNodeData>(); Dictionary <string, MergePyData> dataDict = new Dictionary <string, MergePyData>(); BTUtils.DumpTree(rootNode, (BaseNode node) => { BaseNodeData nodeData = NodeDataManager.Get(node); if (nodeData != null) { nodeData.Serialize(node); dataDict[node.name] = new MergePyData(node); baseNodeDataDict[node.name] = nodeData; } }); BTUtils.SaveJsonToFile <Dictionary <string, MergePyData> >(dataDict, configPath); BaseNodeData rootNodeData = NodeDataManager.Get(rootNode); BTUtils.SaveJsonToFile <BaseNodeData>(rootNodeData, fullConfigPath); BTUtils.SaveJsonToFile <Dictionary <string, BaseNodeData> >(baseNodeDataDict, nodeMapPath); }
public UndoNodeDeleted(BTEditorGraphNode node, int childIndex) { m_graph = node.Graph; m_parentNodeHash = m_graph.GetNodeHash(node.Parent); m_serializedNode = BTUtils.SerializeNode(node.Node); m_childIndex = childIndex; Title = "Deleted " + node.Node.Title; m_createdNodeHash = null; }
public override void Redo() { if (CanRedo) { var createdNode = m_graph.GetNodeByHash(m_createdNodeHash); m_parentNodeHash = m_graph.GetNodeHash(createdNode.Parent); m_serializedNode = BTUtils.SerializeNode(createdNode.Node); m_childIndex = createdNode.Parent.GetChildIndex(createdNode); createdNode.OnDelete(); m_createdNodeHash = null; } }
public override void Redo() { if (CanRedo) { BTEditorGraphNode parentNode = m_graph.GetNodeByHash(m_parentNodeHash); BehaviourNode node = BTUtils.DeserializeNode(m_serializedNode); BTEditorGraphNode createdNode = parentNode.OnCreateChild(node); m_createdNodeHash = m_graph.GetNodeHash(createdNode); m_parentNodeHash = null; m_serializedNode = null; } }
public override void Undo() { if (CanUndo) { BTEditorGraphNode createdNode = m_graph.GetNodeByHash(m_createdNodeHash); m_parentNodeHash = m_graph.GetNodeHash(createdNode.Parent); m_serializedNode = BTUtils.SerializeNode(createdNode.Node); createdNode.OnDelete(); m_createdNodeHash = null; } }
public void OnNodeSwitchType(BTEditorGraphNode target, Type newType) { if (target == null || newType == null) { return; } BTEditorGraphNode parentNode = target.Parent; Vector2 oldPosition = target.NodePosition; int oldIndex = target.Parent.GetChildIndex(target); BehaviourNode node = BTUtils.CreateNode(newType); if (node != null) { node.Constraints.AddRange(target.Node.Constraints); if (node is Decorator) { Decorator original = target.Node as Decorator; Decorator decorator = node as Decorator; decorator.SetChild(original.GetChild()); } else if (node is Composite) { Composite original = target.Node as Composite; Composite composite = node as Composite; for (int i = 0; i < original.ChildCount; i++) { composite.AddChild(original.GetChild(i)); } } BTUndoSystem.BeginUndoGroup("Changed node type"); BTUndoSystem.RegisterUndo(new UndoNodeDeleted(target)); target.OnDelete(); BTEditorGraphNode newNode = parentNode.OnInsertChild(oldIndex, node); if (newNode != null) { newNode.NodePosition = oldPosition; BTUndoSystem.RegisterUndo(new UndoNodeCreated(newNode)); } BTUndoSystem.EndUndoGroup(); } }
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 AddService(GenericMenu menu, BehaviourNode targetNode) { GenericMenu.MenuFunction2 onCreateService = t => { Service service = BTUtils.CreateService(t as Type); if (service != null) { targetNode.Services.Add(service); } }; foreach (var item in m_serviceMenuPaths) { menu.AddItem(new GUIContent("Add Service/" + item.Item2), false, onCreateService, item.Item1); } }
public static void AddConstraint(GenericMenu menu, BehaviourNode targetNode) { GenericMenu.MenuFunction2 onCreateConstraint = t => { Constraint constraint = BTUtils.CreateConstraint(t as Type); if (constraint != null) { targetNode.Constraints.Add(constraint); } }; foreach (var item in m_constraintMenuPaths) { menu.AddItem(new GUIContent(/*"Add Constraint/" + */ "Constraint/" + item.Item2), false, onCreateConstraint, item.Item1); } }
public void Draw() { BTUtils.DrawBezier( inPoint.rect.center, outPoint.rect.center, inPoint.rect.center + Vector2.left * 50f, outPoint.rect.center - Vector2.left * 50f ); // È¡ÏûÁ¬Ïß this._centerPos = (inPoint.rect.center + outPoint.rect.center) * 0.5f; if (Handles.Button(this._centerPos, Quaternion.identity, 4, 8, Handles.RectangleCap)) { //just draw } }
public void OnPasteNode(BTEditorGraphNode destination) { if (CanPaste(destination)) { BehaviourNode node = BTUtils.DeserializeNode(BTEditorCanvas.Current.Clipboard); BTEditorGraphNode child = destination.OnCreateChild(node); if (child != null) { SelectBranch(child); var undoState = new UndoNodeCreated(child); undoState.Title = "Pasted " + child.Node.Title; BTUndoSystem.RegisterUndo(undoState); } } }
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); }
public override void Undo() { if (CanUndo) { BehaviourNode node = BTUtils.DeserializeNode(m_serializedNode); if (m_childIndex >= 0) { var parentNode = m_graph.GetNodeByHash(m_parentNodeHash); var createdNode = parentNode.OnInsertChild(m_childIndex, node); m_createdNodeHash = m_graph.GetNodeHash(createdNode); } else { var parentNode = m_graph.GetNodeByHash(m_parentNodeHash); var createdNode = parentNode.OnCreateChild(node); m_createdNodeHash = m_graph.GetNodeHash(createdNode); } m_parentNodeHash = null; m_serializedNode = null; } }
public BTEditorGraphNode OnCreateChild(Type type) { if (type != null) { BehaviourNode node = BTUtils.CreateNode(type); if (node != null) { Vector2 nodeSize = BTEditorStyle.GetNodeSize(m_node); Vector2 nodePos = NodePosition + nodeSize + new Vector2(50, 0); nodePos.x = Mathf.Max(nodePos.x, 0.0f); nodePos.y = Mathf.Max(nodePos.y, 0.0f); // force horizontal nodePos.y = NodePosition.y; node.Position = nodePos; return(OnCreateChild(node)); } } return(null); }