@@ -29,20 +29,9 @@ enum PropertyType {
2929 Array
3030 }
3131
32- class InspectorDrawer {
33- public UnityEngine . Object target ;
34- public List < IReflectorDrawer > drawer ;
35- public bool shown ;
36- public bool isInternalType ;
37- public InspectorDrawer ( UnityEngine . Object target ) {
38- this . target = target ;
39- this . drawer = new List < IReflectorDrawer > ( ) ;
40- }
41- }
42-
4332 struct ComponentMethod {
4433 public MethodInfo method ;
45- public UnityEngine . Object target ;
34+ public object target ;
4635 }
4736
4837 struct ComponentFields {
@@ -54,6 +43,7 @@ struct ComponentFields {
5443 interface IReflectorDrawer {
5544 void Draw ( ) ;
5645 bool AllowPrivateFields { get ; set ; }
46+ bool AllowObsolete { get ; set ; }
5747 bool Changed { get ; }
5848 object Value { get ; }
5949 MemberInfo Info { get ; }
@@ -62,6 +52,7 @@ interface IReflectorDrawer {
6252
6353 public static class Helper {
6454 internal static readonly Dictionary < Type , PropertyType > propertyTypeMapper = new Dictionary < Type , PropertyType > ( ) ;
55+ static double clickTime ;
6556
6657 internal static void InitPropertyTypeMapper ( ) {
6758 if ( propertyTypeMapper . Count > 0 )
@@ -114,7 +105,7 @@ internal static void ReadOnlyLabelField(string label, string value) {
114105 }
115106
116107 internal static Rect ScaleRect ( Rect source ,
117- float xScale , float yScale , float widthScale , float heightScale ,
108+ float xScale = 0 , float yScale = 0 , float widthScale = 1 , float heightScale = 1 ,
118109 float offsetX = 0 , float offsetY = 0 , float offsetWidth = 0 , float offsetHeight = 0 ) {
119110 return new Rect (
120111 source . x + source . width * xScale + offsetX ,
@@ -282,6 +273,103 @@ static int MaskedEnumFieldPostProcess(int[] itemValues, int val, int maskVal, in
282273 return val ;
283274 }
284275
276+ internal static string StringField ( string label , string value , bool readOnly , params GUILayoutOption [ ] options ) {
277+ int lines = CountLines ( value ) ;
278+ if ( lines > 1 ) {
279+ var _opts = options . ToList ( ) ;
280+ _opts . Add ( GUILayout . Height ( EditorGUIUtility . singleLineHeight * lines ) ) ;
281+ _opts . Add ( GUILayout . MaxWidth ( EditorGUIUtility . currentViewWidth ) ) ;
282+ EditorGUILayout . BeginVertical ( ) ;
283+ EditorGUILayout . PrefixLabel ( label ) ;
284+ if ( readOnly )
285+ EditorGUILayout . SelectableLabel ( value , EditorStyles . textArea , _opts . ToArray ( ) ) ;
286+ else
287+ value = EditorGUILayout . TextArea ( value , _opts . ToArray ( ) ) ;
288+ EditorGUILayout . EndVertical ( ) ;
289+ } else {
290+ if ( readOnly ) {
291+ var _opts = options . ToList ( ) ;
292+ _opts . Add ( GUILayout . Height ( EditorGUIUtility . singleLineHeight ) ) ;
293+ EditorGUILayout . BeginHorizontal ( ) ;
294+ EditorGUILayout . PrefixLabel ( label ) ;
295+ EditorGUILayout . SelectableLabel ( value , EditorStyles . textField , _opts . ToArray ( ) ) ;
296+ EditorGUILayout . EndHorizontal ( ) ;
297+ } else
298+ value = EditorGUILayout . TextField ( label , value , options ) ;
299+ }
300+ return value ;
301+ }
302+
303+ internal static string StringField ( Rect position , string label , string value , bool readOnly ) {
304+ if ( readOnly ) {
305+ EditorGUI . SelectableLabel ( position , value ) ;
306+ } else {
307+ int lines = position . height <= EditorGUIUtility . singleLineHeight ? 1 : CountLines ( value ) ;
308+ if ( lines > 1 )
309+ EditorGUI . PrefixLabel ( ScaleRect ( position , heightScale : 0 , offsetHeight : EditorGUIUtility . singleLineHeight ) , new GUIContent ( label ) ) ;
310+ value = lines > 1 ?
311+ EditorGUI . TextArea ( ScaleRect ( position , offsetY : EditorGUIUtility . singleLineHeight , offsetHeight : - EditorGUIUtility . singleLineHeight ) , value ) :
312+ EditorGUI . TextField ( position , label , value ) ;
313+ }
314+ return value ;
315+ }
316+
317+ internal static UnityEngine . Object ObjectField ( string label , UnityEngine . Object value , Type objectType , bool allowScreenObjs , bool readOnly , params GUILayoutOption [ ] options ) {
318+ if ( ! readOnly )
319+ return EditorGUILayout . ObjectField ( label , value , objectType , allowScreenObjs , options ) ;
320+ EditorGUILayout . BeginHorizontal ( ) ;
321+ EditorGUILayout . PrefixLabel ( label ) ;
322+ var _opts = options . ToList ( ) ;
323+ _opts . Add ( GUILayout . Height ( EditorGUIUtility . singleLineHeight ) ) ;
324+ if ( GUILayout . Button ( EditorGUIUtility . ObjectContent ( value , objectType ) , EditorStyles . objectField , _opts . ToArray ( ) ) )
325+ ClickObject ( value ) ;
326+ EditorGUILayout . EndHorizontal ( ) ;
327+ return value ;
328+ }
329+
330+ internal static UnityEngine . Object ObjectField ( Rect position , string label , UnityEngine . Object value , Type objectType , bool allowScreenObjs , bool readOnly ) {
331+ if ( ! readOnly )
332+ return EditorGUI . ObjectField ( position , label , value , objectType , allowScreenObjs ) ;
333+ EditorGUI . PrefixLabel ( ScaleRect ( position , widthScale : 0.5F ) , new GUIContent ( label ) ) ;
334+ if ( GUI . Button ( ScaleRect ( position , 0.5F , widthScale : 0.5F ) , EditorGUIUtility . ObjectContent ( value , objectType ) , EditorStyles . objectField ) )
335+ ClickObject ( value ) ;
336+ return value ;
337+ }
338+
339+ static void ClickObject ( UnityEngine . Object obj ) {
340+ var newClickTime = EditorApplication . timeSinceStartup ;
341+ if ( newClickTime - clickTime < 0.3 && obj != null )
342+ Selection . activeObject = obj ;
343+ clickTime = newClickTime ;
344+ EditorGUIUtility . PingObject ( obj ) ;
345+ }
346+
347+ static int CountLines ( string str ) {
348+ if ( string . IsNullOrEmpty ( str ) )
349+ return 1 ;
350+ int cursor = 0 , count = 0 , length = str . Length , i = - 1 ;
351+ bool isCR = false ;
352+ while ( cursor < length ) {
353+ i = str . IndexOf ( '\r ' , cursor ) ;
354+ if ( i >= 0 ) {
355+ count ++ ;
356+ isCR = true ;
357+ cursor = i + 1 ;
358+ continue ;
359+ }
360+ i = str . IndexOf ( '\n ' , cursor ) ;
361+ if ( i >= 0 ) {
362+ if ( ! isCR || i != 0 )
363+ count ++ ;
364+ isCR = false ;
365+ cursor = i + 1 ;
366+ continue ;
367+ }
368+ break ;
369+ }
370+ return Math . Max ( 1 , count ) ;
371+ }
372+
285373 internal static bool AssignValue ( MemberInfo info , object target , object value ) {
286374 try {
287375 var fieldInfo = info as FieldInfo ;
@@ -298,6 +386,16 @@ internal static bool AssignValue(MemberInfo info, object target, object value) {
298386 return true ;
299387 }
300388
389+ internal static bool IsReadOnly ( MemberInfo info ) {
390+ var fieldInfo = info as FieldInfo ;
391+ if ( fieldInfo != null )
392+ return fieldInfo . IsInitOnly || fieldInfo . IsLiteral ;
393+ var propertyInfo = info as PropertyInfo ;
394+ if ( propertyInfo != null )
395+ return ! propertyInfo . CanWrite ;
396+ return false ;
397+ }
398+
301399 internal static bool FetchValue ( MemberInfo info , object target , out object value ) {
302400 value = null ;
303401 try {
@@ -316,6 +414,19 @@ internal static bool FetchValue(MemberInfo info, object target, out object value
316414 return true ;
317415 }
318416
417+ internal static int ObjIdOrHashCode ( object obj ) {
418+ var unityObj = obj as UnityEngine . Object ;
419+ if ( unityObj != null )
420+ return unityObj . GetInstanceID ( ) ;
421+ if ( obj != null )
422+ return obj . GetHashCode ( ) ;
423+ return 0 ;
424+ }
425+
426+ internal static GUIStyle GetGUIStyle ( string styleName ) {
427+ return GUI . skin . FindStyle ( styleName ) ?? EditorGUIUtility . GetBuiltinSkin ( EditorSkin . Inspector ) . FindStyle ( styleName ) ;
428+ }
429+
319430 [ MenuItem ( "Window/Script Tester/Inspector+" ) ]
320431 public static void ShowInspectorPlus ( ) {
321432 EditorWindow . GetWindow ( typeof ( InspectorPlus ) ) ;
0 commit comments