Esempio n. 1
0
    void SetColor(BehaviourTreeNode node)
    {
        GUI.color = colorDefault;

        if (node is BehaviourTreeControlNode)
        {
            BehaviourTreeControlNode controlNode = (BehaviourTreeControlNode)node;

            switch (controlNode.type)
            {
            case BehaviourTreeControlNode.Type.SELECTOR: GUI.color = colorControlSelectorNode; break;

            case BehaviourTreeControlNode.Type.SEQUENCE: GUI.color = colorControlSequenceNode; break;

            case BehaviourTreeControlNode.Type.PARALLEL: GUI.color = colorControlParallelNode; break;

            default: GUI.color = colorDefault; break;
            }
        }
        else if (node is BehaviourTreeExecutionNode)
        {
            GUI.color = colorExecutionNode;
        }
        else if (node is BehaviourTreeDecoratorNode)
        {
            GUI.color = colorDecoratorNode;
        }
        else if (node is BehaviourTreeSubTreeNode)
        {
            GUI.color = colorBehaviourTreeNode;
        }
    }
Esempio n. 2
0
    void NewChildControl(BehaviourTreeControlNode.Type type)
    {
        BehaviourTreeControlNode newNode = (BehaviourTreeControlNode)ScriptableObject.CreateInstance("BehaviourTreeControlNode");

        newNode.type          = type;
        newNode.ID            = GetNextWindowID();
        newNode.displayedName = newNode.type.ToString();
        this.selectedNode.AddChild(newNode);
        AddNodeToAssets(newNode);
        SaveBehaviourTree();
        this.selectedNode = newNode;
    }
Esempio n. 3
0
    void NewParentControl(BehaviourTreeControlNode.Type type)
    {
        BehaviourTreeControlNode newNode = (BehaviourTreeControlNode)ScriptableObject.CreateInstance("BehaviourTreeControlNode");

        newNode.type          = type;
        newNode.ID            = GetNextWindowID();
        newNode.displayedName = newNode.type.ToString().Replace('_', ' ');
        BehaviourTreeNode parent = FindParentOfNodeByID(BehaviourTreeEditorWindow.behaviourTree, this.selectedNode.ID);

        parent.ReplaceChild(this.selectedNode, newNode);
        newNode.AddChild(this.selectedNode);
        AddNodeToAssets(newNode);
        SaveBehaviourTree();
        this.selectedNode = newNode;
    }
