Example #1
0
    public ActorStateNode GenerateEntryPointNode(ActorStateTransitionCondition cond = null)
    {
        var node = new ActorStateNode
        {
            title         = "AWAKE",
            GUID          = "0",
            relevantState = null,
            EntryPoint    = true
        };

        var generatePort = GeneratePort(node, Direction.Output);

        generatePort.portName = "Next";

        var condField = new ObjectField
        {
            objectType = typeof(ActorStateTransitionCondition),
            value      = (cond == null ? ScriptableObject.CreateInstance <AlwaysTrueTransitionCondition>() : cond)
        };

        generatePort.contentContainer.Add(condField);
        node.outputContainer.Add(generatePort);


        node.styleSheets.Add(Resources.Load <StyleSheet>("Node"));
        node.RefreshExpandedState();
        node.RefreshPorts();

        node.SetPosition(new Rect(100, 200, 100, 150));
        return(node);
    }
Example #2
0
    public ActorStateNode GenerateAINode(string nodeName, ActorState relevantState = null)
    {
        var retNode = new ActorStateNode
        {
            relevantState = relevantState,
            GUID          = Guid.NewGuid().ToString(),
        };

        var oldLabel = retNode.titleContainer.Q <Label>();

        retNode.titleContainer.Remove(oldLabel);

        var inputPort = GeneratePort(retNode, Direction.Input, Port.Capacity.Multi);

        inputPort.portName = "Input";
        retNode.inputContainer.Add(inputPort);
        retNode.styleSheets.Add(Resources.Load <StyleSheet>("Node"));

        var button = new Button(() => { AddConditionPort(retNode); });

        button.text      = "New State Transition Condition";
        retNode.nodeName = nodeName;
        var titleText = new TextField();

        titleText.value = nodeName;
        titleText.RegisterValueChangedCallback(evt =>
        {
            retNode.nodeName = evt.newValue;
        });
        retNode.titleContainer.Add(titleText);


        retNode.titleContainer.Add(button);

        /*retNode.titleContainer.Add(new TextField
         * {
         *  text = nodeName
         * });*/
        retNode.mainContainer.Add(new Label("State Behaviour"));
        var condField = new ObjectField
        {
            objectType = typeof(ActorState),
            value      = relevantState
        };

        condField.RegisterValueChangedCallback(evt => retNode.relevantState = evt.newValue as ActorState);
        retNode.mainContainer.Add(condField);
        retNode.SetPosition(new Rect(Vector2.zero, defaultNodeSize));
        retNode.RefreshExpandedState();
        retNode.RefreshPorts();

        return(retNode);
    }