Author Topic: Follow UISpite type: Filled  (Read 8520 times)

longbottomup

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 3
    • View Profile
Follow UISpite type: Filled
« on: January 30, 2015, 12:12:07 AM »
Here is NGUI-UISprite type Filled, Fill Dir: Radial 360:

Yes, now i want like this:

I want to UISprite or something else follow the fill amount. Someone can help, thank you very much.
« Last Edit: January 30, 2015, 12:19:28 AM by longbottomup »

broken

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 140
    • View Profile
Re: Follow UISpite type: Filled
« Reply #1 on: January 30, 2015, 03:53:09 AM »
Hi!

You can try something like this:

  1. public class Test : MonoBehaviour
  2. {
  3.     public UISprite FilledSprite;
  4.     public UISprite MarkSprite;
  5.  
  6.     private float _radius;
  7.  
  8.     void Start()
  9.     {
  10.         _radius = FilledSprite.width / 2f;
  11.     }
  12.  
  13.     void Update()
  14.     {
  15.         var amount = 1 - FilledSprite.fillAmount;
  16.         var angle = 360 * amount;
  17.  
  18.         var radAngle = angle * Mathf.Deg2Rad;
  19.  
  20.         MarkSprite.transform.localPosition = new Vector3(
  21.             Mathf.Sin(radAngle) * _radius,
  22.             Mathf.Cos(radAngle) * _radius,
  23.             0f);
  24.     }
  25. }
  26.  

longbottomup

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Follow UISpite type: Filled
« Reply #2 on: January 30, 2015, 05:51:45 AM »
Hi!

You can try something like this:

  1. public class Test : MonoBehaviour
  2. {
  3.     public UISprite FilledSprite;
  4.     public UISprite MarkSprite;
  5.  
  6.     private float _radius;
  7.  
  8.     void Start()
  9.     {
  10.         _radius = FilledSprite.width / 2f;
  11.     }
  12.  
  13.     void Update()
  14.     {
  15.         var amount = 1 - FilledSprite.fillAmount;
  16.         var angle = 360 * amount;
  17.  
  18.         var radAngle = angle * Mathf.Deg2Rad;
  19.  
  20.         MarkSprite.transform.localPosition = new Vector3(
  21.             Mathf.Sin(radAngle) * _radius,
  22.             Mathf.Cos(radAngle) * _radius,
  23.             0f);
  24.     }
  25. }
  26.  

Thank you for your help, but if i change my sprite by this image:

How about that? Please tell give a solution. Thank you.

broken

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 140
    • View Profile
Re: Follow UISpite type: Filled
« Reply #3 on: January 30, 2015, 09:22:33 AM »
I'm not sure, but I think, you must calculate your dynamic distance (radius) based on image pixels count for current angle.

longbottomup

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Follow UISpite type: Filled
« Reply #4 on: January 30, 2015, 11:10:57 AM »
I'm not sure, but I think, you must calculate your dynamic distance (radius) based on image pixels count for current angle.

Thank you for your help.