BloodAndGore/Assets/Scripts/AI/BehaviourLeaf.cs

34 lines
1.0 KiB
C#

using System;
using UnityEngine;
namespace Saltosion.OneWeapon.AI {
[Serializable]
public class BehaviourLeaf : BehaviourNode {
public AIBehaviour[] Behaviours;
public bool IsLeaf { get { return Behaviours.Length > 0; } }
private string ExecutedBehaviours = "";
/* Returns true if any action was taken. */
public override bool Execute(Enemy subject) {
bool Acted = false;
ExecutedBehaviours = "";
foreach (AIBehaviour Behaviour in Behaviours) {
if (Behaviour.CanBehave(subject)) {
ExecutedBehaviours += Behaviour.GetType().Name + ":" + Behaviour.CurrentStatus + ", ";
if (Behaviour.Execute(subject)) {
return true;
} else {
Acted = true;
}
}
}
return Acted;
}
public override string GetExecutedName() {
return ExecutedBehaviours;
}
}
}