Ejemplo n.º 1
0
    public void fillBHNode(List <BHNodeSerializable> serializableNodes)
    {
        BHNodeSerializable serializableNode = new BHNodeSerializable();

        serializableNode.nodeType          = (int)_nodeType;
        serializableNode.childCount        = _childNodes.Count;
        serializableNode.indexOfFirstChild = serializableNodes.Count + 1;
        serializableNode.editorPos         = _rect.position;

        if (_nodeType == NodeType.Action || _nodeType == NodeType.Conditional)
        {
            serializableNode.functionName = functionName;
        }

        serializableNodes.Add(serializableNode);

        for (int i = 0; i < _childNodes.Count; i++)
        {
            _childNodes[i].fillBHNode(serializableNodes);
        }
    }
Ejemplo n.º 2
0
    int readBHTreeComponent(int index, out BHEditorNode bhEditorNode)
    {
        BHNodeSerializable serializableNode = behaviourTreeComponent.bhNodesSerializable[index];

        bhEditorNode = new BHEditorNode((NodeType)serializableNode.nodeType,
                                        serializableNode.editorPos,
                                        nodeBoxStyle, childButtonStyle, parentButtonStyle);

        bhEditorNode.setFunctionName(serializableNode.functionName);
        bhEditorNode.removeNode = removeNode;
        bhEditorNode.setScriptType(script.GetClass());

        _nodes.Add(bhEditorNode);

        for (int i = 0; i < serializableNode.childCount; i++)
        {
            BHEditorNode childEditorNode;
            index = readBHTreeComponent(++index, out childEditorNode);
            childEditorNode.setParent(bhEditorNode);
            bhEditorNode.addChild(childEditorNode);
        }

        return(index);
    }
Ejemplo n.º 3
0
    public int loadTree <T>(int index, out BHNode node, T instanceType)
    {
        BHNodeSerializable serializableNode = bhNodesSerializable[index];

        MethodInfo   function;
        NodeFunction functionToExecute;

        switch ((NodeType)serializableNode.nodeType)
        {
        case NodeType.Sequencer:
            node = new BHSequencer();
            break;

        case NodeType.Selector:
            node = new BHSelector();
            break;

        case NodeType.LogicAnd:
            node = new BHLogicAnd();
            break;

        case NodeType.LogicOr:
            node = new BHLogicOr();
            break;

        case NodeType.DecoratorInverter:
            node = new BHDecoratorInverter();
            break;

        case NodeType.Conditional:
            node = new BHConditional();

            function = instanceType.GetType().GetMethod(serializableNode.functionName, BindingFlags.NonPublic | BindingFlags.Instance);
            if (function != null)
            {
                Debug.Log("setting function");
                functionToExecute = (NodeFunction)Delegate.CreateDelegate(typeof(NodeFunction),
                                                                          instanceType,
                                                                          function);
                node.setFunctionToExecute(functionToExecute);
            }
            break;

        case NodeType.Action:
            node = new BHAction();

            function = instanceType.GetType().GetMethod(serializableNode.functionName, BindingFlags.NonPublic | BindingFlags.Instance);
            if (function != null)
            {
                Debug.Log("setting function");
                functionToExecute = (NodeFunction)Delegate.CreateDelegate(typeof(NodeFunction),
                                                                          instanceType,
                                                                          function);
                node.setFunctionToExecute(functionToExecute);
            }
            break;

        default:
            node = new BHNode();
            break;
        }

        for (int i = 0; i < serializableNode.childCount; i++)
        {
            BHNode childNode;
            index = loadTree <T>(++index, out childNode, instanceType);
            node.addChild(childNode);
        }

        return(index);
    }