예제 #1
0
        void OnDestroy()
        {
            txtLoadingInfo       = null;
            txtLoadingPercent    = null;
            objLoadingProgressFG = null;
            m_instance           = null;

            if (fxObject != null)
            {
                DestroyImmediate(fxObject);
                fxObject = null;
            }
        }
예제 #2
0
        protected override IEnumerator OnInitCoroutine()
        {
            GameObject uiObject = new GameObject("UI");

            GameObject.DontDestroyOnLoad(uiObject);
            uiObject.layer = LayerMask.NameToLayer("UI");

            // Canvas
            GameObject canvasObject = new GameObject("Canvas");

            canvasObject.transform.parent = uiObject.transform;
            canvasObject.layer            = LayerMask.NameToLayer("UI");
            _canvas                          = canvasObject.AddComponent <Canvas>();
            _canvas.renderMode               = RenderMode.ScreenSpaceOverlay;
            _canvas.pixelPerfect             = false;
            _canvas.sortingOrder             = 0;
            _canvas.targetDisplay            = 0;
            _canvas.additionalShaderChannels = AdditionalCanvasShaderChannels.None;

            CanvasScaler scaler = canvasObject.AddComponent <CanvasScaler>();

            scaler.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
            scaler.referenceResolution = new Vector2(1280, 720);
            scaler.screenMatchMode     = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
            scaler.matchWidthOrHeight  = 0;

            GraphicRaycaster caster = canvasObject.AddComponent <GraphicRaycaster>();

            caster.ignoreReversedGraphics = true;
            caster.blockingObjects        = GraphicRaycaster.BlockingObjects.None;

            // 为了实现窗口独占效果
            _exclusiveObject = new GameObject("ExclusiveObject");
            _exclusiveObject.transform.parent = _canvas.transform;
            _exclusiveObject.SetActive(false); // 禁用
            _exclusiveObject.layer = LayerMask.NameToLayer("UI");
            Image         i  = _exclusiveObject.AddComponent <Image>();
            RectTransform rt = _exclusiveObject.transform as RectTransform;

            rt.anchorMin = new Vector2(0, 0);
            rt.anchorMax = new Vector2(1, 1);
            rt.offsetMin = new Vector2(0, 0);
            rt.offsetMax = new Vector2(0, 0);
            i.color      = new Color(0, 0, 0, 0); // 透明

            // EventSystem
            _eventSystemObject = new GameObject("EventSystem");
            _eventSystemObject.transform.parent = uiObject.transform;
            _eventSystemObject.layer            = LayerMask.NameToLayer("UI");
            EventSystem eventSystem = _eventSystemObject.AddComponent <EventSystem>();

            eventSystem.firstSelectedGameObject = null;
            eventSystem.sendNavigationEvents    = true;
            eventSystem.pixelDragThreshold      = 5;
            StandaloneInputModule inputModule = _eventSystemObject.AddComponent <StandaloneInputModule>();

            inputModule.forceModuleActive = false;

            // loading window
            _uiLoadingWindow = OpenWindow("UILoading", typeof(UILoading), false, false) as UILoading;

            yield return(1);
        }