Esempio n. 4
0
    void ControlWindowFunction(int windowID)
    {
        BehaviourTreeControlNode node = (BehaviourTreeControlNode)FindNodeByID(BehaviourTreeEditorWindow.behaviourTree, windowID);

        Event current = Event.current;

        if (current.type == EventType.MouseDown && current.button == 1)
        {
            this.selectedNode = node;

            if (Selection.activeObject != BehaviourTreeEditorWindow.behaviourTree)
            {
                SelectNodeButDontChangeProjectView();
            }

            GenericMenu menu = new GenericMenu();

            AddNewChildOption(menu, true);
            AddInsertNewParentOptions(menu);
            AddMoveOption(menu);
            if (this.selectedNode.ChildrenCount() <= 1)
            {
                menu.AddItem(new GUIContent("Delete Node"), false, DeleteNodeCallback);
                menu.AddDisabledItem(new GUIContent("Delete Branch"));
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Delete Node"));
                menu.AddItem(new GUIContent("Delete Branch"), false, DeleteBranchCallback);
            }

            menu.ShowAsContext();

            current.Use();
        }
        else if (current.type == EventType.MouseDown && current.button == 0)
        {
            this.selectedNode = node;

            if (Selection.activeObject != BehaviourTreeEditorWindow.behaviourTree)
            {
                SelectNodeButDontChangeProjectView();
            }

            current.Use();
        }
    }
    public override void OnInspectorGUI()
    {
        Repaint();

        GUIStyle titleStyle = new GUIStyle();

        titleStyle.fontSize = 20;

        GUIStyle partStyle = new GUIStyle();

        partStyle.fontSize = 15;

        if (BehaviourTreeEditorWindow.Instance == null)
        {
            return;
        }

        BehaviourTreeNode selectedNode = BehaviourTreeEditorWindow.Instance.selectedNode;

        if (selectedNode == null)
        {
            return;
        }

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label(selectedNode.displayedName, titleStyle);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUILayout.Space(30);

        if (selectedNode is BehaviourTreeControlNode)
        {
            BehaviourTreeControlNode node = (BehaviourTreeControlNode)selectedNode;

            GUI.color = Color.white;

            BehaviourTreeControlNode.Type initialTypeValue = node.type;

            BehaviourTreeControlNode.Type typeValue = (BehaviourTreeControlNode.Type)EditorGUILayout.EnumPopup("Type", initialTypeValue);

            if (typeValue != initialTypeValue)
            {
                node.type          = typeValue;
                node.displayedName = typeValue.ToString().Replace('_', ' ');
                BehaviourTreeEditorWindow.SaveNodeAnChildren(node);
                BehaviourTreeEditorWindow.Instance.Repaint();
            }

            if (node.type != BehaviourTreeControlNode.Type.PARALLEL)
            {
                bool initialMemorizeValue = node.startFromFirstNodeEachTick;

                GUILayout.Space(5);

                GUILayout.BeginHorizontal();

                GUI.color = Color.black;
                GUILayout.Label("Don't memorize running node", GUI.skin.label);

                GUI.color = Color.white;
                bool memorizeValue = EditorGUILayout.Toggle(initialMemorizeValue);
                if (memorizeValue != initialMemorizeValue)
                {
                    node.startFromFirstNodeEachTick = memorizeValue;
                    BehaviourTreeEditorWindow.SaveNodeAnChildren(node);
                    BehaviourTreeEditorWindow.Instance.Repaint();
                }

                GUILayout.EndHorizontal();
            }
        }

        else if (selectedNode is BehaviourTreeExecutionNode)
        {
            BehaviourTreeExecutionNode node = (BehaviourTreeExecutionNode)selectedNode;

            if (node.task != null)
            {
                // GUILayout.Space(nodeSize.y * zoomScale);

                PropertyReader.Variable[] variables = PropertyReader.GetFields(node.task.GetType());

                GUILayout.Label("PARAMETER", partStyle);

                foreach (PropertyReader.Variable variable in variables)
                {
                    if (variable.name.StartsWith("param_"))
                    {
                        GUILayout.Space(5);
                        AddParameterField(node, variable);
                    }
                }

                GUILayout.Space(20);

                GUILayout.Label("INPUT", partStyle);

                foreach (PropertyReader.Variable variable in variables)
                {
                    if (variable.name.StartsWith("in_"))
                    {
                        GUILayout.Space(5);
                        AddContextField(node, variable);
                    }
                }

                GUILayout.Space(20);

                GUILayout.Label("OUTPUT", partStyle);

                foreach (PropertyReader.Variable variable in variables)
                {
                    if (variable.name.StartsWith("out_"))
                    {
                        GUILayout.Space(5);
                        AddContextField(node, variable);
                    }
                }
            }
        }

        else if (selectedNode is BehaviourTreeDecoratorNode)
        {
            BehaviourTreeDecoratorNode node = (BehaviourTreeDecoratorNode)selectedNode;

            GUI.color = Color.white;

            BehaviourTreeDecoratorNode.Type initialTypeValue = node.type;

            BehaviourTreeDecoratorNode.Type typeValue = (BehaviourTreeDecoratorNode.Type)EditorGUILayout.EnumPopup("Type", initialTypeValue);

            if (typeValue != initialTypeValue)
            {
                node.type          = typeValue;
                node.displayedName = typeValue.ToString().Replace('_', ' ');
                BehaviourTreeEditorWindow.SaveNodeAnChildren(node);
                BehaviourTreeEditorWindow.Instance.Repaint();
            }
        }

        else if (selectedNode is BehaviourTreeSubTreeNode)
        {
            BehaviourTreeSubTreeNode node = (BehaviourTreeSubTreeNode)selectedNode;

            GUI.color = Color.white;

            BehaviourTree initialValue = node.subTree;

            BehaviourTree newValue = (BehaviourTree)EditorGUILayout.ObjectField(node.subTree, typeof(BehaviourTree), false);

            if (newValue != initialValue)
            {
                node.subTree       = newValue;
                node.displayedName = newValue.ToString().Replace('_', ' ').Split('(')[0];
                BehaviourTreeEditorWindow.SaveNodeAnChildren(node);
                BehaviourTreeEditorWindow.Instance.Repaint();
            }
        }
    }