Exemplo n.º 1
0
 void SetNowView(AView view, object data = null)
 {
     _nowViewName = view.gameObject.name;
     _nowView     = view;
     _nowView.onDestroyHandler += OnViewDestroy;
     view.SetData(data);
 }
Exemplo n.º 2
0
        void UpdateBlur()
        {
            if (null == _blur)
            {
                return;
            }

            if (_needBlurViewSet.Count > 0)
            {
                _blur.gameObject.SetActive(true);
                for (int i = _nowWindows.Count - 1; i > -1; i--)
                {
                    AView view = _nowWindows[i];
                    if (_needBlurViewSet.Contains(view))
                    {
                        int viewChildIdx = view.gameObject.transform.GetSiblingIndex();
                        int blurChildIdx = _blur.GetSiblingIndex();
                        if (blurChildIdx < viewChildIdx)
                        {
                            viewChildIdx--;
                        }
                        _blur.SetSiblingIndex(viewChildIdx);
                        return;
                    }
                }
            }
            else
            {
                _blur.gameObject.SetActive(false);
            }
            _blur.SetSiblingIndex(_blur.parent.childCount - 2);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 创建一个视图对象
        /// </summary>
        /// <param name="viewName"></param>
        /// <param name="abName"></param>
        /// <param name="type"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        static public AView CreateView(string viewName, string abName, Type type, Transform parent)
        {
            GameObject prefab = ResMgr.Ins.Load <GameObject>(abName, viewName);
            AView      view   = CreateViewFromPrefab(prefab, parent, viewName, type);

            return(view);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 移除子视图
 /// </summary>
 /// <param name="child"></param>
 public void RemoveChild(AView child)
 {
     if (child.parent == this)
     {
         child.parent = null;
         _childViewList.Remove(child);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// View对象销毁的回调
 /// </summary>
 /// <param name="view"></param>
 void OnViewDestroy(AView view)
 {
     view.onDestroyHandler -= OnViewDestroy;
     if (_nowView == view)
     {
         _nowView     = null;
         _nowViewName = null;
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// View对象销毁的回调
        /// </summary>
        /// <param name="view"></param>
        void OnViewDestroy(AView view)
        {
            view.onDestroyHandler -= OnViewDestroy;

            _nowWindows.Remove(view);
            _needBlurViewSet.Remove(view);

            UpdateBlur();
        }
Exemplo n.º 7
0
 /// <summary>
 /// 销毁视图对象,同时会回收对应的资源(包含依赖)
 /// </summary>
 /// <param name="viewName"></param>
 /// <param name="isGC">是否执行垃圾回收</param>
 static public void DestroyView(AView view)
 {
     if (_view2ABNameDic.ContainsKey(view.ViewName))
     {
         string abName = _view2ABNameDic[view.ViewName];
         ResMgr.Ins.Unload(abName, false, true);
     }
     GameObject.Destroy(view.gameObject);
 }
Exemplo n.º 8
0
 /// <summary>
 /// 添加子视图
 /// </summary>
 /// <param name="child"></param>
 private void AddChild(AView child)
 {
     if (child.parent != this)
     {
         child.RemoveFromParent();
         child.parent = this;
         _childViewList.Add(child);
     }
 }
Exemplo n.º 9
0
        void SetNowView(AView view, object data = null)
        {
            _nowViewName = view.gameObject.name;
            _nowView     = view;
            _nowView.onDestroyHandler += OnViewDestroy;
            view.SetData(data);

            //执行一次垃圾回收
            ResMgr.Ins.DoGC();
        }
Exemplo n.º 10
0
 void CreateViewAsync(string viewName, string abName, Type type, Action <AView> onCreated, Action <float> onProgress)
 {
     ResMgr.Ins.LoadAsync(abName, viewName,
                          (UnityEngine.Object asset) =>
     {
         GameObject prefab = asset as GameObject;
         AView view        = CreateViewFromPrefab(prefab, _root, viewName, type);
         onCreated(view);
     },
                          onProgress);
 }
Exemplo n.º 11
0
 /// <summary>
 /// 异步创建AView对象
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="viewName">Prefab名称</param>
 /// <param name="abName">Prefab所在资源AB包</param>
 /// <param name="parentView">作为父对象的AView</param>
 /// <param name="parentTransform">父Transform容器</param>
 /// <param name="data">携带的参数</param>
 /// <param name="onCreated">创建完成时调用</param>
 /// <param name="onProgress">创建进度</param>
 public static void CreateAsync <T>(string viewName, string abName, AView parentView, Transform parentTransform, object data = null, Action <T> onCreated = null, Action <float> onProgress = null) where T : AView
 {
     ResMgr.Ins.LoadAsync(abName, viewName,
                          (UnityEngine.Object asset) =>
     {
         GameObject prefab = asset as GameObject;
         T view            = Create <T>(prefab, parentView, parentTransform, data);
         onCreated(view);
     },
                          onProgress);
 }
Exemplo n.º 12
0
        /// <summary>
        /// 通过Prefab创建AView对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="prefab">Prefab对象</param>
        /// <param name="parentView">作为父对象的AView</param>
        /// <param name="parentTransform">父Transform容器</param>
        /// <param name="data">携带的参数</param>
        /// <returns></returns>
        public static T Create <T>(GameObject prefab, AView parentView, Transform parentTransform, object data = null) where T : AView
        {
            AView view = AViewMgr.CreateViewFromPrefab(prefab, parentTransform, prefab.name, typeof(T));

            parentView.AddChild(view);
            if (data != null)
            {
                view.SetData(data);
            }
            return(view as T);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 通过Prefab创建视图
        /// </summary>
        /// <param name="prefab"></param>
        /// <param name="parent"></param>
        /// <param name="viewName"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        static public AView CreateViewFromPrefab(GameObject prefab, Transform parent, string viewName, Type type)
        {
            GameObject go = GameObject.Instantiate(prefab, parent);

            go.name = viewName;

            AView view = Activator.CreateInstance(type) as AView;

            view.SetGameObject(go);
            view.ViewName = viewName;
            return(view);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 关闭(当前打开的)所有窗口
        /// </summary>
        public void CloseAll()
        {
            _needBlurViewSet.Clear();
            int count = _nowWindows.Count;

            for (int i = 0; i < count; i++)
            {
                AView view = _nowWindows[i];
                view.onDestroyHandler -= OnViewDestroy;
                view.Destroy();
            }
            _nowWindows.RemoveRange(0, count);
            UpdateBlur();
        }
Exemplo n.º 15
0
        void OnCreateView(AView view, object data, bool isBlur, bool isCloseOthers)
        {
            if (isCloseOthers)
            {
                CloseAll();
            }

            _nowWindows.Add(view);
            view.onDestroyHandler += OnViewDestroy;
            view.SetData(data);

            if (isBlur)
            {
                _needBlurViewSet.Add(view);
                UpdateBlur();
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// 关闭窗口
 /// </summary>
 /// <param name="target">关闭对象</param>
 public void Close(AView target)
 {
     target.Destroy();
 }