Create -> RGame -> Value -> ValueConfig. You can edit your desired stat here.
Create -> RGame -> Value -> Runtime Values. This is your entity's Stat Data Manager. You can drag and drop the ValueConfig you want into it.
Drag and drop the created Runtime Value SO into the Value SO to use it. You can use the ValueName, get Value, and MaxValue you want to look up by dragging and dropping them into the Value SO.
public SoleObjectRuntimeValueSO ValueSO;
ValueSO.GetValue(ValueName), ValueSO.GetMaxValue(ValueName)
The following is the UI code for displaying the properties in the example, and the effect at runtime.
Create -> RGame-> Formula .You can enter the formula here again, or you can test the formula below to see if it's correct, and if it's not, you'll get the appropriate error message. The format is @{parameter} ${variable} variable is the ValueName in your stat.
You can use it via the Evaluate method, In order to support multiple parameters, you need to pass in the parameter names and values used in a dictionary.
namespace RGame
{
/// <summary>
/// ScriptableObject for defining a formula and calculating its result.
/// </summary>
[CreateAssetMenu(fileName = "NewFormulaCal", menuName = "RGame/FormulaCal")]
public class FormulaCalSO : ScriptableObject
{
[TextArea]
public string Formula;
/// <summary>
/// Calculate the final value based on the formula and provided runtime values.
/// </summary>
public int Evaluate(SoleObjectRuntimeValueSO _runtimeValues, Dictionary<string, double> parameters = null)
{
var valueDic = new Dictionary<string, (int,int)>();
foreach (var item in _runtimeValues.RuntimeValues)
{
valueDic.Add(item.Key,(item.Value.GetCurrentValue(),item.Value.GetMaxValue()));
}
return FormulaParser.Evaluate(Formula,valueDic,parameters);
}
}
}