123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System;
- using UnityEngine.UI;
- using UnityEngine.Events;
- using UnityEngine.EventSystems;
- /// <summary>
- /// 游戏中所有UI脚本必须显示继承
- /// </summary>
- public class GameBehavior : MonoBehaviour
- {
- /// <summary>
- /// OnEnable 后 进入回调
- /// </summary>
- public System.Action<GameObject> enterAc = null;
- /// <summary>
- /// 参数
- /// </summary>
- protected object param = null;
- /// <summary>
- /// 设置参数
- /// </summary>
- /// <param name="parameter">参数</param>
- public void SetParameter(object parameter)
- {
- param = parameter;
- }
- /// <summary>
- /// 获取参数
- /// </summary>
- /// <returns>返回参数</returns>
- public object GetParameter()
- {
- return this.param;
- }
- public virtual void registListeners()
- {
- //LogHelper.Log("registListeners");
- }
- public virtual void distroyListeners()
- {
- //LogHelper.Log("distroyListeners");
- }
- public virtual void OnDestroy()
- {
- distroyListeners();
- }
- public virtual void OnEnable()
- {
- //BaseRefresh();
- }
-
- public virtual void OnDisable()
- {
- distroyListeners();
- }
- public virtual void BaseRefresh()
- {
- registListeners();
- if (enterAc != null)
- {
- enterAc(this.gameObject);
- }
- }
- /// <summary>
- /// 查节点
- /// </summary>
- /// <typeparam name="T">泛型</typeparam>
- /// <param name="go">查询对象</param>
- /// <returns>查询结果</returns>
- static public T FindInParents<T>(GameObject go) where T : Component
- {
- if (go == null)
- {
- return null;
- }
- var comp = go.GetComponent<T>();
- if (comp != null)
- {
- return comp;
- }
- Transform t = go.transform.parent;
- while (t != null && comp == null)
- {
- comp = t.gameObject.GetComponent<T>();
- t = t.parent;
- }
- return comp;
- }
- }
|