Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        public InspectorStringView MakeEditSerializedStringView(ITweakable tweakable, ITweakerSerializer serializer)
        {
            InspectorStringView inspectorStringView = inspectorView.InstantiateInspectorComponent(inspectorView.StringEditPrefab);

            inspectorStringView.InputText.targetGraphic.color = successColor;
            inspectorStringView.StartCoroutine(delayInitEditSerializedStringView(inspectorStringView, tweakable, serializer));
            return(inspectorStringView);
        }
Esempio n. 3
0
        public InspectorStringView MakeEditStringView(ITweakable tweakable)
        {
            InspectorStringView inspectorStringView = inspectorView.InstantiateInspectorComponent(inspectorView.StringEditPrefab);

            inspectorStringView.gameObject.SetActive(value: true);
            inspectorStringView.InputText.targetGraphic.color = successColor;
            inspectorStringView.StartCoroutine(delayInitEditStringView(inspectorStringView, tweakable));
            return(inspectorStringView);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }