uGUI之继承结构
UIBehaviour
继承自MonoBehaviour ,代表ui 组件(区分渲染的ui组件)
- 组件流程方法
//流程方法 protected virtual void Awake() {} protected virtual void OnEnable() {} protected virtual void Start() {} protected virtual void OnDisable() {} protected virtual void OnDestroy() {}ui 组件结构变动回调函数
protected virtual void OnRectTransformDimensionsChange() {} protected virtual void OnBeforeTransformParentChanged() {} protected virtual void OnTransformParentChanged() {} protected virtual void OnDidApplyAnimationProperties() {} protected virtual void OnCanvasGroupChanged() {} /// <summary> /// Called when the state of the parent Canvas is changed. /// </summary> protected virtual void OnCanvasHierarchyChanged() {}添加 IsActive 方法
/// <summary> /// Returns true if the GameObject and the Component are active. /// isActiveAndEnabled 变量存在于 Behaviour中,组件都有的两个变量,命名规则 isxx 都是只读变量 /// 1. enabled 2. isActiveAndEnabled /// </summary> public virtual bool IsActive() { return isActiveAndEnabled; }添加 IsDestory 方法(todo)
/// <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; }完整代码
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. /// isActiveAndEnabled 变量存在于 Behaviour中,组件都有的两个变量,命名规则 isxx 都是只读变量 /// 1. enabled 2. isActiveAndEnabled /// </summary> public virtual bool IsActive() { return isActiveAndEnabled; } #if UNITY_EDITOR protected virtual void OnValidate() {} protected virtual void Reset() {} #endif /// <summary> /// This callback is called if an associated RectTransform has its dimensions changed. The call is also made to all child rect transforms, even if the child transform itself doesn't change - as it could have, depending on its anchoring. /// </summary> protected virtual void OnRectTransformDimensionsChange() {} protected virtual void OnBeforeTransformParentChanged() {} protected virtual void OnTransformParentChanged() {} protected virtual void OnDidApplyAnimationProperties() {} protected virtual void OnCanvasGroupChanged() {} /// <summary> /// Called when the state of the parent Canvas is changed. /// </summary> 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; } }