BloodAndGore/Assets/Scripts/AI/BehaviourLeaf.cs

34 lines
1.0 KiB
C#
Raw Normal View History

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