void ApplySafeArea() { if (SafeAreaTransform == null) { return; } var safeArea = UMVCUtilities.ScreenSafeArea(); var anchorMin = safeArea.position; var anchorMax = safeArea.position + safeArea.size; anchorMin.x /= canvas.pixelRect.width; anchorMin.y /= canvas.pixelRect.height; anchorMax.x /= canvas.pixelRect.width; anchorMax.y /= canvas.pixelRect.height; SafeAreaTransform.anchorMin = anchorMin; SafeAreaTransform.anchorMax = anchorMax; // Debug.Log( // "ApplySafeArea:" + // "\n Screen.orientation: " + Screen.orientation + // #if UNITY_IOS // "\n Device.generation: " + UnityEngine.iOS.Device.generation.ToString() + // #endif // "\n Screen.safeArea.position: " + Screen.safeArea.position.ToString() + // "\n Screen.safeArea.size: " + Screen.safeArea.size.ToString() + // "\n Screen.width / height: (" + Screen.width.ToString() + ", " + Screen.height.ToString() + ")" + // "\n canvas.pixelRect.size: " + canvas.pixelRect.size.ToString() + // "\n anchorMin: " + anchorMin.ToString() + // "\n anchorMax: " + anchorMax.ToString()); }
private static void SafeAreaChanged() { if (lastSafeArea == UMVCUtilities.ScreenSafeArea().size) { return; } //Debug.Log("Safe Area changed from " + lastSafeArea + " to " + Screen.safeArea.size + " at " + Time.time); lastSafeArea = UMVCUtilities.ScreenSafeArea().size; for (int i = 0; i < helpers.Count; i++) { helpers[i].ApplySafeArea(); } }
void Awake() { if (!helpers.Contains(this)) { helpers.Add(this); } canvas = GetComponent <Canvas>(); rectTransform = GetComponent <RectTransform>(); if (!screenChangeVarsInitialized) { lastOrientation = Screen.orientation; lastResolution.x = Screen.width; lastResolution.y = Screen.height; lastSafeArea = UMVCUtilities.ScreenSafeArea().size; screenChangeVarsInitialized = true; } }