Exemplo n.º 1
0
        /// <summary>
        /// 根据类型获取UI的资源信息
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        private UIInstance GetUIInstance(Type t)
        {
            int hash = t.GetHashCode();

            UIInstance config = null;

            if (!_allUIInstances.TryGetValue(hash, out config))
            {
                object[] attrs = t.GetCustomAttributes(typeof(UIViewAttribute), false);
                if (attrs.Length == 0)
                {
                    return(null);
                }
                UIViewAttribute uIViewAttribute = attrs[0] as UIViewAttribute;

                if (string.IsNullOrEmpty(uIViewAttribute?.ViewPath) || string.IsNullOrEmpty(uIViewAttribute.AssetBundleName))
                {
                    return(null);
                }

                config = new UIInstance(uIViewAttribute.AssetBundleName, uIViewAttribute.ViewPath);

                _allUIInstances.Add(hash, config);
            }

            return(config);
        }
Exemplo n.º 2
0
 public TaskLogs(int taskId, string outfilename, UIInstance uiInstance)
 {
     this.outfilename = outfilename;
     this.taskId      = taskId;
     lines            = new List <string>();
     this.uiInstance  = uiInstance;
 }
Exemplo n.º 3
0
        /// <summary>
        /// 销毁指定界面
        /// </summary>
        /// <param name="target">目标</param>
        public static void DestroyUI(T target)
        {
            //先尝试从层级管理器里移除掉
            //如果管理器没有移除成功
            //那么代表不能删除
            if (!CUILayoutManager.Instance.TryRemoveUI(target))
            {
                return;
            }


            //单例UI直接销毁
            if (target == UIInstance)
            {
                if (UIInstance.UIInfo.IsAnimationUI)
                {
                    //支持动画的话就播完动画再销毁
                    UIInstance.AnimOnDestroy(() =>
                    {
                        GameObject.Destroy(UIInstance.gameObject);
                        UIInstance = null;
                    });
                }
                else
                {
                    //不支持动画直接销毁
                    GameObject.Destroy(UIInstance.gameObject);
                    UIInstance = null;
                }

                return;
            }

            //销毁非单例UI
            T findObj = UIInstances.Find(( T obj ) =>
            {
                return(obj == target);
            });

            if (findObj != null)
            {
                if (findObj.UIInfo.IsAnimationUI)
                {
                    //支持动画的话就播完动画再销毁
                    findObj.AnimOnDestroy(() =>
                    {
                        GameObject.Destroy(findObj.gameObject);
                        UIInstances.Remove(findObj);
                    });
                }
                else
                {
                    //不支持动画直接销毁
                    GameObject.Destroy(findObj.gameObject);
                    UIInstances.Remove(findObj);
                }
            }
        }
Exemplo n.º 4
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(this);
     }
     trans = _animPanel.GetComponent <RectTransform>();
 }
