Skip to content

Commit

Permalink
Add cutout database, add a shortcut, ensure 2019.2 support on asmdef.
Browse files Browse the repository at this point in the history
  • Loading branch information
5argon committed May 24, 2019
1 parent 1a3e078 commit 901ca7f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 15 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions E7.NotchSolution.asmdef
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "E7.NotchSolution",
"references": [],
"optionalUnityReferences": [],
"references": [
"Unity.ugui"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
"defineConstraints": [],
"versionDefines": []
}
7 changes: 4 additions & 3 deletions Editor/E7.NotchSolution.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "E7.NotchSolution.Editor",
"references": [
"E7.NotchSolution"
"E7.NotchSolution",
"Unity.ugui"
],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
Expand All @@ -12,5 +12,6 @@
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
"defineConstraints": [],
"versionDefines": []
}
19 changes: 16 additions & 3 deletions Editor/NotchSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/// <summary>
/// It is currently active only when Notch Simulator tab is present.
/// </summary>
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);
Expand Down Expand Up @@ -242,7 +255,7 @@ private static void EnsureCanvasAndEventSetup(PrefabStage prefabStage = null)
(GameObject)PrefabUtility.InstantiatePrefab(mockupCanvasPrefab);

canvasObject = instantiated.GetComponent<MockupCanvas>();
canvasObject.hideFlags = overlayCanvasFlag;
instantiated.hideFlags = overlayCanvasFlag;

if (Application.isPlaying)
{
Expand Down
26 changes: 22 additions & 4 deletions Editor/SimulationDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace E7.NotchSolution
{
/// <summary>
/// Please add more!
/// Please add more! [How to get device's safe area and cutouts](https://github.com/5argon/NotchSolution/issues/2).
/// </summary>
public static class SimulationDatabase
{
Expand All @@ -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
Expand All @@ -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),
},
};
Expand Down
16 changes: 15 additions & 1 deletion Editor/SimulationDatabaseData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ public class SimulationDatabaseData
{
public Rect portraitSafeArea;
public Rect landscapeSafeArea;
public Vector2 screenSize; //width x height

/// <summary>
/// Optional, if no cutouts just left it as `null`.
/// </summary>
public Rect[] portraitCutouts;

/// <summary>
/// Optional, if no cutouts just left it as `null`.
/// </summary>
public Rect[] landscapeCutouts;

/// <summary>
/// Width x height of the portrait orientation.
/// </summary>
public Vector2 screenSize;
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 !)

Expand Down

0 comments on commit 901ca7f

Please sign in to comment.