Code structure cleanup. (2)

This commit is contained in:
2023-08-24 16:18:16 +08:00
parent 1f58390298
commit 8fa2bd1e81
55 changed files with 77 additions and 65 deletions

View File

@@ -0,0 +1,104 @@
using Cryville.Crtr.Ruleset;
using Cryville.Crtr.UI;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Text;
using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Crtr.Config.UI {
public class ConfigPanelMaster : MonoBehaviour {
[SerializeField]
Menu m_menu;
[SerializeField]
Transform m_content;
[SerializeField]
PropertyMasterPanel m_genericConfigPanel;
[SerializeField]
PropertyMasterPanel m_rulesetConfigPanel;
[SerializeField]
InputConfigPanel m_inputConfigPanel;
public RulesetDefinition ruleset;
RulesetConfig _rscfg;
bool _loaded;
void OnEnable() {
try {
PdtEvaluator.Instance.Reset();
FileInfo file = new FileInfo(
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
);
if (!file.Exists) {
throw new FileNotFoundException("Ruleset for the chart not found\nMake sure you have imported the ruleset");
}
DirectoryInfo dir = file.Directory;
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
if (ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
ruleset.LoadPdt(dir);
}
FileInfo cfgfile = new FileInfo(
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
);
if (!cfgfile.Exists) {
if (!cfgfile.Directory.Exists) cfgfile.Directory.Create();
_rscfg = new RulesetConfig();
}
else {
using (StreamReader cfgreader = new StreamReader(cfgfile.FullName, Encoding.UTF8)) {
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
}
}
m_genericConfigPanel.Adapter = new DefaultPropertyMasterAdapter(_rscfg.generic);
m_rulesetConfigPanel.Adapter = new RulesetConfigPropertyMasterAdapter(ruleset.Root.configs, _rscfg.configs);
var proxy = new InputProxy(ruleset.Root, null, new Vector2(Screen.width, Screen.height));
proxy.LoadFrom(_rscfg.inputs);
m_inputConfigPanel.proxy = proxy;
m_inputConfigPanel.OnConfigEnable();
_loaded = true;
}
catch (Exception ex) {
Popup.CreateException(ex);
Logger.Log("main", 4, "Config", "An error occurred while loading the config: {0}", ex);
m_menu.Back();
}
}
public void SwitchCategory(GameObject cat) {
foreach (Transform c in m_content) {
c.gameObject.SetActive(false);
}
cat.SetActive(true);
}
void OnDisable() {
if (_loaded) {
_loaded = false;
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
m_inputConfigPanel.proxy.Dispose();
FileInfo cfgfile = new FileInfo(
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
);
using (StreamWriter cfgwriter = new StreamWriter(cfgfile.FullName, false, Encoding.UTF8)) {
cfgwriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
}
m_inputConfigPanel.OnConfigDisable();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bad1f43573d4f1143a94fddddd30fb81
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,159 @@
using Cryville.Common;
using Cryville.Common.Unity;
using Cryville.Crtr.Ruleset;
using Cryville.Input;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Config.UI {
public class InputConfigPanel : MonoBehaviour {
[SerializeField]
ConfigPanelMaster m_configScene;
[SerializeField]
GameObject m_inputDialog;
[SerializeField]
Transform m_deviceList;
[SerializeField]
GameObject m_prefabListItem;
[SerializeField]
Transform m_entryList;
[SerializeField]
GameObject m_prefabInputConfigEntry;
SimpleInputConsumer _consumer;
public InputProxy proxy;
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new Dictionary<Identifier, InputConfigPanelEntry>();
int _applicableEntries;
Identifier _sel;
int _targetDim;
PhysicalDimension? _targetPDim;
bool _targetNotNull;
public void OpenDialog(Identifier entry) {
_sel = entry;
var def = m_configScene.ruleset.Root.inputs[_sel];
_targetDim = def.dim;
if (def.pdim != null) _targetPDim = ParsePhysicalDimension(def.pdim);
else _targetPDim = null;
_targetNotNull = def.notnull;
m_inputDialog.SetActive(true);
CallHelper.Purge(m_deviceList);
_consumer.EnumerateEvents(ev => { });
_recvsrcs.Clear();
_applicableEntries = 1;
AddSourceItem(null);
}
static PhysicalDimension ParsePhysicalDimension(string str) {
var comps = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
var result = new PhysicalDimension();
foreach (var comp in comps) {
int dim = 1;
if (comp.Length > 1) dim = int.Parse(comp.Substring(1));
switch (comp[0]) {
case 'T': result.Time += dim; break;
case 'L': result.Length += dim; break;
case 'M': result.Mass += dim; break;
case 'I': result.ElectricCurrent += dim; break;
case '\x0398':
case 'H': result.ThermodynamicTemperature += dim; break;
case 'N': result.AmountOfSubstance += dim; break;
case 'J': result.LuminousIntensity += dim; break;
default: throw new ArgumentException(string.Format("Invalid dimension symbol {0}", comp[0]));
}
}
return result;
}
public void CloseDialog() {
m_inputDialog.SetActive(false);
}
public void CloseDialog(InputSource? src) {
proxy.Set(new InputProxyEntry {
Target = _sel,
Source = src,
});
CloseDialog();
}
public void OnConfigEnable() {
CallHelper.Purge(m_entryList);
_entries.Clear();
_consumer = new SimpleInputConsumer(Game.InputManager);
_consumer.Activate();
foreach (var i in m_configScene.ruleset.Root.inputs) {
var e = GameObject.Instantiate(m_prefabInputConfigEntry, m_entryList.transform).GetComponent<InputConfigPanelEntry>();
_entries.Add(i.Key, e);
e.SetKey(this, i.Key);
OnProxyChanged(this, proxy[i.Key]);
}
proxy.ProxyChanged += OnProxyChanged;
}
public void OnConfigDisable() {
_consumer.Deactivate();
}
void OnProxyChanged(object sender, ProxyChangedEventArgs e) {
_entries[e.Name].OnProxyChanged(e);
}
void Start() {
_d_HandleInputEvent = HandleInputEvent;
}
readonly List<InputSource?> _recvsrcs = new List<InputSource?>();
void Update() {
if (m_inputDialog.activeSelf) {
_consumer.EnumerateEvents(_d_HandleInputEvent);
}
}
Action<InputEvent> _d_HandleInputEvent;
void HandleInputEvent(InputEvent ev) {
AddSourceItem(ev.Identifier.Source);
}
void AddSourceItem(InputSource? src) {
if (_recvsrcs.Contains(src)) return;
_recvsrcs.Add(src);
var obj = Instantiate(m_prefabListItem, m_deviceList);
var text = obj.transform.Find("Text").GetComponent<Text>();
text.text = src == null ? "(None)" : src.Value.Handler.GetTypeName(src.Value.Type);
var btn = obj.GetComponent<Button>();
if (src != null) {
var tsrc = src.Value;
bool flag = false;
if (proxy.IsUsed(tsrc)) {
text.text += " <size=9>(Used)</size>";
}
else if (tsrc.Handler.Dimension < _targetDim) {
text.text += " <size=9>(Not Applicable)</size>";
}
else if (_targetPDim != null && tsrc.Handler.ReferenceCue.PhysicalDimension != _targetPDim) {
text.text += " <size=9>(Not Applicable)</size>";
}
else if (!_targetNotNull && !tsrc.Handler.IsNullable) {
text.text += " <size=9>(Not Applicable)</size>";
}
else flag = true;
btn.interactable = flag;
obj.transform.SetSiblingIndex(flag ? _applicableEntries++ : m_deviceList.childCount - 1);
}
else {
obj.transform.SetSiblingIndex(0);
}
btn.onClick.AddListener(() => {
CloseDialog(src);
});
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 279d2404a312e5543813d8aca02800b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,45 @@
using Cryville.Common;
using Cryville.Crtr.Ruleset;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Cryville.Crtr.Config.UI {
public class InputConfigPanelEntry : MonoBehaviour {
[SerializeField]
Text m_key;
[SerializeField]
Text m_value;
[SerializeField]
Button m_button;
public void SetKey(InputConfigPanel master, Identifier name) {
m_key.text = (string)name.Name;
m_value.text = "None";
m_button.onClick.AddListener(() => {
master.OpenDialog(name);
EventSystem.current.SetSelectedGameObject(null);
});
}
public void OnProxyChanged(ProxyChangedEventArgs e) {
if (e.Used) {
m_button.interactable = false;
m_value.text = "(Not Required)";
}
else {
m_button.interactable = true;
if (e.Proxy == null) {
m_value.text = "(Unassigned)";
if (e.Required) m_value.text += " (Required)";
}
else {
m_value.text = e.Proxy.Value.Handler.GetTypeName(e.Proxy.Value.Type);
}
}
m_value.color = e.Required ? Color.yellow : Color.black;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9741a0ed8c1c5e0468ea89f2cf33f36c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace Cryville.Crtr.Config.UI {
public class PVPBool : PropertyValuePanel, IPointerClickHandler {
[SerializeField]
RectTransform m_on;
[SerializeField]
RectTransform m_handleArea;
[SerializeField]
RectTransform m_handle;
protected override void OnValueUpdated() { }
public void Toggle() {
RawValue = !(bool)RawValue;
}
const float SPEED = 8;
float _ratio;
#pragma warning disable IDE0051
void Update() {
if ((bool)RawValue && _ratio != 1) {
_ratio += SPEED * Time.deltaTime;
if (_ratio > 1) _ratio = 1;
UpdateGraphics();
}
else if (!(bool)RawValue && _ratio != 0) {
_ratio -= SPEED * Time.deltaTime;
if (_ratio < 0) _ratio = 0;
UpdateGraphics();
}
}
void OnRectTransformDimensionsChange() {
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
}
#pragma warning restore IDE0051
void UpdateGraphics() {
m_on.anchorMax = new Vector2(_ratio, m_on.anchorMax.y);
m_handle.anchorMin = new Vector2(_ratio, m_handle.anchorMin.y);
m_handle.anchorMax = new Vector2(_ratio, m_handle.anchorMax.y);
}
public void OnPointerClick(PointerEventData eventData) {
Toggle();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9cb1bc40304ff174f891239c8f450c1c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
using System;
namespace Cryville.Crtr.Config.UI {
public class PVPNumber : PVPNumberBase {
protected override void OnValueUpdated() {
base.OnValueUpdated();
if (Range != null && Range.Length == 2) {
var min = (double)Range[0];
var max = (double)Range[1];
var value = Convert.ToDouble(RawValue);
if (value < min) {
value = min;
RawValue = value;
}
else if (value > max) {
value = max;
RawValue = value;
}
SetRatio((float)((value - min) / (max - min)));
}
}
protected override double GetValue(double ratio, float deltaTime, double min, double max) {
// if (LogarithmicMode) throw new NotImplementedException();
return (1 - ratio) * min + ratio * max;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 94cb9dad5ac3eb04ca16d58a7bae0cb5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,118 @@
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Cryville.Crtr.Config.UI {
public abstract class PVPNumberBase : PropertyValuePanel {
[SerializeField]
EventTrigger m_ctn;
[SerializeField]
RectTransform m_handleArea;
[SerializeField]
Image m_handle;
[SerializeField]
Text m_text;
#pragma warning disable IDE0051
protected void Start() {
var ev = new EventTrigger.Entry { eventID = EventTriggerType.InitializePotentialDrag };
ev.callback.AddListener(e => OnInitializePotentialDrag((PointerEventData)e));
m_ctn.triggers.Add(ev);
ev = new EventTrigger.Entry { eventID = EventTriggerType.Drag };
ev.callback.AddListener(e => OnDrag((PointerEventData)e));
m_ctn.triggers.Add(ev);
ev = new EventTrigger.Entry { eventID = EventTriggerType.EndDrag };
ev.callback.AddListener(e => OnEndDrag((PointerEventData)e));
m_ctn.triggers.Add(ev);
ev = new EventTrigger.Entry { eventID = EventTriggerType.PointerClick };
ev.callback.AddListener(e => OnPointerClick((PointerEventData)e));
m_ctn.triggers.Add(ev);
OnIdle();
}
protected override void OnValueUpdated() {
m_text.text = MappedValue.ToString();
}
protected virtual void OnIdle() { }
void Update() {
if (use) {
SetRatio(GetRatioFromPos(pp));
SetValueFromPos(pp);
}
}
void OnRectTransformDimensionsChange() {
m_handleArea.sizeDelta = new Vector2(m_handle.rectTransform.rect.height - m_handle.rectTransform.rect.width, 0);
}
#pragma warning restore IDE0051
Camera cam;
Vector2 pp;
bool use, nouse;
public void OnInitializePotentialDrag(PointerEventData eventData) {
eventData.useDragThreshold = false;
pp = eventData.position;
}
public void OnDrag(PointerEventData eventData) {
if (nouse) return;
cam = eventData.pressEventCamera;
if (!use) {
var delta = eventData.position - pp;
float dx = Mathf.Abs(delta.x), dy = Mathf.Abs(delta.y);
if (dx > dy) use = true;
else if (dx < dy) nouse = true;
}
if (use) {
pp = eventData.position;
eventData.Use();
}
}
public void OnEndDrag(PointerEventData eventData) {
if (!nouse) {
SetValueFromPos(eventData.position);
OnIdle();
eventData.Use();
use = false;
}
nouse = false;
}
public void OnPointerClick(PointerEventData eventData) {
SetValueFromPos(eventData.position);
eventData.Use();
}
float GetRatioFromPos(Vector2 pos) {
Vector2 lp;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_handleArea, pos, cam, out lp)) {
lp -= m_handleArea.rect.position;
return Mathf.Clamp01(lp.x / m_handleArea.rect.width);
}
return float.NegativeInfinity;
}
void SetValueFromPos(Vector2 pos) {
double min = double.NegativeInfinity, max = double.PositiveInfinity;
if (Range != null && Range.Length == 2) {
min = (double)Range[0];
max = (double)Range[1];
}
double ratio = GetRatioFromPos(pos);
double result = GetValue(ratio, Time.deltaTime, min, max);
if (result < min) result = min;
else if (result > max) result = max;
RawValue = result;
}
protected abstract double GetValue(double ratio, float deltaTime, double min, double max);
protected void SetRatio(float ratio) {
m_handle.rectTransform.anchorMin = new Vector2(ratio, m_handle.rectTransform.anchorMin.y);
m_handle.rectTransform.anchorMax = new Vector2(ratio, m_handle.rectTransform.anchorMax.y);
m_handle.rectTransform.anchoredPosition = Vector2.zero;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c928ece9c4b30f04cb33f66eb9f050b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
using System;
namespace Cryville.Crtr.Config.UI {
public class PVPNumberStepped : PVPNumberBase {
protected override void OnIdle() {
SetRatio(0.5f);
}
protected override double GetValue(double ratio, float deltaTime, double min, double max) {
double delta = (ratio > 0.5 ? 1 : -1) * Math.Pow((ratio - 0.5f) * 2, 2) * deltaTime;
// if (LogarithmicMode) return Math.Pow(Math.E, Math.Log(m_value) + delta);
return Convert.ToDouble(RawValue) + delta;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c309650ed758ea34ba64e765f59bb043
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
using UnityEngine.UI;
namespace Cryville.Crtr.Config.UI {
public class PVPString : PropertyValuePanel {
protected override void OnValueUpdated() { _inputField.text = (string)MappedValue; }
InputField _inputField;
void Awake() {
_inputField = GetComponent<InputField>();
_inputField.onValueChanged.AddListener(OnValueChanged);
}
void OnValueChanged(string value) {
RawValue = value;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f81596a59a59fce48854b6753fe8cfc6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Config.UI {
public class PropertyCategoryPanel : MonoBehaviour {
[SerializeField]
private GameObject m_propertyPrefab;
Text _nameLabel = null;
string _name;
public string Name {
get { return _name; }
set { _name = value; UpdateName(); }
}
bool _collapsed = false;
public bool Collapsed {
get { return _collapsed; }
set { _collapsed = value; UpdateName(); }
}
#pragma warning disable IDE0051
void Awake() {
_nameLabel = transform.Find("Name/__text__").GetComponent<Text>();
transform.Find("Name").GetComponent<Button>().onClick.AddListener(ToggleCollapsed);
}
#pragma warning restore IDE0051
public void Load(string name, IEnumerable<IPropertyAdapter> props) {
Name = name.ToUpper();
foreach (var prop in props) {
var obj = Instantiate(m_propertyPrefab, transform, false);
obj.GetComponent<PropertyPanel>().Load(prop);
}
}
void ToggleCollapsed() {
Collapsed = !Collapsed;
for (int i = 1; i < transform.childCount; i++) {
transform.GetChild(i).gameObject.SetActive(!Collapsed);
}
}
private void UpdateName() {
_nameLabel.text = (Collapsed ? "+ " : "- ") + Name;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 11c5451aac09cbd4a8e94c82d5c568e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
using System.Collections.Generic;
using UnityEngine;
namespace Cryville.Crtr.Config.UI {
public class PropertyMasterPanel : MonoBehaviour {
[SerializeField]
GameObject m_categoryPrefab;
[SerializeField]
Transform m_container;
bool _invalidated = true;
public void Invalidate() {
_invalidated = true;
}
private IPropertyMasterAdapter m_adapter;
public IPropertyMasterAdapter Adapter {
get { return m_adapter; }
set {
m_adapter = value;
Invalidate();
}
}
public void Update() {
if (!_invalidated) return;
LoadProperties();
foreach (Transform c in m_container) Destroy(c.gameObject);
foreach (var c in _categories) {
var obj = Instantiate(m_categoryPrefab, m_container, false);
obj.GetComponent<PropertyCategoryPanel>().Load(c.Key, c.Value);
}
}
readonly Dictionary<string, List<IPropertyAdapter>> _categories = new Dictionary<string, List<IPropertyAdapter>>();
public void LoadProperties() {
_categories.Clear();
_invalidated = false;
if (Adapter == null) return;
foreach (var p in Adapter.GetProperties()) {
string category = p.Category;
if (category == null) category = Adapter.DefaultCategory;
if (!_categories.ContainsKey(category))
_categories.Add(category, new List<IPropertyAdapter>());
_categories[category].Add(p);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f8d04667a373e4648a83440b496c8127
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Config.UI {
public class PropertyPanel : MonoBehaviour {
[SerializeField]
GameObject m_bool;
[SerializeField]
GameObject m_number;
[SerializeField]
GameObject m_numberStepped;
[SerializeField]
GameObject m_string;
Text _key;
Transform _valueContainer;
PropertyValuePanel _value;
#pragma warning disable IDE0051
void Awake() {
_key = transform.Find("Key").GetComponent<Text>();
_valueContainer = transform.Find("Value");
}
#pragma warning restore IDE0051
public void Load(IPropertyAdapter prop) {
_key.text = prop.Name;
GameObject vp;
switch (prop.Type) {
case PropertyType.Number: vp = m_number; break;
case PropertyType.NumberStepped: vp = m_numberStepped; break;
case PropertyType.Boolean: vp = m_bool; break;
case PropertyType.String: vp = m_string; break;
default: return;
}
_value = Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
_value.Init(prop);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0a812a9e54dd057459b501c0881b0f68
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aa6b204c7a1fd1d4c95d912196fc7566
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: