internal void SetGameObject(GameObject gameObject, object data = null) { this.gameObject = gameObject; var isActive = this.gameObject.activeInHierarchy; AutoReference(); _z = ComponentUtil.AutoGet <ZeroView>(this.gameObject); _z.aViewClass = GetType().FullName; _z.onEnable += OnGameObjectEnable; _z.onDisable += OnGameObjectDisable; _z.onDestroy += OnGameObjectDestroy; OnInit(data); /* * 通过isActive来限定,只有当gameObject本来为activeInHierarchy状态, * 并且执行OnInit后还在activeInHierarchy状态时,才调用OnEnable,因为 * OnInit中可能执行了SetActive,并且触发了OnGameObjectEnable或OnGameObjectDisable */ if (isActive && this.gameObject.activeInHierarchy) { OnEnable(); } }
protected override void OnInit(object data) { base.OnInit(data); var blurT = transform.Find("Blur"); if (null != blurT) { _blur = ComponentUtil.AutoGet <Blur>(blurT.gameObject); _blur.gameObject.SetActive(false); } }
internal void SetGameObject(GameObject gameObject, object data = null) { this.gameObject = gameObject; _z = ComponentUtil.AutoGet <ZeroView>(this.gameObject); _z.aViewClass = GetType().FullName; _z.onEnable += OnGameObjectEnable; _z.onDisable += OnGameObjectDisable; _z.onDestroy += OnGameObjectDestroy; OnInit(data); if (this.gameObject.activeInHierarchy) { OnEnable(); } }
/// <summary> /// 得到组件(如果没有则自动添加) /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T AudoGetComponent <T>() where T : Component { return(ComponentUtil.AutoGet <T>(gameObject)); }
/// <summary> /// 获取GameObject的事件监听组件,没有则会自动添加 /// </summary> /// <param name="gameObject"></param> /// <returns></returns> public static T Get(GameObject gameObject) { return(ComponentUtil.AutoGet <T>(gameObject)); }