Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: benb on November 03, 2013, 04:21:40 AM

Title: UISlider mCenter not updated
Post by: benb on November 03, 2013, 04:21:40 AM
When you change the value of fullSize programatically mCenter doesn't get updated, so the slider ends up behaving strangely. For example - if the size is increased clicking on the far right side of the slider results in Set being called with a value greater than 1.0.
Title: Re: UISlider mCenter not updated
Post by: ArenMook on November 03, 2013, 09:04:29 AM
You can try using this function:
  1.         public Vector2 fullSize
  2.         {
  3.                 get
  4.                 {
  5.                         return mSize;
  6.                 }
  7.                 set
  8.                 {
  9.                         if (mSize != value)
  10.                         {
  11.                                 mSize = value;
  12.  
  13.                                 if (foreground != null)
  14.                                 {
  15.                                         UIWidget w = foreground.GetComponent<UIWidget>();
  16.  
  17.                                         if (w != null)
  18.                                         {
  19.                                                 w.width = Mathf.RoundToInt(value.x);
  20.                                                 w.height = Mathf.RoundToInt(value.y);
  21.                                                 Vector3[] wc = w.localCorners;
  22.                                                 mCenter = Vector3.Lerp(wc[0], wc[2], 0.5f);
  23.                                         }
  24.                                         else mCenter = foreground.localPosition + (Vector3)value * 0.5f;
  25.                                 }
  26.                                 ForceUpdate();
  27.                         }
  28.                 }
  29.         }