internal override void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex) { #if BELOWZERO UnityAction <float> callback = new UnityAction <float>((value) => parentOptions.OnSliderChange(Id, sliderValue?.ConvertToDisplayValue(value) ?? value)); #else UnityAction <float> callback = new UnityAction <float>((value) => { value = sliderValue?.ConvertToDisplayValue(value) ?? value; if (value != previousValue) { previousValue = value; parentOptions.OnSliderChange(Id, value); } }); #endif #if SUBNAUTICA panel.AddSliderOption(tabIndex, Label, Value, MinValue, MaxValue, DefaultValue, callback); #elif BELOWZERO panel.AddSliderOption(tabIndex, Label, Value, MinValue, MaxValue, DefaultValue, Step, callback, SliderLabelMode.Default, "0.0"); #endif // AddSliderOption for some reason doesn't return created GameObject, so we need this little hack Transform options = panel.tabs[tabIndex].container.transform; OptionGameObject = options.GetChild(options.childCount - 1).gameObject; // last added game object #if BELOWZERO // if we using custom value format, we need to replace vanilla uGUI_SliderWithLabel with our component if (ValueFormat != null) { OptionGameObject.transform.Find("Slider").gameObject.AddComponent <SliderValue>().ValueFormat = ValueFormat; } // fixing tooltip for slider OptionGameObject.transform.Find("Slider/Caption").GetComponent <Text>().raycastTarget = true; #else // if we using custom value format or step, we need to replace vanilla uGUI_SliderWithLabel with our component if (ValueFormat != null || Step >= Mathf.Epsilon) { var sliderValue = OptionGameObject.transform.Find("Slider").gameObject.AddComponent <SliderValue>(); sliderValue.Step = Step; if (ValueFormat != null) { sliderValue.ValueFormat = ValueFormat; } } #endif base.AddToPanel(panel, tabIndex); sliderValue = OptionGameObject.GetComponentInChildren <SliderValue>(); // we can also add custom SliderValue in OnGameObjectCreated event }
internal override void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex) { panel.AddSliderOption(tabIndex, Label, Value, MinValue, MaxValue, DefaultValue, new UnityAction <float>((float value) => parentOptions.OnSliderChange(Id, sliderValue?.ConvertToDisplayValue(value) ?? value))); // AddSliderOption for some reason doesn't return created GameObject, so we need this little hack Transform options = panel.tabs[tabIndex].container.transform; OptionGameObject = options.GetChild(options.childCount - 1).gameObject; // last added game object // if we using custom value format, we need to replace vanilla uGUI_SliderWithLabel with our component if (ValueFormat != null) { OptionGameObject.transform.Find("Slider").gameObject.AddComponent <SliderValue>().ValueFormat = ValueFormat; } base.AddToPanel(panel, tabIndex); sliderValue = OptionGameObject.GetComponentInChildren <SliderValue>(); // we can also add custom SliderValue in OnGameObjectCreated event }