protected override void ShowView(AView view) { if (false == _viewList.Contains(view)) { view.onDestroyHandler += RemoveView; _viewList.Add(view); } }
/// <summary> /// View对象销毁的回调 /// </summary> /// <param name="view"></param> void OnViewDestroy(AView view) { if (Current == view) { Current.onDestroyHandler -= OnViewDestroy; Current = null; } }
/// <summary> /// 界面异步创建完成 /// </summary> /// <param name="view"></param> private void OnAsyncCreated(AView view) { _layer.ShowView(view); if (null != _onCreated) { _onCreated.Invoke(view as AViewType, _token); } }
public override void Clear() { if (null != Current) { Current.onDestroyHandler -= OnViewDestroy; Current.Destroy(); Current = null; } }
/// <summary> /// 创建视图 /// </summary> /// <param name="type"></param> /// <param name="prefab"></param> /// <param name="parent"></param> /// <param name="data"></param> /// <returns></returns> public static AView Create(Type type, GameObject prefab, Transform parent, object data = null) { GameObject go = GameObject.Instantiate(prefab, parent); go.name = prefab.name; AView view = Activator.CreateInstance(type) as AView; view.SetGameObject(go, data); return(view); }
/// <summary> /// 切换视图 /// </summary> /// <param name="view"></param> protected override void ShowView(AView view) { if (null != Current) { Current.onDestroyHandler -= OnViewDestroy; Current.Destroy(); Current = null; } Current = view; view.onDestroyHandler += OnViewDestroy; }
public void ChangeSiblingIndex(AView view, int index) { view.gameObject.transform.SetSiblingIndex(index); }
void RemoveView(AView view) { view.onDestroyHandler -= RemoveView; _viewList.Remove(view); }
/// <summary> /// 显示视图 /// </summary> /// <param name="view"></param> protected abstract void ShowView(AView view);
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="prefab"></param> /// <param name="parent"></param> /// <param name="data"></param> /// <returns></returns> public static T Create <T>(GameObject prefab, Transform parent, object data = null) where T : AView { AView view = Create(typeof(T), prefab, parent, data); return(view as T); }