Firstborn/Assets/RPG Creation Kit/Scripts/BehaviourTrees/Nodes/RootNode.cs

79 lines
1.9 KiB
C#
Raw Permalink Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XNode;
using RPGCreationKit.BehaviourTree;
[CreateNodeMenu("RPGCK_BehaviourTree/RootNode", order = 0)]
[System.Serializable]
public class RootNode : BTNode
{
string state;
public bool isNpcToNpcDialogue; // Is this a dialogue that doesn't involve the player?
[Output(ShowBackingValue.Never)] public Node onExitNode;
[Output] public BTNode firstNode;
// Use this for initialization
protected override void Init()
{
base.Init();
}
// Return the correct value of an output port when requested
public override object GetValue(NodePort port)
{
return null; // Replace this
}
public override NodeState Execute()
{
// Its state is the state of the child
firstNode = ((BTNode)GetOutputPort("firstNode").Connection.node);
switch(m_NodeState)
{
case NodeState.Failure:
m_NodeState = NodeState.Failure;
return m_NodeState;
case NodeState.Running:
case NodeState.Null:
// Continue ticking
firstNode.Execute();
m_NodeState = firstNode.m_NodeState;
return m_NodeState;
case NodeState.Success:
m_NodeState = NodeState.Success;
return m_NodeState;
default:
break;
}
return m_NodeState;
}
public override void OnCreateConnection(NodePort from, NodePort to)
{
base.OnCreateConnection(from, to);
}
public override void OnRemoveConnection(NodePort port)
{
base.OnRemoveConnection(port);
}
public override void OnStart()
{
}
public override void ReorderChild()
{
((BTNode)GetOutputPort("firstNode").node).indexInSequence = 0;
}
}