예제 #1
0
 public override void NodeDeleted(BaseNodeEditor node)
 {
     if (Parent && Parent.Equals(node))
     {
         Parent = null;
     }
 }
예제 #2
0
 public override void AddChild(BaseNodeEditor node)
 {
     if (child != null)
     {
         child.Parent = null;
         UnityEngine.Object.DestroyImmediate(child, true);
     }
     child       = node;
     node.Parent = this;
 }
예제 #3
0
 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);
     }
 }
예제 #4
0
 public override void NodeDeleted(BaseNodeEditor node)
 {
     if (Parent && Parent.Equals(node))
     {
         Parent = null;
     }
     if (children.Contains(node))
     {
         children.Remove(node);
     }
 }
예제 #5
0
    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());
        }
    }
예제 #7
0
    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!");
    }
예제 #8
0
    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();
    }
예제 #9
0
    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);
 }
예제 #12
0
    private static void OpenWindow()
    {
        BaseNodeEditor window = GetWindow <BaseNodeEditor>();

        window.titleContent = new GUIContent("test node editor");
    }
예제 #13
0
 public virtual void AddChild(BaseNodeEditor node)
 {
 }
예제 #14
0
 public virtual void NodeDeleted(BaseNodeEditor node)
 {
 }
예제 #15
0
    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();
    }
예제 #16
0
 public override void AddChild(BaseNodeEditor node)
 {
     children.Add(node);
     node.Parent = this;
 }