UGUI学习笔记1——UIBehaviour

UIBehaviour

namespace UnityEngine.EventSystems
{
    /// <summary>
    /// Base behaviour that has protected implementations of Unity lifecycle functions.
    /// </summary>
    public abstract class UIBehaviour : MonoBehaviour
    {
        protected virtual void Awake()
        {}

        protected virtual void OnEnable()
        {}

        protected virtual void Start()
        {}

        protected virtual void OnDisable()
        {}

        protected virtual void OnDestroy()
        {}

        /// <summary>
        /// Returns true if the GameObject and the Component are active.
        /// </summary>
        public virtual bool IsActive()
        {
        	// Unity 引擎内部实现的 属性声明,用于判断某个对象是否处于激活且启用的状态。
        	// 是activeInHierarchy&&enable
            return isActiveAndEnabled;
        }

// 编辑器相关方法
#if UNITY_EDITOR
		// 在 Inspector 中修改值或脚本重新编译时调用,用于数据验证。
        protected virtual void OnValidate()
        {}

		// 当组件被重置(通过右键菜单)时调用,用于设置默认值。
        protected virtual void Reset()
        {}
#endif
        /// <summary>
        /// This callback is called when the dimensions of an associated RectTransform change. It is always called before Awake, OnEnable, or Start. The call is also made to all child RectTransforms, regardless of whether their dimensions change (which depends on how they are anchored).
        /// 布局调整在 Awake、OnEnable 或 Start 之前
        /// </summary>
      
      	// 当关联的 RectTransform 尺寸或锚点变化时调用(如窗口缩放)。
        protected virtual void OnRectTransformDimensionsChange()
        {}

		// 变化父节点之前触发。
        protected virtual void OnBeforeTransformParentChanged()
        {}

		// 当父级 GameObject 变化时调用,用于调整布局依赖关系。
        protected virtual void OnTransformParentChanged()
        {}

		// 当动画修改了 UI 属性后触发,用于同步状态。
        protected virtual void OnDidApplyAnimationProperties()
        {}

		// 当所属的 CanvasGroup(控制子元素交互性/透明度)属性变化时调用。
        protected virtual void OnCanvasGroupChanged()
        {}

        /// <summary>
        /// Called when the state of the parent Canvas is changed.
        /// </summary>
        // 父级 Canvas 被启用/禁用,或嵌套 Canvas 的 OverrideSorting 属性变化。
        protected virtual void OnCanvasHierarchyChanged()
        {}

        /// <summary>
        /// Returns true if the native representation of the behaviour has been destroyed.
        /// </summary>
        /// <remarks>
        /// When a parent canvas is either enabled, disabled or a nested canvas's OverrideSorting is changed this function is called. You can for example use this to modify objects below a canvas that may depend on a parent canvas - for example, if a canvas is disabled you may want to halt some processing of a UI element.
        /// </remarks>
        public bool IsDestroyed()
        {
        	//销毁状态检查
        	
            // Workaround for Unity native side of the object
            // having been destroyed but accessing via interface
            // won't call the overloaded ==
            return this == null;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值