Code structure cleanup. (2)
This commit is contained in:
40
Assets/Cryville/Crtr/Config/UI/PropertyValuePanel.cs
Normal file
40
Assets/Cryville/Crtr/Config/UI/PropertyValuePanel.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Config.UI {
|
||||
public abstract class PropertyValuePanel : MonoBehaviour {
|
||||
IPropertyAdapter _property;
|
||||
public void Init(IPropertyAdapter property) {
|
||||
_property = property;
|
||||
_property.ValueChanged += GetValue;
|
||||
GetValue();
|
||||
}
|
||||
protected object[] Range { get { return _property.Range; } }
|
||||
public object MappedValue { get; private set; }
|
||||
private object m_rawValue;
|
||||
public object RawValue {
|
||||
get { return m_rawValue; }
|
||||
set {
|
||||
m_rawValue = value;
|
||||
SetValue();
|
||||
}
|
||||
}
|
||||
protected abstract void OnValueUpdated();
|
||||
void GetValue() {
|
||||
if (_property.SetMapped) {
|
||||
MappedValue = _property.GetValue();
|
||||
m_rawValue = _property.MapValueInverse(MappedValue);
|
||||
}
|
||||
else {
|
||||
m_rawValue = _property.GetValue();
|
||||
MappedValue = _property.MapValue(m_rawValue);
|
||||
}
|
||||
OnValueUpdated();
|
||||
}
|
||||
void SetValue() {
|
||||
var outRaw = RawValue;
|
||||
MappedValue = _property.MapValue(outRaw);
|
||||
_property.SetValue(_property.SetMapped ? MappedValue : outRaw);
|
||||
OnValueUpdated();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user