コード例 #1
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);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 创建UI
        /// </summary>
        /// <param name="PrefabInfo"></param>
        /// <returns></returns>
        private static T CreateUI(CUIInfo UIInfo)
        {
            if (UIInfo.IsSigleton)        //单例UI
            {
                if (m_UIInstance == null) //实例不存在
                {
                    m_UIInstance = InstantiateUIAndReturnComponent(UIInfo);
                }

                return(m_UIInstance);
            }
            else  //非单例UI
            {
                T TempComp = InstantiateUIAndReturnComponent(UIInfo);
                UIInstances.Add(TempComp);
                return(TempComp);
            }
        }