Exemplo n.º 5
0
        /// <summary>
        /// 推一个UI界面到栈顶,并打开
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="allowMulti"></param>
        /// <param name="parameters"></param>
        public void Push <T>(bool allowMulti = false, params object[] parameters) where T : UIView
        {
            UIInstance config = GetUIInstance(typeof(T));

            if (config == null)
            {
                return;
            }

            //先将栈顶的UI界面置为暂停状态
            if (_stackUIAsset.Count > 0)
            {
                UIInstance lastConfig = _stackUIAsset.Peek();
                //若该UI已经打开,且不允许加载多个,则返回
                if (Equals(lastConfig, config) && !allowMulti)
                {
                    return;
                }

                IUIView uIView = GetUIView(lastConfig);

                UIEventArgs pauseArgs = new UIEventArgs();
                pauseArgs.UIView = uIView;
                _event.CallEvent(this, EventType.UIPause, pauseArgs);

                uIView.OnPause();
            }

            //UIInstance newConfig = null;
            //newConfig = config;

            //if (allowMulti)
            //    newConfig = new UIInstance(config.AssetBundleName, config.AssetPath);
            //else
            //    newConfig = config;

            _stackUIAsset.Push(config);
            UIView newUIView = GetUIView(config);

            newUIView.OnEnter(parameters);

            //触发打开事件
            UIEventArgs newargs = new UIEventArgs();

            newargs.UIView = newUIView;
            _event.CallEvent(this, EventType.UIEnter, newargs);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 从栈顶关闭一个UI界面,并确定是否销毁
        /// </summary>
        /// <param name="isdestroy"></param>
        public void Pop(bool isdestroy)
        {
            if (_stackUIAsset.Count > 0)
            {
                UIInstance lastConfig = _stackUIAsset.Pop();
                UIView     lastView;
                if (_allUIView.TryGetValue(lastConfig, out lastView))
                {
                    //触发关闭事件
                    UIEventArgs exitArgs = new UIEventArgs();
                    exitArgs.UIView = lastView;
                    _event.CallEvent(this, EventType.UIExit, exitArgs);

                    lastView.OnExit();

                    if (isdestroy)
                    {
                        _allUIView.Remove(lastConfig);
                        MonoBehaviour.Destroy(lastView);
                    }
                    else
                    {
                        lastView.gameObject.SetActive(false);
                    }
                }
            }

            //如果还有面板
            if (_stackUIAsset.Count > 0)
            {
                UIInstance lastAssetConfig = _stackUIAsset.Peek();
                UIView     lastUiView;
                if (_allUIView.TryGetValue(lastAssetConfig, out lastUiView))
                {
                    lastUiView.OnResume();
                    //触发恢复事件
                    UIEventArgs resumeArgs = new UIEventArgs();
                    resumeArgs.UIView = lastUiView;
                    _event.CallEvent(this, EventType.UIResume, resumeArgs);
                }
            }
        }
Exemplo n.º 7
0
        public void OnClose()
        {
            //遍历栈,弹出所有UI面板
            while (_stackUIAsset.Count > 0)
            {
                UIInstance instance = _stackUIAsset.Pop();
                UIView     view     = _allUIView[instance];

                UIEventArgs exitArgs = new UIEventArgs();
                exitArgs.UIView = view;
                _event.CallEvent(this, EventType.UIExit, exitArgs);
                view.OnExit();
            }

            foreach (var item in _allUIView.Values)
            {
                MonoBehaviour.Destroy(item);
            }
            _allUIView.Clear();
        }
Exemplo n.º 8
0
        /// <summary>
        /// 获取UI面板实例
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        private UIView GetUIView(UIInstance config)
        {
            UIView uiView = null;

            if (!_allUIView.TryGetValue(config, out uiView))
            {
                GameObject uiTemplate = _resource.LoadAsset <GameObject>(config.AssetBundleName, config.AssetPath);
                if (uiTemplate == null)
                {
                    throw new Exception("uiview not found: " + config.AssetBundleName + " : " + config.AssetPath);
                }
                GameObject uiInstance = GameObject.Instantiate(uiTemplate);
                uiView = uiInstance.GetComponent <UIView>();
                if (uiView == null)
                {
                    return(null);
                }
                _allUIView[config] = uiView;
                return(uiView);
            }

            uiView.gameObject.SetActive(true);
            return(uiView);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 干掉UI界面
        /// 单例界面干掉单例
        /// 非单例界面干掉所有非单例
        /// </summary>
        public static void DestroyUI()
        {
            if (UIInstance != null && !UIInstance.m_IsRemoving)
            {
                //单例 UI的销毁

                //先尝试从层级管理器里移除掉
                //如果管理器没有移除成功
                //那么代表不能删除
                if (!CUILayoutManager.Instance.TryRemoveUI(m_UIInstance))
                {
                    return;
                }

                //删除UI
                if (UIInstance.UIInfo.IsAnimationUI)
                {
                    UIInstance.m_IsRemoving = true;
                    //支持动画的话就播完动画再销毁
                    UIInstance.AnimOnDestroy(() =>
                    {
                        UIInstance.m_IsRemoving = false;
                        GameObject.Destroy(UIInstance.gameObject);
                        UIInstance = null;
                    });
                }
                else
                {
                    //不支持动画直接销毁
                    GameObject.Destroy(UIInstance.gameObject);
                    UIInstance = null;
                }
            }
            else if (m_UIInstances.Count > 0)
            {
                //非单例 UI的销毁

                for (int i = 0; i < m_UIInstances.Count; i++)
                {
                    //先尝试从层级管理器里移除掉
                    //如果管理器没有移除成功
                    //那么代表不能删除
                    if (!CUILayoutManager.Instance.TryRemoveUI(UIInstances[i]))
                    {
                        continue;;
                    }

                    //支持动画的话就播完动画再销毁
                    if (UIInstances[i].UIInfo.IsAnimationUI)
                    {
                        UIInstances[i].AnimOnDestroy(() => { GameObject.Destroy(UIInstances[i].gameObject); });
                    }
                    else
                    {
                        //不支持动画直接销毁
                        GameObject.Destroy(UIInstances[i].gameObject);
                    }
                }

                m_UIInstances.Clear();
            }

            return;
        }
Exemplo n.º 10
0
 public Command(UIInstance uiInstance, UIStates uiStates, MainWindow mainWindow)
 {
     UiInstance = uiInstance;
     UiStates   = uiStates;
     MainWindow = mainWindow;
 }
Exemplo n.º 11
0
 public TranslationCache(UIInstance uiInstance)
 {
     _uiInstance = uiInstance;
 }