Although we have Visual Formula , you can still code up your evaluator for a specified cost term.
Evaluator requires Item Component as input. It supports 0 or up to 5 inputs. The basis of the Evaluator is:
public abstract class Evaluator : EvaluatorGeneric {}
public abstract class Evaluator<T0> : Evaluator {}
// ...
public abstract class Evaluator<T0, T1, T2, T3, T4> :
Evaluator<T0, T1, T2, T3>
You can create an evaluator that supports more inputs according to this format.
You should override the Evaluate function. Here is the example of IntSumEvaluator
public override async Task<float> Evaluate()
{
await Task.Yield();
var items = GetInvokedItems(); // Filtered by meta
float sum = 0;
foreach(var i in items)
{
var f = i.GetItemComponent(attribute);
if (f != null)
{
sum += (int)f.GetValue();
}
else
{
Debug.LogError($"[MCMC] Item {i} has not {attribute} Item Component");
}
}
return Mathf.Clamp01(Mathf.Abs(sum * 1.0f / maxNumber));
}
Thanks to Odin Inspector
, we can create our smart attribute suggestion engine that suggests the item attribute according to the input type smartly.
Here is the example of IntSumEvaluatorGeneric
:
public class IntSumEvaluator : Evaluator<IntComponent>
{
[BoxGroup("Settings")]
[Required]
[OdinSerialize]
[ValueDropdown("GetAttributesT0")]
public string attribute;
}
You can increase the number of GetAttributesT0
according to the number of inputs to get the right attribute suggestion.