Beispiel #1
0
        public static void PrepAssetForScreenSize(object asset)
        {
            GameObject gameObject = asset as GameObject;

            if (gameObject == null)
            {
                return;
            }
            GameObject gameObject2 = UnityUtils.FindGameObject(gameObject, "WidgetSafeArea");

            if (gameObject2 == null)
            {
                return;
            }
            UIWidget component = gameObject2.GetComponent <UIWidget>();
            Rect     safeArea  = SafeScreenUtils.GetSafeArea();

            if (safeArea.width < (float)Screen.width || safeArea.height < (float)Screen.height || safeArea.x > 0f || safeArea.y > 0f)
            {
                if (SafeScreenUtils.useFixedAnchors)
                {
                    component.leftAnchor.absolute   = 53;
                    component.topAnchor.absolute    = 0;
                    component.rightAnchor.absolute  = -53;
                    component.bottomAnchor.absolute = 0;
                }
                else
                {
                    component.leftAnchor.absolute   = (int)safeArea.x;
                    component.topAnchor.absolute    = (int)safeArea.y;
                    component.rightAnchor.absolute  = (int)(safeArea.width - (float)Screen.width);
                    component.bottomAnchor.absolute = (int)(safeArea.height - (float)Screen.height);
                }
            }
        }
Beispiel #2
0
        public static string GetSafeRectString()
        {
            Rect safeArea = SafeScreenUtils.GetSafeArea();

            return(string.Format("x:{0} y:{1} w:{2} h:{3}", new object[]
            {
                safeArea.x.ToString("F1"),
                safeArea.y.ToString("F1"),
                safeArea.width.ToString("F1"),
                safeArea.height.ToString("F1")
            }));
        }