// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; HeroKitObject[] targetObject = HeroObjectFieldValue.GetValueE(heroKitObject, 0, 1); int angle = SliderValue.GetValue(heroKitObject, 2); bool runThis = (targetObject != null); // execute action for all objects in list for (int i = 0; runThis && i < targetObject.Length; i++) { ExecuteOnTarget(targetObject[i], angle); } // set up the long action eventID = heroKitObject.heroStateData.eventBlock; heroKitObject.heroState.heroEvent[eventID].waiting = true; updateIsDone = false; heroKitObject.longActions.Add(this); // debug message if (heroKitObject.debugHeroObject) { string debugMessage = "Angle: " + angle; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
public override void OnPersistentDataReady() { base.OnPersistentDataReady(); var key = GetFullHierarchicalPersistenceKey(); m_SliderValue = GetOrCreatePersistentData <SliderValue>(m_SliderValue, key); }
public static void OnValueChangedSetText(this SliderValue sliderValue, float minValue, float maxValue, Func <float, string> selector, bool wholeNumbers = false) { sliderValue.Slider.minValue = minValue; sliderValue.Slider.maxValue = maxValue; sliderValue.Slider.wholeNumbers = wholeNumbers; sliderValue.Slider.OnValueChangedAsObservable().SubscribeToText(sliderValue.Text, selector); }
void ReleaseDesignerOutlets () { if (AmountField != null) { AmountField.Dispose (); AmountField = null; } if (AmountStepper != null) { AmountStepper.Dispose (); AmountStepper = null; } if (CollorWell != null) { CollorWell.Dispose (); CollorWell = null; } if (DateTime != null) { DateTime.Dispose (); DateTime = null; } if (FeedbackLabel != null) { FeedbackLabel.Dispose (); FeedbackLabel = null; } if (ImageWell != null) { ImageWell.Dispose (); ImageWell = null; } if (SegmentButtons != null) { SegmentButtons.Dispose (); SegmentButtons = null; } if (SegmentSelection != null) { SegmentSelection.Dispose (); SegmentSelection = null; } if (SliderValue != null) { SliderValue.Dispose (); SliderValue = null; } if (TickedSlider != null) { TickedSlider.Dispose (); TickedSlider = null; } }
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 }
public override void Awake() { base.Awake(); label = AddUIComponent <UILabel>(); slider = AddUIComponent <Slider>(); textField = AddUIComponent <UITextField>(); LabelText = "(None)"; height = 40; width = 460; this.slider.eventValueChanged += delegate(UIComponent sender, float value) { string format = "{0:0}"; if (StepSize < 1) { format = "{0:0.0}"; } textField.text = String.Format(format, value); }; // Check if the text field changed, and update the slider value. this.textField.eventTextSubmitted += delegate(UIComponent sender, string s) { float num; if (float.TryParse(s, out num)) { if (num > MaxValue) { textField.text = MaxValue.ToString(); } else if (num < MinValue) { textField.text = MinValue.ToString(); } SliderValue = num; } textField.text = SliderValue.ToString(); }; }
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 }
// Execute the action public int Execute(HeroKitObject hko) { // get values heroKitObject = hko; // write messages? bool print = BoolValue.GetValue(heroKitObject, 0); if (print) { HeroKitCommonRuntime.writeMessage = BoolValue.GetValue(heroKitObject, 1); if (HeroKitCommonRuntime.writeMessage) { float messageSpeed = SliderValue.GetValue(heroKitObject, 2); if (messageSpeed < 0) { messageSpeed = 0; } if (messageSpeed > 100) { messageSpeed = 100; } // 0=100, 100=0. Then change to 0 to 1. float waitTime = (100 - messageSpeed) * 0.01f; HeroKitCommonRuntime.messageWaitTime = waitTime; } } // change message alignment? bool changeAlignment = BoolValue.GetValue(heroKitObject, 3); if (changeAlignment) { int alignID = DropDownListValue.GetValue(heroKitObject, 4); switch (alignID) { case 1: HeroKitCommonRuntime.messageAlignment = TextAnchor.UpperLeft; break; case 2: HeroKitCommonRuntime.messageAlignment = TextAnchor.UpperCenter; break; case 3: HeroKitCommonRuntime.messageAlignment = TextAnchor.UpperRight; break; case 4: HeroKitCommonRuntime.messageAlignment = TextAnchor.MiddleLeft; break; case 5: HeroKitCommonRuntime.messageAlignment = TextAnchor.MiddleCenter; break; case 6: HeroKitCommonRuntime.messageAlignment = TextAnchor.MiddleRight; break; case 7: HeroKitCommonRuntime.messageAlignment = TextAnchor.LowerLeft; break; case 8: HeroKitCommonRuntime.messageAlignment = TextAnchor.LowerCenter; break; case 9: HeroKitCommonRuntime.messageAlignment = TextAnchor.LowerRight; break; } } // change background alpha bool changeBackgroundAlpha = BoolValue.GetValue(heroKitObject, 5); if (changeBackgroundAlpha) { // get new alpha float alpha = SliderValue.GetValue(heroKitObject, 6); // keep alpha between 0 - 100 if (alpha > 100) { alpha = 100; } else if (alpha < 0) { alpha = 0; } // switch to 0 - 1 scale alpha *= .01f; // change alpha HeroKitCommonRuntime.messageBackgroundAlpha = alpha; HeroKitCommonRuntime.changeMessageBackgroundTransparency = true; } // change background alpha bool changeButtonAlpha = BoolValue.GetValue(heroKitObject, 19); if (changeButtonAlpha) { // get new alpha float alpha = SliderValue.GetValue(heroKitObject, 20); // keep alpha between 0 - 100 if (alpha > 100) { alpha = 100; } else if (alpha < 0) { alpha = 0; } // switch to 0 - 1 scale alpha *= .01f; // change alpha HeroKitCommonRuntime.messageButtonAlpha = alpha; HeroKitCommonRuntime.changeMessageButtonTransparency = true; } // change background image bool changeBackgroundImage = BoolValue.GetValue(heroKitObject, 7); if (changeBackgroundImage) { UnityObjectField unityObject = UnityObjectFieldValue.GetValueA(heroKitObject, 8); HeroKitCommonRuntime.messageBackgroundImage = (unityObject.value != null) ? (Sprite)unityObject.value : null; HeroKitCommonRuntime.changeMessageBackground = true; } // change button image bool changeButtonImage = BoolValue.GetValue(heroKitObject, 9); if (changeButtonImage) { UnityObjectField unityObject = UnityObjectFieldValue.GetValueA(heroKitObject, 10); HeroKitCommonRuntime.messageButtonImage = (unityObject.value != null) ? (Sprite)unityObject.value : null; HeroKitCommonRuntime.changeMessageButton = true; } // change button layout bool changeButtonLayout = BoolValue.GetValue(heroKitObject, 11); if (changeButtonLayout) { HeroKitCommonRuntime.messageButtonLayout = DropDownListValue.GetValue(heroKitObject, 12); HeroKitCommonRuntime.changeMessageButtonLayout = true; } // change text color bool changeTextColor = BoolValue.GetValue(heroKitObject, 13); if (changeTextColor) { HeroKitCommonRuntime.messageTextColor = ColorValue.GetValue(heroKitObject, 14); HeroKitCommonRuntime.changeMessageTextColor = true; } // change heading color bool changeHeadingColor = BoolValue.GetValue(heroKitObject, 15); if (changeHeadingColor) { HeroKitCommonRuntime.messageHeadingColor = ColorValue.GetValue(heroKitObject, 16); HeroKitCommonRuntime.changeMessageHeadingColor = true; } // change button text color bool changeButtonTextColor = BoolValue.GetValue(heroKitObject, 17); if (changeButtonTextColor) { HeroKitCommonRuntime.messageButtonTextColor = ColorValue.GetValue(heroKitObject, 18); HeroKitCommonRuntime.changeMessageButtonTextColor = true; } // change active button color bool changeButtonActiveColor = BoolValue.GetValue(heroKitObject, 21); if (changeButtonActiveColor) { HeroKitCommonRuntime.messageButtonActiveColor = ColorValue.GetValue(heroKitObject, 22); HeroKitCommonRuntime.changeMessageButtonActiveColor = true; } if (heroKitObject.debugHeroObject) { Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, (""))); } return(-99); }
// Execute the action public int Execute(HeroKitObject hko) { heroKitObject = hko; SceneObjectValueData objectData = SceneObjectValue.GetValue(heroKitObject, 0, 1, false); endAlpha = SliderValue.GetValue(heroKitObject, 2) * 0.01f; duration = (float)(IntegerFieldValue.GetValueA(heroKitObject, 3) * 0.10); wait = BoolValue.GetValue(heroKitObject, 4); Canvas canvas = null; // object is hero object if (objectData.heroKitObject != null) { canvas = objectData.heroKitObject[0].GetHeroComponent <Canvas>("Canvas"); if (canvas != null) { canvasGroup = objectData.heroKitObject[0].GetHeroComponent <CanvasGroup>("CanvasGroup", true); } else { Debug.LogError("Can't change alpha because this game object does not have a Canvas component attached to it."); return(-99); } } // object is game object else if (objectData.gameObject != null) { canvas = heroKitObject.GetGameObjectComponent <Canvas>("Canvas", false, objectData.gameObject[0]); if (canvas != null) { canvasGroup = heroKitObject.GetGameObjectComponent <CanvasGroup>("CanvasGroup", true, objectData.gameObject[0]); } else { Debug.LogError("Can't change alpha because this game object does not have a Canvas component attached to it."); return(-99); } } if (canvasGroup.alpha != endAlpha) { startAlpha = canvasGroup.alpha; // set up update for long action heroKitObject.heroState.heroEvent[eventID].waiting = wait; updateIsDone = false; heroKitObject.longActionsFixed.Add(this); } //------------------------------------ // debug message //------------------------------------ if (heroKitObject.debugHeroObject) { string strCanvas = (canvas != null) ? canvas.gameObject.name : ""; string debugMessage = "Canvas: " + strCanvas + "\n" + "Alpha: " + endAlpha + "\n" + "Duration: " + duration; Debug.Log(HeroKitCommonRuntime.GetActionDebugInfo(heroKitObject, debugMessage)); } return(-99); }
private GameObject SpawnSlider(SliderValue value) { GameObject gameObject = Util.KInstantiateUI(sliderPropertyPrefab, base.gameObject, true); HierarchyReferences component = gameObject.GetComponent <HierarchyReferences>(); component.GetReference <Image>("BottomIcon").sprite = Assets.GetSprite(value.bottomSprite); component.GetReference <Image>("TopIcon").sprite = Assets.GetSprite(value.topSprite); KSlider slider = component.GetReference <KSlider>("Slider"); KNumberInputField inputField = component.GetReference <KNumberInputField>("InputField"); gameObject.GetComponent <ToolTip>().SetSimpleTooltip(value.tooltip); slider.minValue = value.minValue; slider.maxValue = value.maxValue; inputField.minValue = 0f; inputField.maxValue = 99999f; inputFields.Add(inputField.gameObject); value.slider = slider; value.inputField = inputField; value.row = gameObject; slider.onReleaseHandle += delegate { slider.value = Mathf.Round(slider.value * 10f) / 10f; inputField.currentValue = slider.value; inputField.SetDisplayValue(inputField.currentValue.ToString()); if (value.onValueChanged != null) { value.onValueChanged(slider.value); } }; slider.onDrag += delegate { slider.value = Mathf.Round(slider.value * 10f) / 10f; inputField.currentValue = slider.value; inputField.SetDisplayValue(inputField.currentValue.ToString()); if (value.onValueChanged != null) { value.onValueChanged(slider.value); } }; slider.onMove += delegate { slider.value = Mathf.Round(slider.value * 10f) / 10f; inputField.currentValue = slider.value; inputField.SetDisplayValue(inputField.currentValue.ToString()); if (value.onValueChanged != null) { value.onValueChanged(slider.value); } }; inputField.onEndEdit += delegate { float num = Mathf.Clamp(Mathf.Round(inputField.currentValue), inputField.minValue, inputField.maxValue); inputField.SetDisplayValue(num.ToString()); slider.value = Mathf.Round(num); if (value.onValueChanged != null) { value.onValueChanged(num); } }; component.GetReference <LocText>("UnitLabel").text = value.unitString; return(gameObject); }
public static void SetValue(this SliderValue sliderValue, float value) { sliderValue.Slider.value = value; }