Esempio n. 1
0
    private NodeData InitializeNodes(NodeData node)
    {
        foreach (var child in GetChildNodes(node.GUID))
        {
            nodeStack.Push(InitializeNodes(child));
        }

        switch ((NodeTypes)node.nodeType)
        {
        case NodeTypes.Composite:
            Composite           compositeDuplicate = ScriptableObject.Instantiate(node.compositeInstance);
            List <NodeData>     childDataNodes     = GetChildNodes(node.GUID);
            List <AbstractNode> childNodes         = new List <AbstractNode>();

            for (int i = 0; i < childDataNodes.Count; i++)
            {
                childNodes.Add(GetNodeInstance(nodeStack.Pop()));
            }

            childNodes.Reverse();

            compositeDuplicate.context = context;
            compositeDuplicate.Construct(childNodes);

            node.compositeInstance = compositeDuplicate;

            return(node);

        case NodeTypes.Decorator:
            Decorator decoratorDuplicate = ScriptableObject.Instantiate(node.decoratorInstance);

            decoratorDuplicate.context = context;
            decoratorDuplicate.Construct(GetNodeInstance(nodeStack.Pop()));

            node.decoratorInstance = decoratorDuplicate;
            return(node);

        case NodeTypes.Action:
            Action actionDuplicate = ScriptableObject.Instantiate(node.actionInstance);

            actionDuplicate.context = context;
            actionDuplicate.Construct();

            node.actionInstance = actionDuplicate;
            return(node);

        default:
            break;
        }

        return(null);
    }