From 901ca7f93b58dc4edfb5ec3aeb1cbda61eedd3da Mon Sep 17 00:00:00 2001 From: 5argon Date: Sat, 25 May 2019 03:05:11 +0700 Subject: [PATCH] Add cutout database, add a shortcut, ensure 2019.2 support on asmdef. --- CHANGELOG.md | 9 ++++++++- E7.NotchSolution.asmdef | 8 +++++--- Editor/E7.NotchSolution.Editor.asmdef | 7 ++++--- Editor/NotchSimulator.cs | 19 ++++++++++++++++--- Editor/SimulationDatabase.cs | 26 ++++++++++++++++++++++---- Editor/SimulationDatabaseData.cs | 16 +++++++++++++++- README.md | 1 + 7 files changed, 71 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2ce4c2..ea514b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.2.1] +## [1.2.1] - 2019-05-25 + +### Added + +- Shortcut for toggling notch simulation added with the new `UnityEditor.ShortcutManagement` shortcut API. Bound to `Alt+N` by default. +- Cutout database for all available devices. Although they are not used yet currently. ### Fixed - Removed `[ExecuteInEditMode]` from `SafeAreaPadding`. +- Simulation database for One Plus 6T and Huawei Mate 20 Pro was incorrect. It is now updated according to submitted debug data in [this thread](https://github.com/5argon/NotchSolution/issues/2). +- `HideFlags` mistake fixed. ## [1.2.0] - 2019-05-18 diff --git a/E7.NotchSolution.asmdef b/E7.NotchSolution.asmdef index d4ad234..4dbd2dc 100644 --- a/E7.NotchSolution.asmdef +++ b/E7.NotchSolution.asmdef @@ -1,12 +1,14 @@ { "name": "E7.NotchSolution", - "references": [], - "optionalUnityReferences": [], + "references": [ + "Unity.ugui" + ], "includePlatforms": [], "excludePlatforms": [], "allowUnsafeCode": false, "overrideReferences": false, "precompiledReferences": [], "autoReferenced": true, - "defineConstraints": [] + "defineConstraints": [], + "versionDefines": [] } \ No newline at end of file diff --git a/Editor/E7.NotchSolution.Editor.asmdef b/Editor/E7.NotchSolution.Editor.asmdef index 39ba9ed..b3b0983 100644 --- a/Editor/E7.NotchSolution.Editor.asmdef +++ b/Editor/E7.NotchSolution.Editor.asmdef @@ -1,9 +1,9 @@ { "name": "E7.NotchSolution.Editor", "references": [ - "E7.NotchSolution" + "E7.NotchSolution", + "Unity.ugui" ], - "optionalUnityReferences": [], "includePlatforms": [ "Editor" ], @@ -12,5 +12,6 @@ "overrideReferences": false, "precompiledReferences": [], "autoReferenced": true, - "defineConstraints": [] + "defineConstraints": [], + "versionDefines": [] } \ No newline at end of file diff --git a/Editor/NotchSimulator.cs b/Editor/NotchSimulator.cs index f221dd1..68a9f45 100644 --- a/Editor/NotchSimulator.cs +++ b/Editor/NotchSimulator.cs @@ -8,29 +8,42 @@ using UnityEditor.SceneManagement; using UnityEditor.Experimental.SceneManagement; using System.Collections.Generic; +using UnityEditor.ShortcutManagement; namespace E7.NotchSolution { public class NotchSimulator : EditorWindow { + static NotchSimulator win; + [MenuItem("Window/General/Notch Simulator")] public static void ShowWindow() { - var win = EditorWindow.GetWindow(typeof(NotchSimulator)); + win = (NotchSimulator)EditorWindow.GetWindow(typeof(NotchSimulator)); win.titleContent = new GUIContent("Notch Simulator"); } + [Shortcut("Notch Solution/Toggle Notch Simulator", null, KeyCode.N, ShortcutModifiers.Alt)] + static void ToggleSimulation() + { + NotchSimulatorUtility.enableSimulation = !NotchSimulatorUtility.enableSimulation; + UpdateAllMockups(); + UpdateSimulatorTargets(); + win?.Repaint(); + } + /// /// It is currently active only when Notch Simulator tab is present. /// void OnGUI() { + win = this; //Sometimes even with flag I can see it in hierarchy until I move a mouse over it?? EditorApplication.RepaintHierarchyWindow(); bool enableSimulation = NotchSimulatorUtility.enableSimulation; EditorGUI.BeginChangeCheck(); - NotchSimulatorUtility.enableSimulation = EditorGUILayout.BeginToggleGroup("Simulate", NotchSimulatorUtility.enableSimulation); + NotchSimulatorUtility.enableSimulation = EditorGUILayout.BeginToggleGroup("Simulate (Alt+N)", NotchSimulatorUtility.enableSimulation); EditorGUI.indentLevel++; NotchSimulatorUtility.selectedDevice = (SimulationDevice)EditorGUILayout.EnumPopup(NotchSimulatorUtility.selectedDevice); @@ -242,7 +255,7 @@ private static void EnsureCanvasAndEventSetup(PrefabStage prefabStage = null) (GameObject)PrefabUtility.InstantiatePrefab(mockupCanvasPrefab); canvasObject = instantiated.GetComponent(); - canvasObject.hideFlags = overlayCanvasFlag; + instantiated.hideFlags = overlayCanvasFlag; if (Application.isPlaying) { diff --git a/Editor/SimulationDatabase.cs b/Editor/SimulationDatabase.cs index 9b5cd62..b424abb 100644 --- a/Editor/SimulationDatabase.cs +++ b/Editor/SimulationDatabase.cs @@ -4,7 +4,7 @@ namespace E7.NotchSolution { /// - /// Please add more! + /// Please add more! [How to get device's safe area and cutouts](https://github.com/5argon/NotchSolution/issues/2). /// public static class SimulationDatabase { @@ -13,7 +13,13 @@ public static class SimulationDatabase [SimulationDevice.iPhoneX] = new SimulationDatabaseData { portraitSafeArea = new Rect(0, 102, 1125, 2202), + portraitCutouts = new Rect[]{ + new Rect (250, 2346, 625, 90), + }, landscapeSafeArea = new Rect(132, 63, 2172, 1062), + landscapeCutouts = new Rect[]{ + new Rect (2346, 250, 90, 625), + }, screenSize = new Vector2(1125, 2436), }, [SimulationDevice.iPadPro] = new SimulationDatabaseData @@ -24,14 +30,26 @@ public static class SimulationDatabase }, [SimulationDevice.OnePlus6T] = new SimulationDatabaseData { - portraitSafeArea = new Rect(0, 79, 1080, 2261), - landscapeSafeArea = new Rect(79, 0, 2261, 1080), + portraitSafeArea = new Rect(0, 0, 1080, 2261), + portraitCutouts = new Rect[]{ + new Rect (372, 2261, 334, 79), + }, + landscapeSafeArea = new Rect(0, 0, 2261, 1080), + landscapeCutouts = new Rect[]{ + new Rect (2261, 374, 79, 334), + }, screenSize = new Vector2(1080, 2340), }, [SimulationDevice.HuaweiMate20Pro] = new SimulationDatabaseData { - portraitSafeArea = new Rect(0, 100, 1440, 3020), + portraitSafeArea = new Rect(0, 0, 1440, 3020), + portraitCutouts = new Rect[]{ + new Rect (374, 3020, 693, 100), + }, landscapeSafeArea = new Rect(100, 0, 3020, 1440), + landscapeCutouts = new Rect[]{ + new Rect (0, 374, 100, 693), + }, screenSize = new Vector2(1440, 3120), }, }; diff --git a/Editor/SimulationDatabaseData.cs b/Editor/SimulationDatabaseData.cs index 142a8d3..c45114a 100644 --- a/Editor/SimulationDatabaseData.cs +++ b/Editor/SimulationDatabaseData.cs @@ -6,6 +6,20 @@ public class SimulationDatabaseData { public Rect portraitSafeArea; public Rect landscapeSafeArea; - public Vector2 screenSize; //width x height + + /// + /// Optional, if no cutouts just left it as `null`. + /// + public Rect[] portraitCutouts; + + /// + /// Optional, if no cutouts just left it as `null`. + /// + public Rect[] landscapeCutouts; + + /// + /// Width x height of the portrait orientation. + /// + public Vector2 screenSize; } } \ No newline at end of file diff --git a/README.md b/README.md index b55fccb..418723d 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,7 @@ Please see the Issue section. ## Current simulation devices available - iPhone X +- iPad Pro - Huawei Mate 20 Pro (Thank you @06Games !) - OnePlus 6T (Thank you @06Games !)