77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using XNode;
|
||
|
using RPGCreationKit.BehaviourTree;
|
||
|
using RPGCreationKit.AI;
|
||
|
using RPGCreationKit.BehaviourTree.Data;
|
||
|
|
||
|
namespace RPGCreationKit.BehaviourTree
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Allows the bool checking directly on a field of RckAI.
|
||
|
/// </summary>
|
||
|
[CreateNodeMenu("RPGCK_BehaviourTree/Actions/This AI/Checks/Field Bool Check", order = 1)]
|
||
|
[System.Serializable]
|
||
|
public class AIField_BoolCheckNode : BTNode
|
||
|
{
|
||
|
public bool not = false;
|
||
|
|
||
|
public string ComponentToGet = "RckAI";
|
||
|
public string FieldToGet;
|
||
|
|
||
|
// 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 void OnStart()
|
||
|
{
|
||
|
STARTED = true;
|
||
|
}
|
||
|
|
||
|
public override NodeState Execute()
|
||
|
{
|
||
|
if (m_NodeState == NodeState.Success || m_NodeState == NodeState.Failure)
|
||
|
if (hasEvaluated == true)
|
||
|
return m_NodeState;
|
||
|
|
||
|
if (!STARTED)
|
||
|
OnStart();
|
||
|
|
||
|
var component = (this.graph as RPGCK_BT).ai;
|
||
|
|
||
|
var field = (this.graph as RPGCK_BT).ai.GetType().GetField(FieldToGet);
|
||
|
|
||
|
bool boolToCheck = (bool)field.GetValue(component);
|
||
|
|
||
|
if (not)
|
||
|
m_NodeState = (boolToCheck) ? NodeState.Failure : NodeState.Success;
|
||
|
else
|
||
|
m_NodeState = (boolToCheck) ? NodeState.Success : NodeState.Failure;
|
||
|
|
||
|
hasEvaluated = true;
|
||
|
return m_NodeState;
|
||
|
}
|
||
|
|
||
|
|
||
|
public override void OnRemoveConnection(NodePort port)
|
||
|
{
|
||
|
base.OnRemoveConnection(port);
|
||
|
indexInSequence = -1;
|
||
|
}
|
||
|
|
||
|
public override void ReEvaluate()
|
||
|
{
|
||
|
if (m_NodeState != NodeState.Running)
|
||
|
base.ReEvaluate();
|
||
|
}
|
||
|
}
|
||
|
}
|