12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- using System . Collections ;
16
- using UnityEditor ;
17
15
using UnityEngine ;
16
+ using UnityEngine . Rendering ;
17
+ using UnityEditor ;
18
18
using UnityEditor . Callbacks ;
19
19
20
+ /// @ingroup EditorScripts
21
+ /// A custom editor for properties on the Cardboard script. This appears in the
22
+ /// Inspector window of a Cardboard object. Its purpose is to allow changing the
23
+ /// `Cardboard.SDK` object's properties from their default values.
20
24
[ CustomEditor ( typeof ( Cardboard ) ) ]
21
25
[ InitializeOnLoad ]
22
26
public class CardboardEditor : Editor {
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
+ GUIContent vrModeLabel = new GUIContent ( "VR Mode Enabled" ,
28
+ "Sets whether VR mode is enabled." ) ;
27
29
28
30
GUIContent distortionCorrectionLabel = new GUIContent ( "Distortion Correction" ,
29
31
"Whether distortion correction is performed the SDK." ) ;
30
32
31
- GUIContent vrModeLabel = new GUIContent ( "VR Mode Enabled" ,
32
- "Sets whether VR mode is enabled." ) ;
33
+ GUIContent autoDriftCorrectionLabel = new GUIContent ( "Auto Drift Correction" ,
34
+ "When enabled, drift in the gyro readings is estimated and removed." ) ;
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." ) ;
38
+
39
+ #if UNITY_IOS
40
+ GUIContent syncWithCardboardLabel = new GUIContent ( "Sync with Cardboard App" ,
41
+ "Enables the 'Sync with Google Cardboard' slider in the viewer settings dialog." ) ;
42
+ #endif
33
43
34
44
GUIContent alignmentMarkerLabel = new GUIContent ( "Alignment Marker" ,
35
45
"Whether to draw the alignment marker. The marker is a vertical line that splits " +
@@ -40,24 +50,15 @@ public class CardboardEditor : Editor {
40
50
"Google Cardboard app to allow the user to configure their individual " +
41
51
"settings and Cardboard headset parameters." ) ;
42
52
43
- GUIContent autoDriftCorrectionLabel = new GUIContent ( "Auto Drift Correction" ,
44
- "When enabled, drift in the gyro readings is estimated and removed." ) ;
45
-
46
53
GUIContent tapIsTriggerLabel = new GUIContent ( "Tap Is Trigger" ,
47
54
"Whether screen taps are treated as trigger events." ) ;
48
55
49
- GUIContent neckModelScaleLabel = new GUIContent ( "Neck Model Scale" ,
50
- "The scale factor of the builtin neck model [0..1]. To disable, set to 0." ) ;
51
-
52
- GUIContent editorSettingsLabel = new GUIContent ( "Editor Mock Settings" ,
56
+ GUIContent editorSettingsLabel = new GUIContent ( "Unity Editor Emulation Settings" ,
53
57
"Controls for the in-editor emulation of Cardboard." ) ;
54
58
55
59
GUIContent autoUntiltHeadLabel = new GUIContent ( "Auto Untilt Head" ,
56
60
"When enabled, just release Ctrl to untilt the head." ) ;
57
61
58
- GUIContent simulateDistortionLabel = new GUIContent ( "Simulate Distortion Correction" ,
59
- "Whether to perform distortion correction in the editor." ) ;
60
-
61
62
GUIContent screenSizeLabel = new GUIContent ( "Screen Size" ,
62
63
"The screen size to emulate." ) ;
63
64
@@ -67,35 +68,39 @@ public class CardboardEditor : Editor {
67
68
public override void OnInspectorGUI ( ) {
68
69
GUI . changed = false ;
69
70
71
+ GUIStyle headingStyle = new GUIStyle ( GUI . skin . label ) ;
72
+ headingStyle . fontStyle = FontStyle . Bold ;
73
+ headingStyle . fontSize = 14 ;
74
+
70
75
Cardboard cardboard = ( Cardboard ) target ;
71
76
72
- #if UNITY_IOS
73
- cardboard . SyncWithCardboardApp =
74
- EditorGUILayout . Toggle ( syncWithCardboardLabel , cardboard . SyncWithCardboardApp ) ;
75
- #endif
77
+ EditorGUILayout . LabelField ( "General Settings" , headingStyle ) ;
76
78
cardboard . VRModeEnabled =
77
79
EditorGUILayout . Toggle ( vrModeLabel , cardboard . VRModeEnabled ) ;
78
80
cardboard . DistortionCorrection =
79
81
EditorGUILayout . Toggle ( distortionCorrectionLabel , cardboard . DistortionCorrection ) ;
82
+ cardboard . AutoDriftCorrection =
83
+ EditorGUILayout . Toggle ( autoDriftCorrectionLabel , cardboard . AutoDriftCorrection ) ;
84
+ cardboard . NeckModelScale =
85
+ EditorGUILayout . Slider ( neckModelScaleLabel , cardboard . NeckModelScale , 0 , 1 ) ;
86
+ EditorGUILayout . Separator ( ) ;
87
+
88
+ EditorGUILayout . LabelField ( "Cardboard Settings" , headingStyle ) ;
89
+ #if UNITY_IOS
90
+ cardboard . SyncWithCardboardApp =
91
+ EditorGUILayout . Toggle ( syncWithCardboardLabel , cardboard . SyncWithCardboardApp ) ;
92
+ #endif
80
93
cardboard . EnableAlignmentMarker =
81
94
EditorGUILayout . Toggle ( alignmentMarkerLabel , cardboard . EnableAlignmentMarker ) ;
82
95
cardboard . EnableSettingsButton =
83
96
EditorGUILayout . Toggle ( settingsButtonLabel , cardboard . EnableSettingsButton ) ;
84
- cardboard . AutoDriftCorrection =
85
- EditorGUILayout . Toggle ( autoDriftCorrectionLabel , cardboard . AutoDriftCorrection ) ;
86
97
cardboard . TapIsTrigger =
87
98
EditorGUILayout . Toggle ( tapIsTriggerLabel , cardboard . TapIsTrigger ) ;
88
- cardboard . NeckModelScale =
89
- EditorGUILayout . Slider ( neckModelScaleLabel , cardboard . NeckModelScale , 0 , 1 ) ;
90
-
91
99
EditorGUILayout . Separator ( ) ;
92
100
93
- EditorGUILayout . LabelField ( editorSettingsLabel ) ;
94
-
101
+ EditorGUILayout . LabelField ( editorSettingsLabel , headingStyle ) ;
95
102
cardboard . autoUntiltHead =
96
103
EditorGUILayout . Toggle ( autoUntiltHeadLabel , cardboard . autoUntiltHead ) ;
97
- cardboard . simulateDistortionCorrection =
98
- EditorGUILayout . Toggle ( simulateDistortionLabel , cardboard . simulateDistortionCorrection ) ;
99
104
cardboard . ScreenSize = ( CardboardProfile . ScreenSizes )
100
105
EditorGUILayout . EnumPopup ( screenSizeLabel , cardboard . ScreenSize ) ;
101
106
cardboard . DeviceType = ( CardboardProfile . DeviceTypes )
@@ -116,13 +121,28 @@ public static void CheckGraphicsAPI(BuildTarget target, string path) {
116
121
}
117
122
118
123
private static void CheckGraphicsAPI ( ) {
119
- if ( EditorUserBuildSettings . activeBuildTarget == BuildTarget . iPhone
124
+ #if UNITY_IOS
125
+ #if UNITY_5 || UNITY_4_6 && ! UNITY_4_6_1 && ! UNITY_4_6_2
126
+ #if UNITY_5
127
+ var iOSBuildTarget = BuildTarget . iOS ;
128
+ var iOSGraphicsAPIs = PlayerSettings . GetGraphicsAPIs ( BuildTarget . iOS ) ;
129
+ bool isOpenGL = true ;
130
+ foreach ( var device in iOSGraphicsAPIs ) {
131
+ isOpenGL &= ( device == GraphicsDeviceType . OpenGLES2 || device == GraphicsDeviceType . OpenGLES3 ) ;
132
+ }
133
+ #else
134
+ var iOSBuildTarget = BuildTarget . iPhone ;
135
+ bool isOpenGL = PlayerSettings . targetIOSGraphics == TargetIOSGraphics . OpenGLES_2_0
136
+ || PlayerSettings . targetIOSGraphics == TargetIOSGraphics . OpenGLES_3_0 ;
137
+ #endif // UNITY_5
138
+ if ( EditorUserBuildSettings . activeBuildTarget == iOSBuildTarget
120
139
&& ! Application . isPlaying
121
140
&& 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." ) ;
141
+ && ! isOpenGL ) {
142
+ Debug . LogWarning ( "iOS Graphics API should be set to OpenGL for best " +
143
+ "distortion-correction performance in Cardboard." ) ;
126
144
}
145
+ #endif // UNITY_5 || UNITY_4_6 && !UNITY_4_6_1 && !UNITY_4_6_2
146
+ #endif // UNITY_IOS
127
147
}
128
148
}
0 commit comments