public override void NodeDeleted(BaseNodeEditor node) { if (Parent && Parent.Equals(node)) { Parent = null; } }
public override void AddChild(BaseNodeEditor node) { if (child != null) { child.Parent = null; UnityEngine.Object.DestroyImmediate(child, true); } child = node; node.Parent = this; }
private void CreateNewBT() { bt = BehaviourTreeCreator.Create(); if (bt != null) { root = null; bt.nodes = new List <BaseNodeEditor>(); string relPath = AssetDatabase.GetAssetPath(bt); EditorPrefs.SetString("AssetPath", relPath); } }
public override void NodeDeleted(BaseNodeEditor node) { if (Parent && Parent.Equals(node)) { Parent = null; } if (children.Contains(node)) { children.Remove(node); } }
void CheckMousePos() { isNodeSelected = false; selectedNode = null; for (int i = 0; i < bt.nodes.Count; i++) { if (bt.nodes [i].nodeRect.Contains(mousePos)) { isNodeSelected = true; selectedNode = bt.nodes [i]; break; } } }
public override string ComputeResult() { BaseNodeEditor child = editorNode.child; if (child.runtimeNode.ResultValue.Equals(Result.RUNNING.ToString())) { return(Result.RUNNING.ToString()); } else if (child.runtimeNode.ResultValue.Equals(Result.SUCCESS.ToString())) { return(Result.FAILURE.ToString()); } else { return(Result.SUCCESS.ToString()); } }
private void LoadBT() { string absPath = EditorUtility.OpenFilePanel("Select a Behaviour Tree...", Application.dataPath, "asset"); if (absPath.StartsWith(Application.dataPath)) { string relPath = absPath.Substring(Application.dataPath.Length - "Assets".Length); bt = (BehaviourTreeEditor)AssetDatabase.LoadAssetAtPath(relPath, typeof(BehaviourTreeEditor)); if (bt != null && bt.nodes == null) { bt.nodes = new List <BaseNodeEditor> (); EditorPrefs.SetString("AssetPath", relPath); } root = null; } Debug.Log("BT Loaded!"); }
void OnEnable() { if (EditorPrefs.HasKey("AssetPath") && File.Exists(EditorPrefs.GetString("AssetPath"))) { string assetPath = EditorPrefs.GetString("AssetPath"); bt = (BehaviourTreeEditor)AssetDatabase.LoadAssetAtPath(assetPath, typeof(BehaviourTreeEditor)); if (bt != null && bt.nodes == null) { bt.nodes = new List <BaseNodeEditor> (); } if (bt != null && bt.nodes.Count > 0) { root = bt.nodes [0]; } } AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); }
void DeleteNode() { BaseNodeEditor toRemove = selectedNode; bt.nodes.Remove(toRemove); if (toRemove.Equals(root)) { root = null; foreach (BaseNodeEditor node in bt.nodes) { UnityEngine.Object.DestroyImmediate(node, true); } bt.nodes.Clear(); } else { foreach (BaseNodeEditor node in bt.nodes) { node.NodeDeleted(toRemove); } } UnityEngine.Object.DestroyImmediate(toRemove, true); AssetDatabase.SaveAssets(); }
public override void NodeDeleted(BaseNodeEditor node) { base.NodeDeleted(node); }
public override void AddChild(BaseNodeEditor node) { base.AddChild(node); }
private static void OpenWindow() { BaseNodeEditor window = GetWindow <BaseNodeEditor>(); window.titleContent = new GUIContent("test node editor"); }
public virtual void AddChild(BaseNodeEditor node) { }
public virtual void NodeDeleted(BaseNodeEditor node) { }
private void OnGUI() { if (bt == null) { DrawToolbar(); return; } Event e = Event.current; mousePos = e.mousePosition; if (mousePos.x >= 250 && mousePos.y >= 20 && e.button == 1 && e.type == EventType.MouseDown) { CheckMousePos(); if (!isNodeSelected) { if (root == null) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Add root/Sequence"), false, AddSequence); menu.AddItem(new GUIContent("Add root/Selector"), false, AddSelector); menu.AddItem(new GUIContent("Add root/Inverter"), false, AddInverter); menu.ShowAsContext(); e.Use(); } } else { var behavNodes = Assembly.GetExecutingAssembly().GetTypes() .Where(t => t.BaseType.Equals(typeof(BaseBehaviourNode))) .ToList(); GenericMenu menu = new GenericMenu(); if (!selectedNode.GetType().Equals(typeof(BehaviourNodeEditor)) && !selectedNode.GetType().BaseType.Equals(typeof(BehaviourNodeEditor))) { menu.AddItem(new GUIContent("Add child/Sequence"), false, AddSequenceChild); menu.AddItem(new GUIContent("Add child/Selector"), false, AddSelectorChild); menu.AddItem(new GUIContent("Add child/Inverter"), false, AddInverterChild); menu.AddItem(new GUIContent("Add child/Behaviour/PlaceHolder"), false, AddBehaviour, "PlaceHolder"); foreach (var nodeType in behavNodes) { menu.AddItem(new GUIContent("Add child/Behaviour/" + nodeType.Name), false, AddBehaviour, nodeType); } menu.AddSeparator(""); } menu.AddItem(new GUIContent("Delete Node"), false, DeleteNode); menu.ShowAsContext(); e.Use(); } } if (bt.nodes.Count > 0 && root == null) { root = bt.nodes [0]; } leftSideRect = horizontalSplitView.BeginSplitView(); verticalSplitView.BeginSplitView(); DrawParameters(); verticalSplitView.Split(); DrawBlackboard(); verticalSplitView.EndSplitView(); horizontalSplitView.Split(); DrawToolbar(); foreach (BaseNodeEditor node in bt.nodes) { node.DrawConnections(); } BeginWindows(); { for (int i = 0; i < bt.nodes.Count; i++) { Rect prevRect = bt.nodes[i].nodeRect; bt.nodes[i].nodeRect = GUI.Window(i, bt.nodes[i].nodeRect, DrawNode, new GUIContent(bt.nodes[i].title)); if (bt.nodes [i].nodeRect.x < leftSideRect.xMax - bt.nodes [i].nodeRect.x + 10) { bt.nodes [i].nodeRect.x = prevRect.x; } if (bt.nodes [i].nodeRect.y < 20) { bt.nodes [i].nodeRect.y = prevRect.y; } } } EndWindows(); horizontalSplitView.EndSplitView(); }
public override void AddChild(BaseNodeEditor node) { children.Add(node); node.Parent = this; }