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 = sliderValue;
// Save the raw value
rawValue = val;
// Take steps into account
float stepValue = sliderValue;
// If the stepped value doesn't match the last one, it's time to update
if (force || prevStep != stepValue)
{
Vector3 scale = mSize;
#if UNITY_EDITOR
if (Application.isPlaying)
{
if (direction == Direction.Horizontal) scale.x *= stepValue;
else scale.y *= stepValue;
}
#else
if (direction == Direction.Horizontal) scale.x *= stepValue;
else scale.y *= stepValue;
#endif
#if UNITY_EDITOR
if (Application.isPlaying)
#endif
{
if (mFGFilled != null && mFGFilled.type == UISprite.Type.Filled)
{
mFGFilled.fillAmount = stepValue;
}
else if (foreground != null)
{
mFGTrans.localScale = scale;
if (mFGWidget != null)
{
if (val > 0.001f)
{
mFGWidget.enabled = true;
mFGWidget.MarkAsChanged();
}
else
{
mFGWidget.enabled = false;
}
}
}
}
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 (eventReceiver != null && !string.IsNullOrEmpty(functionName) && Application.isPlaying)
{
eventReceiver.SendMessage(functionName, stepValue, SendMessageOptions.DontRequireReceiver);
}
if (onValueChange != null) onValueChange(stepValue);
current = null;
}
}