private void Set(float input, bool force) { if (!this.mInitDone) { this.Init(); } float num = Mathf.Clamp01(input); if (num < 0.001f) { num = 0f; } float value = this.value; this.rawValue = num; float value2 = this.value; if (force || value != value2) { Vector3 localScale = this.mSize; if (this.direction == UISlider360.Direction.Horizontal) { localScale.x *= value2; } else { localScale.y *= value2; } if (this.mFGFilled != null && this.mFGFilled.type == UIBasicSprite.Type.Filled) { this.mFGFilled.fillAmount = value2; } else if (this.mFGWidget != null) { if (value2 > 0.001f) { this.mFGWidget.width = Mathf.RoundToInt(localScale.x); this.mFGWidget.height = Mathf.RoundToInt(localScale.y); this.mFGWidget.enabled = true; } else { this.mFGWidget.enabled = false; } } else if (this.foreground != null) { this.mFGTrans.localScale = localScale; } if (this.thumb != null) { Vector3 localPosition = this.thumb.localPosition; if (this.mFGFilled != null && this.mFGFilled.type == UIBasicSprite.Type.Filled) { if (this.mFGFilled.fillDirection == UIBasicSprite.FillDirection.Horizontal) { localPosition.x = ((!this.mFGFilled.invert) ? localScale.x : (this.mSize.x - localScale.x)); } else if (this.mFGFilled.fillDirection == UIBasicSprite.FillDirection.Vertical) { localPosition.y = ((!this.mFGFilled.invert) ? localScale.y : (this.mSize.y - localScale.y)); } else { Debug.LogWarning("Slider thumb is only supported with Horizontal or Vertical fill direction", this); } } else if (this.direction == UISlider360.Direction.Horizontal) { localPosition.x = localScale.x; } else { localPosition.y = localScale.y; } this.thumb.localPosition = localPosition; } UISlider360.current = this; if (this.eventReceiver != null && !string.IsNullOrEmpty(this.functionName)) { this.eventReceiver.SendMessage(this.functionName, value2, SendMessageOptions.DontRequireReceiver); } UISlider360.current = null; } }
/// <summary> /// Update the visible slider. /// </summary> void Set(float input, bool force) { if (!mInitDone) { Init(); } // Clamp the input float val = Mathf.Clamp01(input); if (val < 0.001f) { val = 0f; } float prevStep = value; // Save the raw value rawValue = val; #if UNITY_EDITOR if (!Application.isPlaying) { return; } #endif // Take steps into account float stepValue = value; // If the stepped value doesn't match the last one, it's time to update if (force || prevStep != stepValue) { Vector3 scale = mSize; if (direction == Direction.Horizontal) { scale.x *= stepValue; } else { scale.y *= stepValue; } if (mFGFilled != null && mFGFilled.type == UISprite.Type.Filled) { mFGFilled.fillAmount = stepValue; } else if (mFGWidget != null) { if (stepValue > 0.001f) { mFGWidget.width = Mathf.RoundToInt(scale.x); mFGWidget.height = Mathf.RoundToInt(scale.y); mFGWidget.enabled = true; } else { mFGWidget.enabled = false; } } else if (foreground != null) { mFGTrans.localScale = scale; } if (thumb != null) { Vector3 pos = thumb.localPosition; if (mFGFilled != null && mFGFilled.type == UISprite.Type.Filled) { if (mFGFilled.fillDirection == UISprite.FillDirection.Horizontal) { pos.x = mFGFilled.invert ? mSize.x - scale.x : scale.x; } else if (mFGFilled.fillDirection == UISprite.FillDirection.Vertical) { pos.y = mFGFilled.invert ? mSize.y - scale.y : scale.y; } else { Debug.LogWarning("Slider thumb is only supported with Horizontal or Vertical fill direction", this); } } else if (direction == Direction.Horizontal) { pos.x = scale.x; } else { pos.y = scale.y; } thumb.localPosition = pos; } current = this; /* * if (EventDelegate.IsValid(onChange)) * { * EventDelegate.Execute(onChange); * } * else */ if (eventReceiver != null && !string.IsNullOrEmpty(functionName)) { // Legacy functionality support (for backwards compatibility) eventReceiver.SendMessage(functionName, stepValue, SendMessageOptions.DontRequireReceiver); } current = null; } }