Beispiel #1
0
        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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
 private void BindArgsToTweakables()
 {
     base.Children.Add(new InvokableNode(null));
     Type[] parameterTypes = Invokable.ParameterTypes;
     argTweakables = new ITweakable[parameterTypes.Length];
     for (int i = 0; i < parameterTypes.Length; i++)
     {
         Type          tweakableType = parameterTypes[i];
         ParameterInfo parameterInfo = Invokable.Parameters[i];
         object        virtualFieldRef;
         ITweakable    tweakable = TweakableFactory.MakeTweakable(tweakableType, parameterInfo.Name, Invokable.InvokableInfo.ArgDescriptions[i], parameterInfo.GetCustomAttributes(typeof(Attribute), inherit: true) as Attribute[], out virtualFieldRef);
         argTweakables[i] = tweakable;
         if (parameterInfo.IsOptional && (parameterInfo.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault && !(parameterInfo.DefaultValue is DBNull))
         {
             tweakable.SetValue(parameterInfo.DefaultValue);
         }
         base.Children.Add(new TweakableNode(tweakable, virtualFieldRef));
     }
 }
Beispiel #4
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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
 public void SetTweakableValue <T>(ITweakable tweakable, T value)
 {
     tweakable.SetValue(value);
 }