/// <summary> /// 界面异步创建完成 /// </summary> /// <param name="view"></param> private void OnAsyncCreated(AView view) { _layer.ShowView(view); if (null != _onCreated) { _onCreated.Invoke(view as AViewType, _token); } }
protected override void ShowView(AView view) { if (false == _viewList.Contains(view)) { view.onDestroyed += RemoveView; _viewList.Add(view); } }
/// <summary> /// View对象销毁的回调 /// </summary> /// <param name="view"></param> void OnViewDestroy(AView view) { if (Current == view) { Current.onDestroyed -= OnViewDestroy; Current = null; } }
public override void Clear() { if (null != Current) { Current.onDestroyed -= 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.onDestroyed -= OnViewDestroy; Current.Destroy(); Current = null; } Current = view; view.onDestroyed += OnViewDestroy; }
/// <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); }
public void ChangeSiblingIndex(AView view, int index) { view.gameObject.transform.SetSiblingIndex(index); AutoOptimize(); }
void RemoveView(AView view) { view.onDestroyed -= RemoveView; viewList.Remove(view); AutoOptimize(); }
void RemoveView(AView view) { view.onDestroyed -= RemoveView; _viewList.Remove(view); }