This is going to be a bit tricky but it is really bothering me so I hope you will have the patience to follow along :)
Here is my very basic architecture:
So in the framework, I am creating I have Actions
these currently have a list of Conditions
or Considerations (same thing different name).
While each Condition
share some of the same functionality such as:
- Returning a float score
- Using an evaluation formula
They implement these in very different ways depending on the situation.
Take a look at the following code:
[CreateAssetMenu(fileName = "Consider my health vs max health",
menuName = "AnAppGames/AI/Example/Decisions/Health Consideration")]
public class MyHealth : BaseConsideration
{
private float health;
public float maxHealth;
public override float Consider<T>(BaseAiContext context, BaseAction action, T value)
{
health = value as float;
return EvaluateValues(health / maxHealth);
}
}
What you are looking at is my first attempt at making some sort of "reusable" Consideration
.
Now in the continuation of my development, I had to make the following Consideration
:
public class DistanceFromMe : BaseConsideration
{
public float minRange;
public float maxRange;
private float ConsiderWithValues(Transform target, Transform caller)
{
return EvaluateValues(new FloatData(Vector3.Distance(target.transform.position, caller.position),
minRange,
maxRange).GetNormalizedData());
}
public override float Consider<T>(BaseAiContext context, BaseAction action, T value)
{
Transform target = value as Transform;
if (target == null)
{
return 0;
}
return ConsiderWithValues(target.transform, context.transform);
}
public override float Consider(float x)
{
return EvaluateValues(new FloatData(x,
minRange,
maxRange).GetNormalizedData());
}
}
And now the trouble begins I thought "This is not a scaleable solution" as soon as I need more than 1 generic parameter I am screwed and have to create additional overrides of this Consider
function.
So what I need is somehow to add different types of parameters to the Consideration
however these parameters will vary a lot.
Another problem I have with this is that when I loop through the list I won't be able to tell what parameters i needed and how to fulfill the needs of the Consideration
.
I thought of different ways of dealing with this inside the editor but I have come up empty :(
Can anyone help me out with this architectural mess? :)
It is worth mentioning that at the current point each of these are ScriptableObjects I am not 100 set in the fact that they should be but i am just not sure how to deal with this problem.