Hello.
I Created 2 ScriptableObjects to work on my IA.
namespace Game.Units.IA.Behaviours.Conditions {
public delegate bool DoResultDelegate();
public class BehaviourCondition : ScriptableObject {
protected event DoResultDelegate DoResult;
public GameObject gameObject;
public bool Result() {
Debug.Log("resulting...");
if (DoResult != null) {
return DoResult();
} else
return false;
}
}
}
namespace Game.Units.IA.Behaviours {
public class IABehaviour : ScriptableObject {
#region variables
[SerializeField] private IABehaviourType behaviourType;
[SerializeField] private BehaviourCondition[] conditions;
[SerializeField] private GameObject gameObject;
protected Action OnAct;
#endregion
#region methods
protected virtual void Awake() {
if (gameObject != null)
foreach (BehaviourCondition BC in conditions) {
BC.gameObject = gameObject;
}
}
private bool CanAct() {
bool canAct = false;
foreach(BehaviourCondition BC in conditions) {
canAct = canAct && BC.Result();
}
return canAct;
}
/// <summary>
/// executes the behaviour.
/// </summary>
public void Act() {
if (CanAct()) {
if (OnAct != null)
OnAct();
}
}
#endregion
#region properties
public IABehaviourType BehaviourType {
get { return behaviourType; }
set { behaviourType = value; }
}
public GameObject GameObject {
get { return gameObject; }
set { gameObject = value; }
}
#endregion
}
}
On my IAController at line 16 I execute my ScriptableObject.
namespace Game.Units.IA {
[RequireComponent(typeof(NavMeshAgent))]
public class IAController : MonoBehaviour {
#region variables
[SerializeField] private IABehaviour behaviour;
private NavMeshAgent agent;
#endregion
#region methods
private void Awake() {
agent = GetComponent<NavMeshAgent>();
behaviour.GameObject = gameObject;
}
private void Update() {
behaviour.Act();
}
#endregion
#region properties
public IABehaviour Behaviour {
get { return behaviour; }
set { behaviour = value; }
}
#endregion
}
}
The problem is: On my IABehaviour on line 21, when i’m debugging, the variable have my scriptableObject, but it is not going through the Result method on BehaviourCondition. Why?