Created
February 7, 2024 17:36
-
-
Save LuviKunG/fb994b3e7980d3b25007ae2ec7f4c0a3 to your computer and use it in GitHub Desktop.
User Interface Behaviour. Inherit from this class to create a User Interface Behaviour which will have a reference to the RectTransform.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace UnityEngine | |
{ | |
using EventSystems; | |
/// <summary> | |
/// User Interface Behaviour. | |
/// Inherit from this class to create a User Interface Behaviour | |
/// which will have a reference to the <see cref="RectTransform"/>. | |
/// </summary> | |
public abstract class UserInterfaceBehaviour : UIBehaviour | |
{ | |
/// <summary> | |
/// Get the <see cref="RectTransform"/> of the current <see cref="GameObject"/>. | |
/// </summary> | |
public ref RectTransform rectTransform | |
{ | |
get | |
{ | |
if (m_rectTransform is null) | |
{ | |
m_rectTransform = GetComponent<RectTransform>(); | |
} | |
return ref m_rectTransform; | |
} | |
} | |
private RectTransform m_rectTransform; | |
protected override void OnBeforeTransformParentChanged() | |
{ | |
m_rectTransform = GetComponent<RectTransform>(); | |
} | |
protected override void OnRectTransformDimensionsChange() | |
{ | |
m_rectTransform = GetComponent<RectTransform>(); | |
} | |
protected override void OnTransformParentChanged() | |
{ | |
m_rectTransform = GetComponent<RectTransform>(); | |
} | |
protected override void Reset() | |
{ | |
m_rectTransform = GetComponent<RectTransform>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment