I hear that the new 4.6 UI’s layout is event driven.
I am having great difficulty finding the event to listen to / handler to interface for listening when a RectTransform changes.
I hear that the new 4.6 UI’s layout is event driven.
I am having great difficulty finding the event to listen to / handler to interface for listening when a RectTransform changes.
For future reference, there is a function that seems to work pretty well for this:
UI.Graphic.OnRectTransformDimensionsChange
I’ve used it to do responsive stacking columns and other neat tricks.
Hi there is a tranform.hasChanged, but this seems to get called constantly…
But this script seems to work, btw. used localToWorldMatrix so that it would detect movement if attached as a child of another object that says rotates, …
using UnityEngine;
using System.Collections;
public class TransFormChange : MonoBehaviour {
private Matrix4x4 old;
// Use this for initialization
void Start () {
old = transform.localToWorldMatrix;
}
// Update is called once per frame
void Update () {
//if (transform.hasChanged)
if (!old.Equals(transform.localToWorldMatrix))
{
Debug.Log (transform.position);
old = transform.localToWorldMatrix;
}
}
}
you have to set it to false again.
void Update () {
if (transform.hasChanged)
{
Debug.Log (transform.position);
transform.hasChanged = false;
}
}