internal override void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex) { // Add item OptionGameObject = panel.AddItem(tabIndex, panel.bindingOptionPrefab); // Update text Text text = OptionGameObject.GetComponentInChildren <Text>(); if (text != null) { OptionGameObject.GetComponentInChildren <TranslationLiveUpdate>().translationKey = Label; text.text = Language.main.Get(Label); } // Create bindings uGUI_Bindings bindings = OptionGameObject.GetComponentInChildren <uGUI_Bindings>(); uGUI_Binding binding = bindings.bindings[0]; // Destroy secondary bindings int last = bindings.bindings.Length - 1; UnityEngine.Object.Destroy(bindings.bindings[last].gameObject); UnityEngine.Object.Destroy(bindings); // Update bindings binding.device = Device; binding.value = KeyCodeUtils.KeyCodeToString(Key); binding.onValueChanged.RemoveAllListeners(); var callback = new UnityAction <KeyCode>((KeyCode key) => parentOptions.OnKeybindChange(Id, key)); binding.onValueChanged.AddListener(new UnityAction <string>((string s) => callback?.Invoke(KeyCodeUtils.StringToKeyCode(s)))); base.AddToPanel(panel, tabIndex); }
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 }
internal override void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex) { // Add item OptionGameObject = panel.AddItem(tabIndex, panel.bindingOptionPrefab); // Update text Text text = OptionGameObject.GetComponentInChildren <Text>(); if (text != null) { OptionGameObject.GetComponentInChildren <TranslationLiveUpdate>().translationKey = Label; text.text = Language.main.Get(Label); } // Create bindings uGUI_Bindings bindings = OptionGameObject.GetComponentInChildren <uGUI_Bindings>(); uGUI_Binding binding = bindings.bindings[0]; // Destroy secondary bindings int last = bindings.bindings.Length - 1; UnityEngine.Object.Destroy(bindings.bindings[last].gameObject); UnityEngine.Object.Destroy(bindings); // Update bindings binding.device = Device; binding.value = KeyCodeUtils.KeyCodeToString(Key); #if SUBNAUTICA binding.onValueChanged.RemoveAllListeners(); var callback = new UnityAction <KeyCode>((KeyCode key) => parentOptions.OnKeybindChange(Id, key)); binding.onValueChanged.AddListener(new UnityAction <string>((string s) => callback?.Invoke(KeyCodeUtils.StringToKeyCode(s)))); #elif BELOWZERO binding.action = ButtonPatcher.EnsureButton(Label, KeyCodeUtils.KeyCodeToString(Key), Device); binding.bindingSet = GameInput.BindingSet.Primary; var callback = new UnityAction <KeyCode>((KeyCode key) => parentOptions.OnKeybindChange(Id, key)); binding.bindCallback = new Action <GameInput.Device, GameInput.Button, GameInput.BindingSet, string>((GameInput.Device device, GameInput.Button button, GameInput.BindingSet bindingSet, string s) => { callback?.Invoke(KeyCodeUtils.StringToKeyCode(s)); panel.TryBind1_0(device, button, bindingSet, s); binding.RefreshValue(); }); #endif base.AddToPanel(panel, tabIndex); }