959e80cf72
assets upload description.
105 lines
3.7 KiB
C#
105 lines
3.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using XNode;
|
|
using RPGCreationKit.BehaviourTree.Data;
|
|
|
|
namespace RPGCreationKit.BehaviourTree
|
|
{
|
|
[CreateNodeMenu("RPGCK_BehaviourTree/Comparison/Math/Int Comparison", order = 1)]
|
|
[System.Serializable]
|
|
public class CIntComparisonNode : BTNode
|
|
{
|
|
public bool firstUseVariable;
|
|
public BT_Int firstStoredValue;
|
|
public int firstInstantValue;
|
|
|
|
public ComparisionOperators operation;
|
|
|
|
public bool secondUseVariable;
|
|
public BT_Int secondStoredValue;
|
|
public int secondInstantValue;
|
|
|
|
|
|
public override void OnStart()
|
|
{
|
|
if (firstUseVariable)
|
|
// Solve references
|
|
firstStoredValue = (BT_Int)BTReference.SolveReference(this.graph as RPGCK_BT, firstStoredValue.name);
|
|
else
|
|
{
|
|
// Create a storedValue from instantreference
|
|
BT_Int newbtInt = CreateInstance<BT_Int>();
|
|
newbtInt.Name = "TEMP_BT_INT_FIRST";
|
|
newbtInt.value = firstInstantValue;
|
|
|
|
firstStoredValue = newbtInt;
|
|
}
|
|
|
|
if (secondUseVariable)
|
|
// Solve references
|
|
secondStoredValue = (BT_Int)BTReference.SolveReference(this.graph as RPGCK_BT, secondStoredValue.name);
|
|
else
|
|
{
|
|
// Create a storedValue from instantreference
|
|
BT_Int newbtInt = CreateInstance<BT_Int>();
|
|
newbtInt.Name = "TEMP_BT_INT_SECOND";
|
|
newbtInt.value = secondInstantValue;
|
|
|
|
secondStoredValue = newbtInt;
|
|
}
|
|
|
|
STARTED = true;
|
|
}
|
|
|
|
public override NodeState Execute()
|
|
{
|
|
if (m_NodeState == NodeState.Success || m_NodeState == NodeState.Failure)
|
|
if (hasEvaluated == true)
|
|
return m_NodeState;
|
|
|
|
if (!STARTED)
|
|
OnStart();
|
|
|
|
switch(operation)
|
|
{
|
|
case ComparisionOperators.Equal:
|
|
m_NodeState = (firstStoredValue.value == secondStoredValue.value) ? m_NodeState = NodeState.Success : NodeState.Failure;
|
|
break;
|
|
|
|
case ComparisionOperators.GreaterOrEqualThan:
|
|
m_NodeState = (firstStoredValue.value >= secondStoredValue.value) ? m_NodeState = NodeState.Success : NodeState.Failure;
|
|
break;
|
|
|
|
case ComparisionOperators.GreaterThan:
|
|
m_NodeState = (firstStoredValue.value > secondStoredValue.value) ? m_NodeState = NodeState.Success : NodeState.Failure;
|
|
break;
|
|
|
|
case ComparisionOperators.LessOrEqualThan:
|
|
m_NodeState = (firstStoredValue.value <= secondStoredValue.value) ? m_NodeState = NodeState.Success : NodeState.Failure;
|
|
break;
|
|
|
|
case ComparisionOperators.LessThan:
|
|
m_NodeState = (firstStoredValue.value < secondStoredValue.value) ? m_NodeState = NodeState.Success : NodeState.Failure;
|
|
break;
|
|
|
|
case ComparisionOperators.NotEqual:
|
|
m_NodeState = (firstStoredValue.value != secondStoredValue.value) ? m_NodeState = NodeState.Success : NodeState.Failure;
|
|
break;
|
|
|
|
default:
|
|
m_NodeState = NodeState.Failure;
|
|
break;
|
|
}
|
|
|
|
hasEvaluated = true;
|
|
return m_NodeState;
|
|
}
|
|
|
|
public override void ReEvaluate()
|
|
{
|
|
if (m_NodeState != NodeState.Running)
|
|
base.ReEvaluate();
|
|
}
|
|
}
|
|
} |