using System.Collections; using System.Collections.Generic; using UnityEngine; namespace MBT { public abstract class Condition : Decorator { protected bool lastConditionCheckResult = false; public override NodeResult Execute() { if (!TryGetChild(out Node node)) { return NodeResult.failure; } if (node.status == Status.Success || node.status == Status.Failure) { return NodeResult.From(node.status); } lastConditionCheckResult = Check(); if (lastConditionCheckResult == false) { return NodeResult.failure; } return node.runningNodeResult; } /// /// Reevaluate condition and try to abort the tree if required /// /// Abort type protected void EvaluateConditionAndTryAbort(Abort abortType) { bool c = Check(); if (c != lastConditionCheckResult) { lastConditionCheckResult = c; TryAbort(abortType); } } /// /// Method called to check condition /// /// Condition result public abstract bool Check(); } }