|
15 | 15 | using System.Collections; |
16 | 16 | using UnityEditor; |
17 | 17 | using UnityEngine; |
| 18 | +using UnityEditor.Callbacks; |
18 | 19 |
|
19 | 20 | [CustomEditor(typeof(Cardboard))] |
| 21 | +[InitializeOnLoad] |
20 | 22 | public class CardboardEditor : Editor { |
21 | | - GUIContent tapIsTriggerLabel = new GUIContent("Tap Is Trigger", |
22 | | - "Allow screen taps and mouse clicks to emulate the magnet trigger."); |
| 23 | +#if UNITY_IOS |
| 24 | + GUIContent syncWithCardboardLabel = new GUIContent("Sync with Cardboard App", |
| 25 | + "Enables the 'Sync with Google Cardboard' slider in the viewer settings dialog."); |
| 26 | +#endif |
| 27 | + |
| 28 | + GUIContent distortionCorrectionLabel = new GUIContent("Distortion Correction", |
| 29 | + "Whether distortion correction is performed the SDK."); |
| 30 | + |
| 31 | + GUIContent vrModeLabel = new GUIContent("VR Mode Enabled", |
| 32 | + "Sets whether VR mode is enabled."); |
23 | 33 |
|
24 | 34 | GUIContent alignmentMarkerLabel = new GUIContent("Alignment Marker", |
25 | | - "Whether to draw the alignment marker. The marker is a vertical line that splits " + |
26 | | - "the viewport in half, designed to help users align the screen with the Cardboard."); |
| 35 | + "Whether to draw the alignment marker. The marker is a vertical line that splits " + |
| 36 | + "the viewport in half, designed to help users align the screen with the Cardboard."); |
27 | 37 |
|
28 | 38 | GUIContent settingsButtonLabel = new GUIContent("Settings Button", |
29 | | - "Whether to draw the settings button. The settings button opens the " + |
30 | | - "Google Cardboard app to allow the user to configure their individual " + |
31 | | - "settings and Cardboard headset parameters."); |
| 39 | + "Whether to draw the settings button. The settings button opens the " + |
| 40 | + "Google Cardboard app to allow the user to configure their individual " + |
| 41 | + "settings and Cardboard headset parameters."); |
32 | 42 |
|
33 | | - GUIContent vrModeEnabledLabel = new GUIContent("VR Mode Enabled", |
34 | | - "Explicitly set whether VR mode is enabled. Clears the Auto Enable VR setting."); |
35 | | - |
36 | | - GUIContent neckModelScaleLabel = new GUIContent("Neck Model Scale", |
37 | | - "The scale factor of the builtin neck model [0..1]. To disable, set to 0."); |
| 43 | + GUIContent autoDriftCorrectionLabel = new GUIContent("Auto Drift Correction", |
| 44 | + "When enabled, drift in the gyro readings is estimated and removed."); |
38 | 45 |
|
39 | | - GUIContent backButtonExitsAppLabel = new GUIContent("Back Button Exits App", |
40 | | - "Whether tapping the back button exits the app."); |
| 46 | + GUIContent tapIsTriggerLabel = new GUIContent("Tap Is Trigger", |
| 47 | + "Whether screen taps are treated as trigger events."); |
41 | 48 |
|
42 | | - GUIContent autoDriftCorrectionLabel = new GUIContent("Auto Drift Correction", |
43 | | - "When enabled, drift in the gyro readings is estimated and removed. Currently only " + |
44 | | - "works on Android."); |
| 49 | + GUIContent neckModelScaleLabel = new GUIContent("Neck Model Scale", |
| 50 | + "The scale factor of the builtin neck model [0..1]. To disable, set to 0."); |
45 | 51 |
|
46 | 52 | GUIContent editorSettingsLabel = new GUIContent("Editor Mock Settings", |
47 | | - "Controls for the in-editor emulation of Cardboard."); |
| 53 | + "Controls for the in-editor emulation of Cardboard."); |
48 | 54 |
|
49 | 55 | GUIContent autoUntiltHeadLabel = new GUIContent("Auto Untilt Head", |
50 | | - "When enabled, just release Ctrl to untilt the head."); |
| 56 | + "When enabled, just release Ctrl to untilt the head."); |
| 57 | + |
| 58 | + GUIContent simulateDistortionLabel = new GUIContent("Simulate Distortion Correction", |
| 59 | + "Whether to perform distortion correction in the editor."); |
51 | 60 |
|
52 | 61 | GUIContent screenSizeLabel = new GUIContent("Screen Size", |
53 | | - "The screen size to emulate."); |
| 62 | + "The screen size to emulate."); |
54 | 63 |
|
55 | 64 | GUIContent deviceTypeLabel = new GUIContent("Device Type", |
56 | | - "The Cardboard device type to emulate."); |
57 | | - |
58 | | - GUIContent simulateDistortionLabel = new GUIContent("Simulate Distortion Correction", |
59 | | - "Whether to perform distortion correction in the editor."); |
| 65 | + "The Cardboard device type to emulate."); |
60 | 66 |
|
61 | 67 | public override void OnInspectorGUI() { |
62 | 68 | GUI.changed = false; |
63 | 69 |
|
64 | | - DrawDefaultInspector(); |
65 | | - |
66 | 70 | Cardboard cardboard = (Cardboard)target; |
67 | 71 |
|
68 | | - bool newTapIsTrigger = EditorGUILayout.Toggle(tapIsTriggerLabel, cardboard.TapIsTrigger); |
69 | | - if (newTapIsTrigger != cardboard.TapIsTrigger) { |
70 | | - cardboard.TapIsTrigger = newTapIsTrigger; |
71 | | - } |
72 | | - |
73 | | - bool newEnableAlignmentMarkder = |
74 | | - EditorGUILayout.Toggle(alignmentMarkerLabel, cardboard.EnableAlignmentMarker); |
75 | | - if (newEnableAlignmentMarkder != cardboard.EnableAlignmentMarker) { |
76 | | - cardboard.EnableAlignmentMarker = newEnableAlignmentMarkder; |
77 | | - } |
78 | | - |
79 | | - bool newEnableSettingsButton = |
80 | | - EditorGUILayout.Toggle(settingsButtonLabel, cardboard.EnableSettingsButton); |
81 | | - if (newEnableSettingsButton != cardboard.EnableSettingsButton) { |
82 | | - cardboard.EnableSettingsButton = newEnableSettingsButton; |
83 | | - } |
84 | | - |
85 | | - bool newAutoDriftCorrection = |
86 | | - EditorGUILayout.Toggle(autoDriftCorrectionLabel, cardboard.AutoDriftCorrection); |
87 | | - if (newAutoDriftCorrection != cardboard.AutoDriftCorrection) { |
88 | | - cardboard.AutoDriftCorrection = newAutoDriftCorrection; |
89 | | - } |
90 | | - |
91 | | - bool newVRModeEnabled = EditorGUILayout.Toggle(vrModeEnabledLabel, cardboard.VRModeEnabled); |
92 | | - if (newVRModeEnabled != cardboard.VRModeEnabled) { |
93 | | - cardboard.VRModeEnabled = newVRModeEnabled; |
94 | | - } |
95 | | - |
96 | | - float newNeckModelScale = EditorGUILayout.Slider(neckModelScaleLabel, |
97 | | - cardboard.NeckModelScale, 0, 1); |
98 | | - if (!Mathf.Approximately(newNeckModelScale, cardboard.NeckModelScale)) { |
99 | | - cardboard.NeckModelScale = newNeckModelScale; |
100 | | - } |
101 | | - |
102 | | - cardboard.BackButtonExitsApp = |
103 | | - EditorGUILayout.Toggle(backButtonExitsAppLabel, cardboard.BackButtonExitsApp); |
| 72 | +#if UNITY_IOS |
| 73 | + cardboard.SyncWithCardboardApp = |
| 74 | + EditorGUILayout.Toggle(syncWithCardboardLabel, cardboard.SyncWithCardboardApp); |
| 75 | +#endif |
| 76 | + cardboard.VRModeEnabled = |
| 77 | + EditorGUILayout.Toggle(vrModeLabel, cardboard.VRModeEnabled); |
| 78 | + cardboard.DistortionCorrection = |
| 79 | + EditorGUILayout.Toggle(distortionCorrectionLabel, cardboard.DistortionCorrection); |
| 80 | + cardboard.EnableAlignmentMarker = |
| 81 | + EditorGUILayout.Toggle(alignmentMarkerLabel, cardboard.EnableAlignmentMarker); |
| 82 | + cardboard.EnableSettingsButton = |
| 83 | + EditorGUILayout.Toggle(settingsButtonLabel, cardboard.EnableSettingsButton); |
| 84 | + cardboard.AutoDriftCorrection = |
| 85 | + EditorGUILayout.Toggle(autoDriftCorrectionLabel, cardboard.AutoDriftCorrection); |
| 86 | + cardboard.TapIsTrigger = |
| 87 | + EditorGUILayout.Toggle(tapIsTriggerLabel, cardboard.TapIsTrigger); |
| 88 | + cardboard.NeckModelScale = |
| 89 | + EditorGUILayout.Slider(neckModelScaleLabel, cardboard.NeckModelScale, 0, 1); |
104 | 90 |
|
105 | 91 | EditorGUILayout.Separator(); |
106 | 92 |
|
107 | 93 | EditorGUILayout.LabelField(editorSettingsLabel); |
108 | 94 |
|
109 | | - cardboard.autoUntiltHead = EditorGUILayout.Toggle(autoUntiltHeadLabel, |
110 | | - cardboard.autoUntiltHead); |
111 | | - |
| 95 | + cardboard.autoUntiltHead = |
| 96 | + EditorGUILayout.Toggle(autoUntiltHeadLabel, cardboard.autoUntiltHead); |
112 | 97 | cardboard.simulateDistortionCorrection = |
113 | 98 | EditorGUILayout.Toggle(simulateDistortionLabel, cardboard.simulateDistortionCorrection); |
114 | | - |
115 | | - cardboard.screenSize = (CardboardProfile.ScreenSizes) |
116 | | - EditorGUILayout.EnumPopup(screenSizeLabel, cardboard.screenSize); |
117 | | - |
118 | | - cardboard.deviceType = (CardboardProfile.DeviceTypes) |
119 | | - EditorGUILayout.EnumPopup(deviceTypeLabel, cardboard.deviceType); |
| 99 | + cardboard.ScreenSize = (CardboardProfile.ScreenSizes) |
| 100 | + EditorGUILayout.EnumPopup(screenSizeLabel, cardboard.ScreenSize); |
| 101 | + cardboard.DeviceType = (CardboardProfile.DeviceTypes) |
| 102 | + EditorGUILayout.EnumPopup(deviceTypeLabel, cardboard.DeviceType); |
120 | 103 |
|
121 | 104 | if (GUI.changed) { |
122 | 105 | EditorUtility.SetDirty(cardboard); |
123 | 106 | } |
| 107 | + } |
| 108 | + |
| 109 | + static CardboardEditor() { |
| 110 | + EditorUserBuildSettings.activeBuildTargetChanged += CheckGraphicsAPI; |
| 111 | + } |
| 112 | + |
| 113 | + [PostProcessBuild] |
| 114 | + public static void CheckGraphicsAPI(BuildTarget target, string path) { |
| 115 | + CheckGraphicsAPI(); |
| 116 | + } |
124 | 117 |
|
125 | | - if (EditorApplication.isPlaying) { |
126 | | - bool newInCardboard = EditorGUILayout.Toggle("Is In Cardboard", cardboard.InCardboard); |
127 | | - if (newInCardboard != cardboard.InCardboard) { |
128 | | - cardboard.SetInCardboard(newInCardboard); // Takes effect at end of frame. |
129 | | - } |
| 118 | + private static void CheckGraphicsAPI() { |
| 119 | + if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iPhone |
| 120 | + && !Application.isPlaying |
| 121 | + && Object.FindObjectOfType<Cardboard>() != null |
| 122 | + && PlayerSettings.targetIOSGraphics != TargetIOSGraphics.OpenGLES_2_0 |
| 123 | + && PlayerSettings.targetIOSGraphics != TargetIOSGraphics.OpenGLES_3_0) { |
| 124 | + Debug.LogWarning("iOS Graphics API should be set to OpenGL for best distortion-" |
| 125 | + + "correction performance in Cardboard."); |
130 | 126 | } |
131 | 127 | } |
132 | 128 | } |
0 commit comments