This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

https://docs.unity3d.com/ScriptReference/DrivenRectTransformTracker.html

Is there something like this (DrivenRectTransformTracker) from unity for godot.
For when editor 'tools' change variables that are not meant to be serialized?

I have a script that orients a texture rect based on orientation and dimensions of screen...
If I make it a @tool so it runs in editor too, it constantly dirties the scene...

not a huge deal since i can easily discard those changes or make it not a tool

Probably not... just wondering. Maybe a better way to do it? Thanks

Here is how i was using it

using UnityEngine;
using UnityEngine.UI;
namespace Test
{
    [ExecuteInEditMode]
    [RequireComponent(typeof(Image))]
    public class Background : MonoBehaviour
    {
        Transform _t;
        DrivenRectTransformTracker _driven;
        Image _image;
        void Awake()
        {
            _t = transform;
            _driven = new DrivenRectTransformTracker();
            _driven.Clear();
            _driven.Add(this, _t as RectTransform,
                DrivenTransformProperties.Scale | DrivenTransformProperties.Rotation);
            _image = GetComponent<Image>();
        }
        void OnEnable()
        {
            Orientation.OnChanged += OrientationChanged;
            OrientationChanged();
        }
        void OnDisable()
        {
            Orientation.OnChanged -= OrientationChanged;
            _driven.Clear();
        }
        void OrientationChanged()
        {
            _driven.Clear();
            _driven.Add(this, _t as RectTransform,
                DrivenTransformProperties.Scale | DrivenTransformProperties.Rotation);
            if (Screen.width > Screen.height)
            {
                _t.localScale = new Vector3(Screen.height / _image.preferredWidth, Screen.width / _image.preferredHeight, 1);
                _t.localRotation = Quaternion.Euler(0.0f, 0.0f, 90.0f);
            }
            else
            {
                _t.localScale = new Vector3(Screen.width / _image.preferredWidth, Screen.height / _image.preferredHeight, 1);
                _t.localRotation = Quaternion.identity;
            }
        }
    }
}
in Engine by (1,945 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.