Exemplo n.º 1
0
    void NewChildDecorator(BehaviourTreeDecoratorNode.Type type)
    {
        BehaviourTreeDecoratorNode newNode = (BehaviourTreeDecoratorNode)ScriptableObject.CreateInstance("BehaviourTreeDecoratorNode");

        newNode.type          = type;
        newNode.ID            = GetNextWindowID();
        newNode.displayedName = newNode.type.ToString();
        this.selectedNode.AddChild(newNode);
        AddNodeToAssets(newNode);
        SaveBehaviourTree();
        this.selectedNode = newNode;
    }
Exemplo n.º 2
0
    void NewParentDecorator(BehaviourTreeDecoratorNode.Type type)
    {
        BehaviourTreeDecoratorNode newNode = (BehaviourTreeDecoratorNode)ScriptableObject.CreateInstance("BehaviourTreeDecoratorNode");

        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;
    }
    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();
            }
        }
    }