Esempio n. 1
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;
    }
    private static BehaviourTreeNode CopyNodesRecursively(BehaviourTreeNode original)
    {
        BehaviourTreeNode result = UnityEngine.ScriptableObject.Instantiate(original);

        for (int i = 0; i < result.ChildrenCount(); i++)
        {
            result.ReplaceChild(result.GetChildren()[i], CopyNodesRecursively(original.GetChildren()[i]));
        }

        if (original is BehaviourTreeExecutionNode)
        {
            ((BehaviourTreeExecutionNode)result).task = UnityEngine.ScriptableObject.Instantiate(((BehaviourTreeExecutionNode)original).task);
        }

        if (original is BehaviourTreeSubTreeNode)
        {
            ((BehaviourTreeSubTreeNode)result).subTree = Copy(((BehaviourTreeSubTreeNode)original).subTree);
        }

        return(result);
    }
Esempio n. 3
0
    void DeleteNodeCallback()
    {
        if (!EditorUtility.DisplayDialog("Delete node ?",
                                         "Are you sure you want to delete the node " + this.selectedNode.displayedName + " ?",
                                         "Yes, delete this node", "No"))
        {
            return;
        }

        BehaviourTreeNode parent = FindParentOfNodeByID(BehaviourTreeEditorWindow.behaviourTree, this.selectedNode.ID);

        if (this.selectedNode.ChildrenCount() > 0)
        {
            parent.ReplaceChild(this.selectedNode, this.selectedNode.GetChildren()[0]);
        }
        else
        {
            parent.RemoveChild(this.selectedNode);
        }

        DeleteNodeAsset(this.selectedNode);
        AssetDatabase.Refresh();
        SaveBehaviourTree();
    }