Ejemplo n.º 1
0
        public virtual Rect GetSafeArea()
        {
            Rect nsa = new Rect(0, 0, Screen.width, Screen.height);

            if (!IsRootSafeArea())
            {
                return(nsa);
            }
            else
            {
                Rect safeArea = Screen.safeArea;
                if (Application.isEditor)
                {
#if UNITY_EDITOR
                    nsa      = EditorSafeAreaSimulator.GetNormalizedSafeArea();
                    safeArea = new Rect(Screen.width * nsa.x, Screen.height * nsa.y, Screen.width * nsa.width, Screen.height * nsa.height);
#endif
                }
                else if (IsStatusBarActiveWithLayoutStable() && Screen.safeArea == nsa)
                {
                    //This is the size of statusbar in IOS/Android without notch
                    safeArea.height = Mathf.Max(0, safeArea.height - GetStatusBarHeight());
                }


                return(safeArea);
            }
        }
Ejemplo n.º 2
0
        protected virtual void TryInit()
        {
            TryInstantiateContent();
            if (Content != null)
            {
                if (m_forceClip)
                {
                    Content.gameObject.GetAddComponent <RectMask2D>();
                }
                var layoutElement = Content.gameObject.GetAddComponent <LayoutElement>();
                layoutElement.ignoreLayout = true;
                ResetRectTransform(m_Content, false);
                RefreshContentChildren();
            }

            TryInstantiateUnsafeContent();
#if UNITY_EDITOR
            EditorSafeAreaSimulator.RegisterSafeAreaComponent(this);
#endif
            if (m_UnsafeContent != null)
            {
#if UNITY_EDITOR
                SetupSimulatorMaskContent();
#endif

                ResetRectTransform(m_UnsafeContent, true);
            }
            Refresh();
        }
Ejemplo n.º 3
0
        protected override void OnDestroy()
        {
            base.OnDestroy();
            CancelInvoke();
            ClearCachedInteropInfos();
#if UNITY_EDITOR
            EditorSafeAreaSimulator.UnregisterSafeAreaComponent(this);
#endif
        }
Ejemplo n.º 4
0
        protected virtual void SetupSimulatorMaskContent()
        {
            var spriteToApply = m_UnsafeContent != null && Application.isPlaying ? EditorSafeAreaSimulator.GetOrLoadSimulatorSprite() : null;

            if (Application.isPlaying && spriteToApply != null && m_UnsafeContent != null)
            {
                if (_simulatorSpriteContent == null)
                {
                    _simulatorSpriteContent = new GameObject("SimulatorMaskContent").AddComponent <Image>();
                    _simulatorSpriteContent.gameObject.hideFlags = HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild;
                    _simulatorSpriteContent.transform.SetParent(Content.parent);
                    _simulatorSpriteContent.transform.SetSiblingIndex(Content.transform.GetSiblingIndex() + 1);
                    _simulatorSpriteContent.type = Image.Type.Sliced;

                    var layoutElement = _simulatorSpriteContent.gameObject.GetAddComponent <LayoutElement>();
                    layoutElement.ignoreLayout = true;
                }
                if (_simulatorSpriteContent != null)
                {
                    _simulatorSpriteContent.raycastTarget = false;
                    _simulatorSpriteContent.sprite        = spriteToApply;
                    _simulatorSpriteContent.gameObject.SetActive(spriteToApply != null);
                    if (_simulatorSpriteContent.gameObject.activeSelf)
                    {
                        ResetRectTransform(_simulatorSpriteContent.rectTransform);
                    }
                }
            }
            else if (_simulatorSpriteContent != null)
            {
                if (Application.isPlaying)
                {
                    GameObject.Destroy(_simulatorSpriteContent.gameObject);
                }
                else
                {
                    GameObject.DestroyImmediate(_simulatorSpriteContent.gameObject);
                }
            }
        }