public InspectorStringView MakeEditNumericView(ITweakable tweakable) { InspectorStringView stringView = inspectorView.InstantiateInspectorComponent(inspectorView.StringSmallEditPrefab); stringView.InputText.text = tweakable.GetValue().ToString(); stringView.ValueChanged += delegate(string newValue) { object obj = null; double result2; decimal result3; if (long.TryParse(newValue, out var result)) { obj = result; } else if (double.TryParse(newValue, out result2)) { obj = result2; } else if (decimal.TryParse(newValue, out result3)) { obj = result3; } if (obj == null) { logger.Warn("Failed to parse string to numeric type: {0}", newValue); stringView.InputText.targetGraphic.color = errorColor; } else { object obj2 = Convert.ChangeType(obj, tweakable.TweakableType); if (obj2 == null) { logger.Warn("Failed to convert value '{0}' of type {1} to tweakable of type {2}.", obj.ToString(), obj.GetType().FullName, tweakable.TweakableType.FullName); stringView.InputText.targetGraphic.color = errorColor; } else { tweakable.SetValue(obj2); stringView.InputText.targetGraphic.color = successColor; stringView.InputText.text = tweakable.GetValue().ToString(); } } }; Action <object, object> tweakableValueChanged = delegate(object oldValue, object newValue) { stringView.InputText.text = newValue.ToString(); stringView.InputText.targetGraphic.color = successColor; }; tweakable.ValueChanged += tweakableValueChanged; stringView.Destroyed += delegate { tweakable.ValueChanged -= tweakableValueChanged; }; stringView.gameObject.SetActive(value: true); return(stringView); }
private IEnumerator delayInitEditStringView(InspectorStringView stringView, ITweakable tweakable) { yield return(null); object value = tweakable.GetValue(); if (value != null) { stringView.InputText.text = value.ToString(); } else { stringView.InputText.text = ""; } Action <object, object> tweakableValueChanged = delegate(object oldValue, object newValue) { stringView.InputText.text = newValue.ToString(); }; tweakable.ValueChanged += tweakableValueChanged; stringView.Destroyed += delegate { tweakable.ValueChanged -= tweakableValueChanged; }; stringView.ValueChanged += tweakable.SetValue; }
public InspectorBoolView MakeEditBoolView(ITweakable tweakable) { InspectorBoolView boolView = inspectorView.InstantiateInspectorComponent(inspectorView.BoolEditPrefab); bool isOn = (bool)tweakable.GetValue(); boolView.Toggle.isOn = isOn; boolView.ToggleText.text = isOn.ToString(); boolView.ValueChanged += delegate(bool newValue) { tweakable.SetValue(newValue); boolView.ToggleText.text = newValue.ToString(); }; Action <object, object> tweakableValueChanged = delegate(object oldValue, object newValue) { boolView.Toggle.isOn = (bool)newValue; boolView.ToggleText.text = newValue.ToString(); }; tweakable.ValueChanged += tweakableValueChanged; boolView.Destroyed += delegate { tweakable.ValueChanged -= tweakableValueChanged; }; boolView.gameObject.SetActive(value: true); return(boolView); }
protected override void ConfigureView() { base.ConfigureView(); base.View.Name = TileDisplay.GetFriendlyName(tweakable.ShortName); base.View.TileColor = Color.cyan; object value = tweakable.GetValue(); if (value != null) { base.View.Value = value.ToString(); } else { base.View.Value = "null"; } base.Node.Tweakable.ValueChanged += ValueChanged; }
public IEnumerator delayInitEditSerializedStringView(InspectorStringView stringView, ITweakable tweakable, ITweakerSerializer serializer) { yield return(null); object value = tweakable.GetValue(); if (value != null) { stringView.InputText.text = serializer.Serialize(value); } else { stringView.InputText.text = ""; } stringView.ValueChanged += delegate(string newValue) { object obj = serializer.Deserialize(newValue, tweakable.TweakableType); if (obj != null) { tweakable.SetValue(obj); } else { logger.Warn("Failed to deserialize string to type '" + tweakable.TweakableType.FullName + "': " + newValue); } }; Action <object, object> tweakableValueChanged = delegate(object oldValue, object newValue) { stringView.InputText.text = serializer.Serialize(newValue); }; tweakable.ValueChanged += tweakableValueChanged; stringView.Destroyed += delegate { tweakable.ValueChanged -= tweakableValueChanged; }; stringView.gameObject.SetActive(value: true); }
public InspectorSliderView MakeSliderView(ITweakable tweakable) { InspectorSliderView sliderView = inspectorView.InstantiateInspectorComponent(inspectorView.SliderPrefab); Type tweakableType = tweakable.TweakableType; if (!tweakableType.IsNumericType()) { return(null); } if (tweakableType == typeof(int) || tweakableType == typeof(uint) || tweakableType == typeof(long) || tweakableType == typeof(ulong) || tweakableType == typeof(short) || tweakableType == typeof(ushort)) { sliderView.Slider.wholeNumbers = true; } else { sliderView.Slider.wholeNumbers = false; } sliderView.Slider.minValue = (float)Convert.ChangeType(tweakable.MinValue, typeof(float)); sliderView.Slider.maxValue = (float)Convert.ChangeType(tweakable.MaxValue, typeof(float)); sliderView.Slider.value = (float)Convert.ChangeType(tweakable.GetValue(), typeof(float)); sliderView.ValueChanged += delegate(float newValue) { tweakable.SetValue(Convert.ChangeType(newValue, tweakable.TweakableType)); }; Action <object, object> tweakableValueChanged = delegate(object oldValue, object newValue) { sliderView.Slider.value = (float)Convert.ChangeType(newValue, typeof(float)); }; tweakable.ValueChanged += tweakableValueChanged; sliderView.Destroyed += delegate { tweakable.ValueChanged -= tweakableValueChanged; }; return(sliderView); }
public T GetTweakableValue <T>(ITweakable tweakable) { return((T)tweakable.GetValue()); }