public void SetupDeviceFrame(SafeAreaType type) { // Get prefab name and path string prefabName = "TA Deco"; string prefabPath = type.ToString() + "/" + prefabName; // Make and setup deco game object GameObject prefab = Resources.Load(prefabPath) as GameObject; this._frameDeco = MonoBehaviour.Instantiate(prefab) as GameObject; _frameDeco.name = prefabName; RectTransform frameDecoRectTransform = _frameDeco.GetComponent <RectTransform>(); frameDecoRectTransform.SetParent(this.transform); frameDecoRectTransform.localScale = new Vector3(1.0f, 1.0f, 1.0f); frameDecoRectTransform.offsetMin = new Vector2(0.0f, 0.0f); frameDecoRectTransform.offsetMax = new Vector2(0.0f, 0.0f); // Setup Scale (because canvas base scale) Vector3 scaleFactor = this.GetComponent <RectTransform>().localScale; foreach (Transform tr in _frameDeco.transform) { RectTransform temp = tr.GetComponent <RectTransform>(); temp.localScale = new Vector3(temp.localScale.x / scaleFactor.x, temp.localScale.y / scaleFactor.y, temp.localScale.z / scaleFactor.z); } }
// ================================================================= // Functions 4 Editor // ================================================================= public void ShowSafeAreaFrame(SafeAreaType type) { switch (type) { // Listing SafeArea Device case SafeAreaType.IphoneXTall: UpdateSafeArea(new Rect(0, 102, 1125, 2202), new Vector2(1125.0f, 2436.0f)); break; case SafeAreaType.IphoneXWide: UpdateSafeArea(new Rect(132, 0, 2202, 1125), new Vector2(2436.0f, 1125.0f)); break; default: throw new ArgumentOutOfRangeException("type", type, null); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); SafeAreaController saController = target as SafeAreaController; EditorGUILayout.Space(); EditorGUILayout.LabelField("Safe-Area Test in Editor"); testType = (SafeAreaType)EditorGUILayout.EnumPopup("Test Device Type:", testType); if (!saController.IsSafeAreaOn) { if (GUILayout.Button("Show Safe-Area")) { if (saController) { saController.ShowSafeAreaFrame(testType); saController.SetupDeviceFrame(testType); saController.IsSafeAreaOn = true; } } } else { if (GUILayout.Button("Hide Safe-Area")) { if (saController) { saController.HideSafeAreaFrame(testType); saController.DeleteDeviceFrame(); saController.IsSafeAreaOn = false; } } } EditorGUILayout.Space(); }
public void HideSafeAreaFrame(SafeAreaType type) { UpdateSafeArea(new Rect(0, 0, 1, 1), new Vector2(1, 1)); }