public InspectorToggleValueView MakeToggleValueView(ITweakable tweakable, IToggleTweakable toggleTweakable, int toggleIndex, ToggleGroup group) { InspectorToggleValueView valueView = inspectorView.InstantiateInspectorComponent(inspectorView.ToggleValuePrefab); valueView.Toggle.group = group; valueView.Toggle.isOn = toggleTweakable.CurrentIndex == toggleIndex; valueView.ToggleText.text = toggleTweakable.GetNameByIndex(toggleIndex); Action <object, object> tweakableValueChanged = delegate { if (toggleTweakable.CurrentIndex == toggleIndex && !valueView.Toggle.isOn) { valueView.Toggle.isOn = true; } }; tweakable.ValueChanged += tweakableValueChanged; valueView.Destroyed += delegate { tweakable.ValueChanged -= tweakableValueChanged; }; valueView.Toggle.onValueChanged.AddListener(delegate(bool isOn) { if (isOn && toggleIndex != toggleTweakable.CurrentIndex) { toggleTweakable.SetValueByName(toggleTweakable.GetNameByIndex(toggleIndex)); } }); return(valueView); }
private IEnumerable <IInspectorContentView> MakeContentViews(ITweakable tweakable) { yield return(contentFactory.MakeDescriptionView(tweakable.Description)); if (tweakable.TweakableType == typeof(string)) { yield return(contentFactory.MakeEditStringView(tweakable)); } else if (tweakable.TweakableType == typeof(bool)) { yield return(contentFactory.MakeEditBoolView(tweakable)); } else if (!tweakable.TweakableType.IsEnum) { if (tweakable.TweakableType.IsNumericType()) { yield return(contentFactory.MakeEditNumericView(tweakable)); if (tweakable.HasRange && !TweakerFlagsUtil.IsSet(TweakableUIFlags.HideRangeSlider, tweakable)) { yield return(contentFactory.MakeSliderView(tweakable)); } } else { yield return(contentFactory.MakeEditSerializedStringView(tweakable, gridController.Console.Serializer)); } } if (tweakable.HasStep) { yield return(contentFactory.MakeStepperView(tweakable)); } if (tweakable.HasToggle) { InspectorToggleGroupView groupView = contentFactory.MakeToggleGroupView(); yield return(groupView); IToggleTweakable toggle = tweakable.Toggle; for (int i = 0; i < toggle.ToggleCount; i++) { yield return(contentFactory.MakeToggleValueView(tweakable, toggle, i, groupView.ToggleGroup)); } } }
private void CreateComponents() { if (TweakableType.IsEnum) { string[] names = Enum.GetNames(TweakableType); Array values = Enum.GetValues(TweakableType); int num = names.Length; TweakableInfo.ToggleValues = new TweakableNamedToggleValue <T> [num]; for (int i = 0; i < num; i++) { TweakableInfo.ToggleValues[i] = new TweakableNamedToggleValue <T>(names[i], (T)values.GetValue(i)); } } if (HasStep && !HasToggle) { stepTweakable = new StepTweakable <T>(this); } else if (HasToggle) { toggleTweakable = new ToggleTweakable <T>(this); stepTweakable = toggleTweakable; } }