@@ -241,7 +241,7 @@ internal static Quaternion QuaternionField(string label, Quaternion value, param
241241 GUI . changed = false ;
242242 cValue = EditorGUILayout . Vector4Field ( label , cValue , options ) ;
243243 if ( GUI . changed ) return new Quaternion ( cValue . x , cValue . y , cValue . z , cValue . w ) ;
244- GUI . changed = changed ;
244+ if ( changed ) GUI . changed = true ;
245245 return value ;
246246 }
247247
@@ -250,86 +250,31 @@ internal static Quaternion QuaternionField(Rect position, string label, Quaterni
250250 var changed = GUI . changed ;
251251 GUI . changed = false ;
252252 cValue = EditorGUI . Vector4Field ( position , label , cValue ) ;
253- if ( GUI . changed ) return new Quaternion ( cValue . x , cValue . y , cValue . z , cValue . w ) ;
254- GUI . changed = changed ;
253+ if ( GUI . changed ) return new Quaternion ( cValue . x , cValue . y , cValue . z , cValue . w ) . normalized ;
254+ if ( changed ) GUI . changed = true ;
255255 return value ;
256256 }
257257
258- internal static object EnumField ( Rect position , GUIContent label , Type type , object value ) {
259- int val = EnumFieldPreProcess ( type , value , out var itemNames , out var itemValues ) ;
260- int newVal = EditorGUI . Popup ( position , label , val , itemNames ) ;
261- return EnumFieldPostProcess ( itemValues , newVal ) ;
262- }
263-
264- internal static object EnumField ( GUIContent label , Type type , object value , params GUILayoutOption [ ] options ) {
265- int val = EnumFieldPreProcess ( type , value , out var itemNames , out var itemValues ) ;
266- int newVal = EditorGUILayout . Popup ( label , val , itemNames , options ) ;
267- return EnumFieldPostProcess ( itemValues , newVal ) ;
268- }
269-
270- private static int EnumFieldPreProcess ( Type type , object rawValue , out GUIContent [ ] itemNames , out Array itemValues ) {
271- itemNames = Array . ConvertAll ( Enum . GetNames ( type ) , x => new GUIContent ( x ) ) ;
272- itemValues = Enum . GetValues ( type ) ;
273- long val = Convert . ToInt64 ( rawValue ) ;
274- for ( int i = 0 ; i < itemValues . Length ; i ++ )
275- if ( Convert . ToInt64 ( itemValues . GetValue ( i ) ) == val )
276- return i ;
277- return 0 ;
278- }
279-
280- private static object EnumFieldPostProcess ( Array itemValues , int val ) => itemValues . GetValue ( val ) ;
281-
282- internal static object MaskedEnumField ( Rect position , string label , Type type , object mask ) =>
283- MaskedEnumField ( position , new GUIContent ( label ) , type , mask ) ;
284-
285- internal static object MaskedEnumField ( Rect position , GUIContent label , Type type , object mask ) {
286- int val = MaskedEnumFieldPreProcess ( type , mask , out var itemNames , out var itemValues ) ;
287- int newVal = EditorGUI . MaskField ( position , label , val , itemNames ) ;
288- return MaskedEnumFieldPostProcess ( type , itemValues , mask , val , newVal ) ;
289- }
290-
291- internal static object MaskedEnumField ( string label , Type type , object mask , params GUILayoutOption [ ] options ) =>
292- MaskedEnumField ( new GUIContent ( label ) , type , mask , options ) ;
293-
294- internal static object MaskedEnumField ( GUIContent label , Type type , object mask , params GUILayoutOption [ ] options ) {
295- int val = MaskedEnumFieldPreProcess ( type , mask , out var itemNames , out var itemValues ) ;
296- int newVal = EditorGUILayout . MaskField ( label , val , itemNames , options ) ;
297- return MaskedEnumFieldPostProcess ( type , itemValues , mask , val , newVal ) ;
258+ internal static Quaternion EulerField ( string label , Quaternion value , params GUILayoutOption [ ] options ) {
259+ var cValue = value . eulerAngles ;
260+ var changed = GUI . changed ;
261+ GUI . changed = false ;
262+ cValue = EditorGUILayout . Vector3Field ( label , cValue , options ) ;
263+ if ( GUI . changed ) return Quaternion . Euler ( cValue ) ;
264+ if ( changed ) GUI . changed = true ;
265+ return value ;
298266 }
299267
300- private static int MaskedEnumFieldPreProcess ( Type type , object rawValue , out string [ ] itemNames , out Array itemValues ) {
301- itemNames = Enum . GetNames ( type ) ;
302- itemValues = Enum . GetValues ( type ) ;
303- int maskVal = 0 ;
304- long value = Convert . ToInt64 ( rawValue ) , itemValue ;
305- for ( int i = 0 ; i < itemValues . Length ; i ++ ) {
306- itemValue = Convert . ToInt64 ( itemValues . GetValue ( i ) ) ;
307- if ( itemValue != 0 ) {
308- if ( ( value & itemValue ) != 0 )
309- maskVal |= 1 << i ;
310- } else if ( value == 0 )
311- maskVal |= 1 << i ;
312- }
313- return maskVal ;
268+ internal static Quaternion EulerField ( Rect position , string label , Quaternion value ) {
269+ var cValue = value . eulerAngles ;
270+ var changed = GUI . changed ;
271+ GUI . changed = false ;
272+ cValue = EditorGUI . Vector3Field ( position , label , cValue ) ;
273+ if ( GUI . changed ) return Quaternion . Euler ( cValue ) ;
274+ if ( changed ) GUI . changed = true ;
275+ return value ;
314276 }
315277
316- private static object MaskedEnumFieldPostProcess ( Type enumType , Array itemValues , object rawValue , int maskVal , int newMaskVal ) {
317- int changes = maskVal ^ newMaskVal ;
318- long value = Convert . ToInt64 ( rawValue ) , itemValue ;
319- for ( int i = 0 ; i < itemValues . Length ; i ++ )
320- if ( ( changes & ( 1 << i ) ) != 0 ) {
321- itemValue = Convert . ToInt64 ( itemValues . GetValue ( i ) ) ;
322- if ( ( newMaskVal & ( 1 << i ) ) != 0 ) {
323- if ( itemValue == 0 ) {
324- value = 0 ;
325- break ;
326- }
327- value |= itemValue ;
328- } else
329- value &= ~ itemValue ;
330- }
331- return Enum . ToObject ( enumType , value ) ;
332- }
333278
334279 internal static string StringField ( GUIContent label , string value , bool readOnly , params GUILayoutOption [ ] options ) {
335280 int length = value == null ? 0 : value . Length ;
0 commit comments