Exemplo n.º 1
0
        public void Update()
        {
            if (_allUIView == null || _allUIView.Count <= 0)
            {
                return;
            }

            float deltaTime = Time.deltaTime;

            for (UI_TYPE type = UI_TYPE.UI_NONE; type < UI_TYPE.UI_MAX; ++type)
            {
                BaseUIView baseUIView = null;
                if (_allUIView.TryGetValue(type, out baseUIView))
                {
                    baseUIView.Core(deltaTime);

                    if (baseUIView.IsNeedDestroy())
                    {
                        _allUIView.Remove(type);
                        _backUIViewQueue.Remove(baseUIView);
                        _openUIViewQueue.Remove(baseUIView);
                        baseUIView.Hide();
                        baseUIView.Release();
                        GameObject.Destroy(baseUIView.gameObject);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Release()
        {
            if (_allUIView == null)
            {
                return;
            }

            for (UI_TYPE i = UI_TYPE.UI_NONE; i < UI_TYPE.UI_MAX; ++i)
            {
                BaseUIView uiView = null;
                if (_allUIView.TryGetValue(i, out uiView))
                {
                    if (uiView != null)
                    {
                        if (!uiView.IsClose())
                        {
                            uiView.Hide();
                        }
                        uiView.Release();
                        GameObject.Destroy(uiView.gameObject);
                    }
                }
            }

            _UICamera = null;
            _allUIView.Clear();
            _backUIViewQueue.Clear();
            Resources.UnloadUnusedAssets();
        }
Exemplo n.º 3
0
        public void RefreshUISortingOrder()
        {
            int maxSortingOrder        = 0;
            int popMaxSortingOrder     = POPUP_VIEW_SORTINGORDER;
            int specialMaxSotringOrder = SPECIAL_VIEW_SOTRINGORDER;

            for (int i = 0; i < _openUIViewQueue.Count; ++i)
            {
                BaseUIView baseUIView = _openUIViewQueue[i];
                if (baseUIView == null || baseUIView.gameObject == null)
                {
                    continue;
                }

                if (baseUIView.UILayer == UI_LAYER.NORMAL)
                {
                    maxSortingOrder = baseUIView.UpdateSortingOrder(maxSortingOrder);
                }
                else if (baseUIView.UILayer == UI_LAYER.POPUP)
                {
                    popMaxSortingOrder = baseUIView.UpdateSortingOrder(popMaxSortingOrder);
                }
                else if (baseUIView.UILayer == UI_LAYER.MASK)
                {
                    specialMaxSotringOrder = baseUIView.UpdateSortingOrder(specialMaxSotringOrder);
                }
            }
        }
Exemplo n.º 4
0
        public BaseUIView OpenUIView(UI_TYPE uiType, object param = null)
        {
            BaseUIView baseUIView = null;

            if (!_allUIView.TryGetValue(uiType, out baseUIView))
            {
                string     uiAssetPath = GetUIAssetPathByUIType(uiType);
                GameObject goUI        = GameObject.Instantiate(Resources.Load <GameObject>(uiAssetPath));
                baseUIView = goUI.GetComponent <BaseUIView>();
                _allUIView.Add(uiType, baseUIView);
            }
            else
            {
                if (!baseUIView.IsClose())
                {
                    baseUIView.Hide();
                }
            }

            if (baseUIView.IsNeedBack())
            {
                for (int i = 0, len = _backUIViewQueue.Count; i < len; ++i)
                {
                    BaseUIView tempUIView = _backUIViewQueue[i];
                    if (tempUIView.Equals(baseUIView))
                    {
                        _backUIViewQueue.RemoveAt(i);
                        break;
                    }
                }

                _backUIViewQueue.Add(baseUIView);
            }

            if (_openUIViewQueue.Contains(baseUIView))
            {
                _openUIViewQueue.Remove(baseUIView);
            }
            _openUIViewQueue.Add(baseUIView);

            ChangeUIViewParent(baseUIView);

            HideOldView();
            baseUIView.UIType = uiType;
            if (baseUIView.IsShowAfterOpenEffect)
            {
                baseUIView.UIParam = param;
                baseUIView.ShowOpenEffect();
            }
            else
            {
                baseUIView.Show(param);
            }
            baseUIView.ChangeCameraRenderTexture(true);
            baseUIView.ChangeCanvasLayer(UILayer);
            baseUIView.ChangeGraphicRaycasterState(true);
            RefreshUISortingOrder();

            return(baseUIView);
        }
Exemplo n.º 5
0
        public void CloseUIView(BaseUIView closeUIView)
        {
            if (closeUIView == null)
            {
                return;
            }

            if (closeUIView.DeleteOnHide)
            {
                _allUIView.Remove(closeUIView.UIType);
                _backUIViewQueue.Remove(closeUIView);
                _openUIViewQueue.Remove(closeUIView);
                closeUIView.Hide();
                closeUIView.Release();
                GameObject.Destroy(closeUIView.gameObject);
            }
            else
            {
                ChangeUIViewParent(closeUIView, true);
                closeUIView.ChangeCameraRenderTexture(false);
                closeUIView.ChangeCanvasLayer(HideLayer);
                closeUIView.ChangeGraphicRaycasterState(false);
                _openUIViewQueue.Remove(closeUIView);
                closeUIView.Hide();
            }
        }
Exemplo n.º 6
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            BaseUIView baseUIView = target as BaseUIView;

            if (baseUIView == null)
            {
                return;
            }

            if (baseUIView.gameObject.activeInHierarchy && baseUIView.ContentCanvas == null)
            {
                baseUIView.CreateUIContent();
            }

            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            GUILayout.Label("UI_TYPE : ", GUILayout.Width(60));
            string uiType = UIPostprocessor.GetUITypeByUIPrefabName(baseUIView.gameObject.name);

            if (System.Enum.IsDefined(typeof(UI_TYPE), uiType))
            {
                GUILayout.Label(uiType + " = " + (int)(UI_TYPE)System.Enum.Parse(typeof(UI_TYPE), uiType));
            }
            GUILayout.EndHorizontal();
        }
Exemplo n.º 7
0
        public void CloseUIView(UI_TYPE uiType)
        {
            BaseUIView baseUIView = null;

            if (_allUIView.TryGetValue(uiType, out baseUIView))
            {
                CloseUIView(baseUIView);
            }
        }
Exemplo n.º 8
0
        public BaseUIView FindUIViewByUIType(UI_TYPE uiType)
        {
            BaseUIView baseUIView = null;

            if (_allUIView.TryGetValue(uiType, out baseUIView))
            {
                return(baseUIView);
            }

            return(null);
        }
Exemplo n.º 9
0
        public bool IsUIOpen(UI_TYPE uiType)
        {
            BaseUIView baseUIView = null;

            if (_allUIView.TryGetValue(uiType, out baseUIView))
            {
                return(!baseUIView.IsClose());
            }

            return(false);
        }
Exemplo n.º 10
0
        public bool IsUIBackHide(UI_TYPE uiType)
        {
            BaseUIView baseUIView = null;

            if (_allUIView.TryGetValue(uiType, out baseUIView))
            {
                int index = _backUIViewQueue.LastIndexOf(baseUIView);
                return(index < (_backUIViewQueue.Count - 1));
            }

            return(false);
        }
Exemplo n.º 11
0
        static void OnImportMonoUIAsset(string assetPath)
        {
            if (!assetPath.Contains(_uiPrefabFile) || !assetPath.Contains(".prefab"))
            {
                return;
            }

            Debug.Log("OnImportMonoUIAsset:" + assetPath);
            GameObject uiPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath);

            if (uiPrefab == null)
            {
                return;
            }

            BaseUIView baseUIView = uiPrefab.GetComponent <BaseUIView>();

            if (baseUIView == null)
            {
                return;
            }

            string        uiType = GetUITypeByUIPrefabName(uiPrefab.name);
            string        uiPath = assetPath.Replace("Assets/Resources/", "").Replace(".prefab", "");
            List <string> names  = new List <string>();
            Dictionary <string, string> dictUIPaths = new Dictionary <string, string>();

            LoadCacheCommonUIData(names, dictUIPaths);

            if (!names.Contains(_ui_none_key))
            {
                names.Add(_ui_none_key);
                names.Add(_ui_max_key);

                dictUIPaths.Add(_ui_none_key, "null");
                dictUIPaths.Add(_ui_max_key, "null");
            }

            if (!names.Contains(uiType))
            {
                int max = names.Count - 1;
                names.Insert(max, uiType);
                dictUIPaths.Add(uiType, uiPath);

                AutoCreateCommonUIDataCS(names, dictUIPaths);
                SaveCacheCommonUIData(names, dictUIPaths);

                PrefabUtility.SetPropertyModifications(uiPrefab, new PropertyModification[0]);
                AssetDatabase.SaveAssets();
            }
        }
Exemplo n.º 12
0
        private void ChangeUIViewParent(BaseUIView baseUIView, bool isHide = false)
        {
            if (baseUIView == null || baseUIView.transform == null)
            {
                return;
            }

            if (isHide && _hideRoot != null)
            {
                baseUIView.transform.SetParent(_hideRoot.transform, false);
            }
            else
            {
                baseUIView.transform.SetParent(_layerRoots[(int)baseUIView.UILayer], false);
                baseUIView.transform.localPosition = Vector3.zero;
            }
        }
Exemplo n.º 13
0
        private void HideOldView()
        {
            if (_backUIViewQueue.Count <= 0)
            {
                return;
            }

            BaseUIView baseUIView = _backUIViewQueue[_backUIViewQueue.Count - 1];

            if (baseUIView.UIMode == UI_MODE.HIDE_OTHER)
            {
                for (int i = _backUIViewQueue.Count - 2; i >= 0; --i)
                {
                    _backUIViewQueue[i].ChangeCameraRenderTexture(false);
                    _backUIViewQueue[i].ChangeCanvasLayer(HideLayer);
                    _backUIViewQueue[i].ChangeGraphicRaycasterState(false);
                    ChangeUIViewParent(_backUIViewQueue[i], true);
                }
            }
        }
Exemplo n.º 14
0
        static void OnMoveMonoUIAsset(string assetPath)
        {
            if (!assetPath.Contains(_uiPrefabFile) || !assetPath.Contains(".prefab"))
            {
                return;
            }

            Debug.Log("OnMoveMonoUIAsset:" + assetPath);
            GameObject uiPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath);

            if (uiPrefab == null)
            {
                return;
            }

            BaseUIView baseUIView = uiPrefab.GetComponent <BaseUIView>();

            if (baseUIView == null)
            {
                return;
            }

            string        uiType = GetUITypeByUIPrefabName(uiPrefab.name);
            string        uiPath = assetPath.Replace("Assets/Resources/", "").Replace(".prefab", "");
            List <string> names  = new List <string>();
            Dictionary <string, string> dictUIPaths = new Dictionary <string, string>();

            LoadCacheCommonUIData(names, dictUIPaths);
            if (dictUIPaths.ContainsKey(uiType) && dictUIPaths[uiType] != uiPath)
            {
                string oldAssetPath = "Assets/Resources/" + dictUIPaths[uiType] + ".asset";
                AssetDatabase.DeleteAsset(oldAssetPath);

                dictUIPaths[uiType] = uiPath;

                AutoCreateCommonUIDataCS(names, dictUIPaths);
                SaveCacheCommonUIData(names, dictUIPaths);
            }
        }
Exemplo n.º 15
0
        public void CloseUIView()
        {
            if (_backUIViewQueue == null || _backUIViewQueue.Count <= 0)
            {
                return;
            }

            int        lastIndex   = _backUIViewQueue.Count - 1;
            BaseUIView closeUIView = _backUIViewQueue[lastIndex];
            UI_TYPE    closeUIType = closeUIView.UIType;

            _backUIViewQueue.RemoveAt(lastIndex);
            CloseUIView(closeUIView);

            if (lastIndex > 0)
            {
                BaseUIView showUIView = _backUIViewQueue[lastIndex - 1];
                ChangeUIViewParent(showUIView);
                showUIView.ChangeCameraRenderTexture(true);
                showUIView.ChangeCanvasLayer(UILayer);
                showUIView.ChangeGraphicRaycasterState(true);
                showUIView.Back();
            }
        }