Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Raj on March 31, 2014, 03:18:23 PM

Title: Ablility to use Unity Animation Timeline to animate AnchorPoints
Post by: Raj on March 31, 2014, 03:18:23 PM
We would like to be able to animate AnchorPoints within the Unity Animation Timeline as this is a preferable way for our artists to animate objects rather than using the Tween objects.
Title: Re: Ablility to use Unity Animation Timeline to animate AnchorPoints
Post by: ArenMook on April 01, 2014, 07:41:04 AM
You can certainly do that, but you will need an intermediate script like so:
  1. using UnityEngine;
  2.  
  3. [ExecuteInEditMode]
  4. [RequireComponent(typeof(UIRect))]
  5. public class AnimatedAnchor : MonoBehaviour
  6. {
  7.     public float left = 0f;
  8.     public float right = 0f;
  9.     public float top = 0f;
  10.     public float bottom = 0f;
  11.  
  12.     UIRect mRect;
  13.  
  14.     void Start ()
  15.     {
  16.         mRect = GetComponent<UIRect>();
  17.         left = mRect.leftAnchor.absolute;
  18.         right = mRect.rightAnchor.absolute;
  19.         top = mRect.topAnchor.absolute;
  20.         bottom = mRect.bottomAnchor.absolute;
  21.     }
  22.  
  23.     void Update()
  24.     {
  25.         if (mRect.leftAnchor.absolute != left) mRect.leftAnchor.absolute = left;
  26.         if (mRect.rightAnchor.absolute != right) mRect.rightAnchor.absolute = right;
  27.         if (mRect.topAnchor.absolute != top) mRect.topAnchor.absolute = top;
  28.         if (mRect.bottomAnchor.absolute != bottom) mRect.bottomAnchor.absolute = bottom;
  29.     }
  30. }
Title: Re: Ablility to use Unity Animation Timeline to animate AnchorPoints
Post by: Raj on April 01, 2014, 08:05:46 AM
Thanks, one of our engineers had though about this approach, but we thought it might be more useful on the Widget.

We'll give this a go it should be fine.

Cheers