BloodAndGore/Assets/Scripts/AI/BehaviourBranch.cs
2019-08-04 18:35:28 +03:00

40 lines
1.3 KiB
C#

using System;
using UnityEngine;
namespace Saltosion.OneWeapon.AI {
[Serializable]
public class BehaviourBranch : BehaviourNode {
public Trigger Trigger;
// FIXME: Change these from arrays to just single ones
// BehaviourLeaf already has the capability to have multiple behaviours
public BehaviourNode[] TriggeredNodes;
public BehaviourNode[] NotTriggeredNodes;
private String MostRecentExecution;
/* Returns true if any action was taken. */
public override bool Execute(Enemy subject) {
if (Trigger != null && Trigger.IsTriggered(subject)) {
foreach (BehaviourNode Node in TriggeredNodes) {
if (Node.Execute(subject)) {
MostRecentExecution = Node.GetExecutedName();
return true;
}
}
} else {
foreach (BehaviourNode Node in NotTriggeredNodes) {
if (Node.Execute(subject)) {
MostRecentExecution = Node.GetExecutedName();
return true;
}
}
}
return false;
}
public override string GetExecutedName() {
return MostRecentExecution;
}
}
}