Esempio n. 1
0
 public void CreateRoot(bool isSequence, string name)
 {
     m_root = new ConnorNode(isSequence, name);
 }
Esempio n. 2
0
 public void SetRoot(ConnorNode root)
 {
     m_root = root;
 }
    private void OnGUI()
    {
        funcstionsSrc = source.GetComponent <Functions>();
        Type t = funcstionsSrc.GetType();

        functionListSrc = t.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
        for (int i = 0; i < functionListSrc.Length; i++)
        {
            //functionList[i] = functionListSrc[i].Name;
            functionList.Add(functionListSrc[i].Name);
        }

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("AI Actor", EditorStyles.boldLabel);
        source = (GameObject)EditorGUILayout.ObjectField(source, typeof(GameObject), true);
        EditorGUILayout.EndHorizontal();


        //Stops things from drawing if there is no gameobject assgined
        if (source != null)
        {
            if (GUILayout.Button("Create Behaviour Tree"))
            {
                if (source.GetComponent <BehaviourTree>() == null)
                {
                    source.AddComponent <BehaviourTree>();
                    behaviourTreeSrc = source.GetComponent <BehaviourTree>();

                    behaviourTreeSrc.CreateRoot(true, "Behaviour Tree Root");
                    currentNode = behaviourTreeSrc.GetRoot();
                }
            }
            if (GUILayout.Button("Find"))
            {
                behaviourTreeSrc = null;
                //behaviourTree.SetRoot(behaviourTree.GetRoot());
                behaviourTreeSrc = source.GetComponent <BehaviourTree>();
                behaviourTreeSrc.SetRoot(source.GetComponent <BehaviourTree>().GetRoot());
            }
            if (GUILayout.Button("Clear"))
            {
                DestroyImmediate(source.GetComponent <BehaviourTree>());
                behaviourTreeSrc = null;
            }

            if (behaviourTreeSrc != null)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Root", EditorStyles.boldLabel);
                GUILayout.Box(behaviourTreeSrc.GetRoot().GetName());
                EditorGUILayout.EndHorizontal();
                //---------------------------------------------------
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Node name:", EditorStyles.boldLabel);
                //nodeName = EditorGUILayout.TextField("", nodeName);
                nodeName = EditorGUILayout.TextField(nodeName);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Functions", EditorStyles.boldLabel);
                //EditorGUILayout.DropdownButton(funclist, FocusType.Passive);
                index = EditorGUILayout.Popup(index, functionList.ToArray());
                EditorGUILayout.EndHorizontal();


                //if (currentNode.GetType() != typeof(ActionNode))
                //{
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Create Sequence"))
                {
                    ConnorNode temp = (ConnorNode)currentNode;
                    if (temp != null)
                    {
                        temp.AddChild(new ConnorNode(true, nodeName));
                    }
                }
                if (GUILayout.Button("Create Selector"))
                {
                    ConnorNode temp = (ConnorNode)currentNode;
                    if (temp != null)
                    {
                        temp.AddChild(new ConnorNode(false, nodeName));
                        //GetWindow<BehaviourTreeEditor>("Name");
                    }
                }
                if (GUILayout.Button("Create Action"))
                {
                    ConnorNode temp = (ConnorNode)currentNode;
                    if (temp != null)
                    {
                        temp.AddChild(new ActionNode((ActionNode.ActionNodeDelegate)Delegate.CreateDelegate(typeof(ActionNode.ActionNodeDelegate), source.GetComponent <Functions>(), functionListSrc[index]), nodeName));
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
        }

        if (behaviourTreeSrc != null)
        {
            if (behaviourTreeSrc.GetRoot() != null)
            {
                behaviourTreeSrc.GetRoot().PrintGUIElement(this);
            }
        }
    }