public class StatBase
{
[SerializeField] private float _baseValue;
public virtual float BaseValue
{
get { return _baseValue; }
set
{
Debug.Log(value - _baseValue);
_baseValue = value;
}
}
}
public class StatAttribute : StatBase
{
[SerializeField] private int _statLinkerValue;
public override float BaseValue
{
get
{
if (base.BaseValue + StatLinkerValue < MinValue)
return MinValue;
else if (base.BaseValue + StatLinkerValue > MaxValue)
return MaxValue;
else
return base.BaseValue + StatLinkerValue;
}
}
}
public class EntityEditor : Editor
{
public override void OnInspectorGUI()
{
showBase = EditorGUILayout.Toggle("Show Base Value", showBase);
if (showBase)
{
stat.BaseValue = EditorGUILayout.FloatField("Base Value",
stat.BaseValue);
GUILayout.Space(10);
}
}
}
stat variable is a StatAttribute, They have a method that updates the value of StatLinkerValue that I will call from the editor (Update button). Everything works fine when I click the Update button, StatLinkerValue varies from 0 to 100, but somehow the editor has repeatedly added the _baseValue 100 until it equals MaxValue.
This error will not occur if I do not present the BaseValue in the Editor, so I added a toggle to turn it off before performing the update.Everything went well, but when I turned on Toggle again, _baseValue immediately increased. I have spent quite a long time without understanding what is happening, I have not assigned _baseValue to any form other than stat.BaseValue = EditorGUILayout.FloatField (“Base Value”, stat.BaseValue); Inside Editor. Finally sorry for my english.