@@ -33,6 +33,7 @@ class InspectorDrawer {
3333 public UnityEngine . Object target ;
3434 public List < IReflectorDrawer > drawer ;
3535 public bool shown ;
36+ public bool isInternalType ;
3637 public InspectorDrawer ( UnityEngine . Object target ) {
3738 this . target = target ;
3839 this . drawer = new List < IReflectorDrawer > ( ) ;
@@ -185,18 +186,102 @@ static StringBuilder JoinStringList(StringBuilder sb, IList<string> list, string
185186 return sb ;
186187 }
187188
188- internal static Quaternion QuaterionField ( string label , Quaternion value , params GUILayoutOption [ ] options ) {
189+ internal static Quaternion QuaternionField ( string label , Quaternion value , params GUILayoutOption [ ] options ) {
189190 var cValue = new Vector4 ( value . x , value . y , value . z , value . w ) ;
190191 cValue = EditorGUILayout . Vector4Field ( label , cValue , options ) ;
191192 return new Quaternion ( cValue . x , cValue . y , cValue . z , cValue . w ) ;
192193 }
193194
194- internal static Quaternion QuaterionField ( Rect position , string label , Quaternion value ) {
195+ internal static Quaternion QuaternionField ( Rect position , string label , Quaternion value ) {
195196 var cValue = new Vector4 ( value . x , value . y , value . z , value . w ) ;
196197 cValue = EditorGUI . Vector4Field ( position , label , cValue ) ;
197198 return new Quaternion ( cValue . x , cValue . y , cValue . z , cValue . w ) ;
198199 }
199200
201+ internal static int EnumField ( Rect position , string label , Type type , int value ) {
202+ string [ ] itemNames ;
203+ int [ ] itemValues ;
204+ int val = EnumFieldPreProcess ( type , value , out itemNames , out itemValues ) ;
205+ int newVal = EditorGUI . Popup ( position , label , val , itemNames ) ;
206+ return EnumFieldPostProcess ( itemValues , newVal ) ;
207+ }
208+
209+ internal static int EnumField ( string label , Type type , int value , params GUILayoutOption [ ] options ) {
210+ string [ ] itemNames ;
211+ int [ ] itemValues ;
212+ int val = EnumFieldPreProcess ( type , value , out itemNames , out itemValues ) ;
213+ int newVal = EditorGUILayout . Popup ( label , val , itemNames , options ) ;
214+ return EnumFieldPostProcess ( itemValues , newVal ) ;
215+ }
216+
217+ static int EnumFieldPreProcess ( Type type , int val , out string [ ] itemNames , out int [ ] itemValues ) {
218+ itemNames = Enum . GetNames ( type ) ;
219+ itemValues = Enum . GetValues ( type ) as int [ ] ;
220+ for ( int i = 0 ; i < itemValues . Length ; i ++ )
221+ if ( val == itemValues [ i ] )
222+ return i ;
223+ return 0 ;
224+ }
225+
226+ static int EnumFieldPostProcess ( int [ ] itemValues , int val ) {
227+ return itemValues [ val ] ;
228+ }
229+
230+
231+ internal static int MaskedEnumField ( Rect position , string label , Type type , int mask ) {
232+ return MaskedEnumField ( position , new GUIContent ( label ) , type , mask ) ;
233+ }
234+
235+ internal static int MaskedEnumField ( Rect position , GUIContent label , Type type , int mask ) {
236+ string [ ] itemNames ;
237+ int [ ] itemValues ;
238+ int val = MaskedEnumFieldPreProcess ( type , mask , out itemNames , out itemValues ) ;
239+ int newVal = EditorGUI . MaskField ( position , label , val , itemNames ) ;
240+ return MaskedEnumFieldPostProcess ( itemValues , mask , val , newVal ) ;
241+ }
242+
243+ internal static int MaskedEnumField ( string label , Type type , int mask , params GUILayoutOption [ ] options ) {
244+ return MaskedEnumField ( new GUIContent ( label ) , type , mask , options ) ;
245+ }
246+
247+ internal static int MaskedEnumField ( GUIContent label , Type type , int mask , params GUILayoutOption [ ] options ) {
248+ string [ ] itemNames ;
249+ int [ ] itemValues ;
250+ int val = MaskedEnumFieldPreProcess ( type , mask , out itemNames , out itemValues ) ;
251+ int newVal = EditorGUILayout . MaskField ( label , val , itemNames , options ) ;
252+ return MaskedEnumFieldPostProcess ( itemValues , mask , val , newVal ) ;
253+ }
254+
255+ static int MaskedEnumFieldPreProcess ( Type type , int val , out string [ ] itemNames , out int [ ] itemValues ) {
256+ itemNames = Enum . GetNames ( type ) ;
257+ itemValues = Enum . GetValues ( type ) as int [ ] ;
258+ int maskVal = 0 ;
259+ for ( int i = 0 ; i < itemValues . Length ; i ++ ) {
260+ if ( itemValues [ i ] != 0 ) {
261+ if ( ( val & itemValues [ i ] ) == itemValues [ i ] )
262+ maskVal |= 1 << i ;
263+ } else if ( val == 0 )
264+ maskVal |= 1 << i ;
265+ }
266+ return maskVal ;
267+ }
268+
269+ static int MaskedEnumFieldPostProcess ( int [ ] itemValues , int val , int maskVal , int newMaskVal ) {
270+ int changes = maskVal ^ newMaskVal ;
271+ for ( int i = 0 ; i < itemValues . Length ; i ++ )
272+ if ( ( changes & ( 1 << i ) ) != 0 ) {
273+ if ( ( newMaskVal & ( 1 << i ) ) != 0 ) {
274+ if ( itemValues [ i ] == 0 ) {
275+ val = 0 ;
276+ break ;
277+ }
278+ val |= itemValues [ i ] ;
279+ } else
280+ val &= ~ itemValues [ i ] ;
281+ }
282+ return val ;
283+ }
284+
200285 internal static bool AssignValue ( MemberInfo info , object target , object value ) {
201286 try {
202287 var fieldInfo = info as FieldInfo ;
@@ -224,7 +309,8 @@ internal static bool FetchValue(MemberInfo info, object target, out object value
224309 value = propertyInfo . GetValue ( target , null ) ;
225310 else
226311 return false ;
227- } catch {
312+ } catch ( Exception ex ) {
313+ value = ex ;
228314 return false ;
229315 }
230316 return true ;
0 commit comments