1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- using System . Collections ;
16- using UnityEditor ;
1715using UnityEngine ;
16+ using UnityEngine . Rendering ;
17+ using UnityEditor ;
1818using UnityEditor . Callbacks ;
1919
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.
2024[ CustomEditor ( typeof ( Cardboard ) ) ]
2125[ InitializeOnLoad ]
2226public 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." ) ;
2729
2830 GUIContent distortionCorrectionLabel = new GUIContent ( "Distortion Correction" ,
2931 "Whether distortion correction is performed the SDK." ) ;
3032
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
3343
3444 GUIContent alignmentMarkerLabel = new GUIContent ( "Alignment Marker" ,
3545 "Whether to draw the alignment marker. The marker is a vertical line that splits " +
@@ -40,24 +50,15 @@ public class CardboardEditor : Editor {
4050 "Google Cardboard app to allow the user to configure their individual " +
4151 "settings and Cardboard headset parameters." ) ;
4252
43- GUIContent autoDriftCorrectionLabel = new GUIContent ( "Auto Drift Correction" ,
44- "When enabled, drift in the gyro readings is estimated and removed." ) ;
45-
4653 GUIContent tapIsTriggerLabel = new GUIContent ( "Tap Is Trigger" ,
4754 "Whether screen taps are treated as trigger events." ) ;
4855
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" ,
5357 "Controls for the in-editor emulation of Cardboard." ) ;
5458
5559 GUIContent autoUntiltHeadLabel = new GUIContent ( "Auto Untilt Head" ,
5660 "When enabled, just release Ctrl to untilt the head." ) ;
5761
58- GUIContent simulateDistortionLabel = new GUIContent ( "Simulate Distortion Correction" ,
59- "Whether to perform distortion correction in the editor." ) ;
60-
6162 GUIContent screenSizeLabel = new GUIContent ( "Screen Size" ,
6263 "The screen size to emulate." ) ;
6364
@@ -67,35 +68,39 @@ public class CardboardEditor : Editor {
6768 public override void OnInspectorGUI ( ) {
6869 GUI . changed = false ;
6970
71+ GUIStyle headingStyle = new GUIStyle ( GUI . skin . label ) ;
72+ headingStyle . fontStyle = FontStyle . Bold ;
73+ headingStyle . fontSize = 14 ;
74+
7075 Cardboard cardboard = ( Cardboard ) target ;
7176
72- #if UNITY_IOS
73- cardboard . SyncWithCardboardApp =
74- EditorGUILayout . Toggle ( syncWithCardboardLabel , cardboard . SyncWithCardboardApp ) ;
75- #endif
77+ EditorGUILayout . LabelField ( "General Settings" , headingStyle ) ;
7678 cardboard . VRModeEnabled =
7779 EditorGUILayout . Toggle ( vrModeLabel , cardboard . VRModeEnabled ) ;
7880 cardboard . DistortionCorrection =
7981 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
8093 cardboard . EnableAlignmentMarker =
8194 EditorGUILayout . Toggle ( alignmentMarkerLabel , cardboard . EnableAlignmentMarker ) ;
8295 cardboard . EnableSettingsButton =
8396 EditorGUILayout . Toggle ( settingsButtonLabel , cardboard . EnableSettingsButton ) ;
84- cardboard . AutoDriftCorrection =
85- EditorGUILayout . Toggle ( autoDriftCorrectionLabel , cardboard . AutoDriftCorrection ) ;
8697 cardboard . TapIsTrigger =
8798 EditorGUILayout . Toggle ( tapIsTriggerLabel , cardboard . TapIsTrigger ) ;
88- cardboard . NeckModelScale =
89- EditorGUILayout . Slider ( neckModelScaleLabel , cardboard . NeckModelScale , 0 , 1 ) ;
90-
9199 EditorGUILayout . Separator ( ) ;
92100
93- EditorGUILayout . LabelField ( editorSettingsLabel ) ;
94-
101+ EditorGUILayout . LabelField ( editorSettingsLabel , headingStyle ) ;
95102 cardboard . autoUntiltHead =
96103 EditorGUILayout . Toggle ( autoUntiltHeadLabel , cardboard . autoUntiltHead ) ;
97- cardboard . simulateDistortionCorrection =
98- EditorGUILayout . Toggle ( simulateDistortionLabel , cardboard . simulateDistortionCorrection ) ;
99104 cardboard . ScreenSize = ( CardboardProfile . ScreenSizes )
100105 EditorGUILayout . EnumPopup ( screenSizeLabel , cardboard . ScreenSize ) ;
101106 cardboard . DeviceType = ( CardboardProfile . DeviceTypes )
@@ -116,13 +121,28 @@ public static void CheckGraphicsAPI(BuildTarget target, string path) {
116121 }
117122
118123 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
120139 && ! Application . isPlaying
121140 && 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." ) ;
126144 }
145+ #endif // UNITY_5 || UNITY_4_6 && !UNITY_4_6_1 && !UNITY_4_6_2
146+ #endif // UNITY_IOS
127147 }
128148}
0 commit comments