BloodAndGore/Assets/Scripts/AI/BehaviourBranch.cs

40 lines
1.3 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 BehaviourBranch : BehaviourNode {
public Trigger Trigger;
2019-08-04 17:35:24 +02:00
// FIXME: Change these from arrays to just single ones
// BehaviourLeaf already has the capability to have multiple behaviours
2019-08-03 17:36:17 +02:00
public BehaviourNode[] TriggeredNodes;
public BehaviourNode[] NotTriggeredNodes;
2019-08-04 15:44:44 +02:00
private String MostRecentExecution;
2019-08-03 17:36:17 +02:00
/* Returns true if any action was taken. */
public override bool Execute(Enemy subject) {
2019-08-04 15:44:44 +02:00
if (Trigger != null && Trigger.IsTriggered(subject)) {
2019-08-03 17:36:17 +02:00
foreach (BehaviourNode Node in TriggeredNodes) {
if (Node.Execute(subject)) {
2019-08-04 15:44:44 +02:00
MostRecentExecution = Node.GetExecutedName();
2019-08-03 17:36:17 +02:00
return true;
}
}
} else {
foreach (BehaviourNode Node in NotTriggeredNodes) {
if (Node.Execute(subject)) {
2019-08-04 15:44:44 +02:00
MostRecentExecution = Node.GetExecutedName();
2019-08-03 17:36:17 +02:00
return true;
}
}
}
return false;
}
2019-08-04 15:44:44 +02:00
public override string GetExecutedName() {
return MostRecentExecution;
}
2019-08-03 17:36:17 +02:00
}
}