Runtime
This value system is borrowed from some well-known games such as World of Warcraft and Elden's Ring.
SoleValueRuntime
If you need to edit update rules or add rules you can do so in SoleValueRuntime.cs
.
SoleValueRuntime.cs
/// <summary>
/// Updates the cached current value.
/// </summary>
private void UpdateCurrentValue()
{
int baseCurrentValue = mBaseValue + mValueAdd.GetValue();
int mul = mValuePercentAdd.GetValue() * mValuePercentMul.GetValue();
mCurrentValue = (baseCurrentValue * mul) / 10000;
}
You can change the value at runtime by using the following four functions. You can also change the relationship between the current value and the maximum value here.
//Direct modification Examples include using props to recover,
//enemies attacking themselves, skill attacks, etc.
public void ModifyValue(int _modValue, bool _isMaxValue = false)
//Reference modifications, e.g. equipment, special buffs
public ModifyReference ReferenceModifyValue(StatModifyType _modifyType, int _modValue)
//Remove Reference e.g. touching equipment, end of special buffs
public void RemoveModifyReference(ModifyReference _modifyReference)SoleObjectRuntimeValueSO
CommonStatRuntimeSO
This script manages all runtime values.
If you have a lot of enemies, you don't want to create a lot of this ScriptableObject for that purpose.
ScriptableObject.CreateInstance<SoleObjectRuntimeValueSO>();
runtimeValueSO.SetValueConfigSO(mValueConfig);
It will be initialized the first time it is used, so you need to make sure that SetConfig is initialized before you use it.
Examples
The floowing are examples of use
public class EnemyConfigSO : DescriptionBaseSO
{
[SerializeField] private ValueConfigSO mValueConfig;
public RuntimeAnimatorController MyAnimator;
public SoleObjectRuntimeValueSO GetRuntimeValueSO()
{
var runtimeValueSO = ScriptableObject.CreateInstance<SoleObjectRuntimeValueSO>();
runtimeValueSO.SetValueConfigSO(mValueConfig);
return runtimeValueSO;
}
}
There are also some APIs provided that may not be common that you can view directly in the code. All are commented.
Last updated