Rect SimulateSafeArea() { SimulatingDevice = DeviceUnknown; if (!simulatesSafeArea) { return(Screen.safeArea); } if (ScreenUtility.IsIPhoneXResolution()) { SimulatingDevice = DeviceIPhoneX; return(ScreenUtility.GetSafeArea(true)); } return(Screen.safeArea); }
void OnGUI() { ValidateOrientation(); if (!ScreenUtility.IsIPhoneXResolution()) { return; } var tex = new Texture2D(1, 1); var safe = GetEmulatedSafeAreaOnIPhoneX(); if (viewsUnsafeArea) { var unsafes = new Rect[] { new Rect(0, 0, Screen.width, safe.y), new Rect(0, safe.y, safe.x, safe.height), new Rect(safe.xMax, safe.y, Screen.width - safe.xMax, safe.height), new Rect(0, safe.yMax, Screen.width, Screen.height - safe.yMax) }; foreach (var area in unsafes) { DrawRect(tex, area, color); } } if (viewsFrame) { var min = Mathf.Min(Screen.width, Screen.height); float homebarWidth = min; float homebarHeight = 16; switch (orientation) { case DeviceOrientation.Portrait: { var notchWidth = Screen.width * 0.55f; var notchHeight = safe.yMin * 2 / 3; var notch = new Rect((Screen.width - notchWidth) / 2, 0, notchWidth, notchHeight); DrawRect(tex, notch, color); homebarWidth = min * 0.45f; break; } case DeviceOrientation.LandscapeRight: { var notchWidth = Screen.height * 0.55f; var notchHeight = safe.xMin * 2 / 3; var notch = new Rect(0, (Screen.height - notchWidth) / 2, notchHeight, notchWidth); DrawRect(tex, notch, color); homebarWidth = min * 0.6f; break; } case DeviceOrientation.LandscapeLeft: { var notchWidth = Screen.height * 0.55f; var notchHeight = (Screen.width - safe.xMax) * 2 / 3; var notch = new Rect(Screen.width - notchHeight, (Screen.height - notchWidth) / 2, notchHeight, notchWidth); DrawRect(tex, notch, color); homebarWidth = min * 0.6f; break; } } { DrawRect(tex, new Rect((Screen.width - homebarWidth) / 2, Screen.height - homebarHeight * 2, homebarWidth, homebarHeight), color); var corner = min / 12f; var diff = new Vector2(-1, -1) / 2 * corner; DrawLine( tex, Vector2.right * corner + diff, Vector2.up * corner + diff, color, corner ); diff = new Vector2(1, -1) / 2 * corner; DrawLine( tex, Vector2.right * Screen.width + Vector2.left * corner + diff, Vector2.right * Screen.width + Vector2.up * corner + diff, color, corner ); diff = new Vector2(-1, 1) / 2 * corner; DrawLine( tex, Vector2.up * Screen.height + Vector2.right * corner + diff, Vector2.up * Screen.height + Vector2.down * corner + diff, color, corner ); diff = new Vector2(1, 1) / 2 * corner; DrawLine( tex, new Vector2(Screen.width, Screen.height) + Vector2.left * corner + diff, new Vector2(Screen.width, Screen.height) + Vector2.down * corner + diff, color, corner ); } } }