Author Topic: Ablility to use Unity Animation Timeline to animate AnchorPoints  (Read 3391 times)

Raj

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Ablility to use Unity Animation Timeline to animate AnchorPoints
« Reply #1 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. }

Raj

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Ablility to use Unity Animation Timeline to animate AnchorPoints
« Reply #2 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