11using UnityEngine ;
22using UnityEditor ;
33using System ;
4+ using System . Collections ;
45using System . Collections . Generic ;
56using System . Reflection ;
67using System . Linq ;
@@ -18,6 +19,7 @@ enum PropertyType {
1819 Vector2 ,
1920 Vector3 ,
2021 Vector4 ,
22+ Quaterion ,
2123 Color ,
2224 Rect ,
2325 Bounds ,
@@ -57,10 +59,10 @@ interface IReflectorDrawer {
5759 event Action OnRequireRedraw ;
5860 }
5961
60- static class Helper {
61- public static readonly Dictionary < Type , PropertyType > propertyTypeMapper = new Dictionary < Type , PropertyType > ( ) ;
62+ public static class Helper {
63+ internal static readonly Dictionary < Type , PropertyType > propertyTypeMapper = new Dictionary < Type , PropertyType > ( ) ;
6264
63- public static void InitPropertyTypeMapper ( ) {
65+ internal static void InitPropertyTypeMapper ( ) {
6466 if ( propertyTypeMapper . Count > 0 )
6567 return ;
6668 propertyTypeMapper . Add ( typeof ( string ) , PropertyType . String ) ;
@@ -78,15 +80,29 @@ public static void InitPropertyTypeMapper() {
7880 propertyTypeMapper . Add ( typeof ( Vector2 ) , PropertyType . Vector2 ) ;
7981 propertyTypeMapper . Add ( typeof ( Vector3 ) , PropertyType . Vector3 ) ;
8082 propertyTypeMapper . Add ( typeof ( Vector4 ) , PropertyType . Vector4 ) ;
83+ propertyTypeMapper . Add ( typeof ( Quaternion ) , PropertyType . Quaterion ) ;
8184 propertyTypeMapper . Add ( typeof ( Color ) , PropertyType . Color ) ;
8285 propertyTypeMapper . Add ( typeof ( Rect ) , PropertyType . Rect ) ;
8386 propertyTypeMapper . Add ( typeof ( Bounds ) , PropertyType . Bounds ) ;
8487 propertyTypeMapper . Add ( typeof ( AnimationCurve ) , PropertyType . Curve ) ;
8588 propertyTypeMapper . Add ( typeof ( UnityEngine . Object ) , PropertyType . Object ) ;
8689 propertyTypeMapper . Add ( typeof ( Array ) , PropertyType . Array ) ;
8790 }
91+
92+ static readonly Hashtable storedState = new Hashtable ( ) ;
93+
94+ internal static void StoreState ( object key , object value ) {
95+ if ( storedState . ContainsKey ( key ) )
96+ storedState [ key ] = value ;
97+ else
98+ storedState . Add ( key , value ) ;
99+ }
100+
101+ internal static T GetState < T > ( object key , T defaultValue = default ( T ) ) {
102+ return storedState . ContainsKey ( key ) ? ( T ) storedState [ key ] : defaultValue ;
103+ }
88104
89- public static void ReadOnlyLabelField ( string label , string value ) {
105+ internal static void ReadOnlyLabelField ( string label , string value ) {
90106 if ( value . Contains ( '\r ' ) || value . Contains ( '\n ' ) ) {
91107 EditorGUILayout . PrefixLabel ( label ) ;
92108 EditorGUILayout . SelectableLabel ( value , EditorStyles . textArea ) ;
@@ -96,7 +112,7 @@ public static void ReadOnlyLabelField(string label, string value) {
96112 }
97113 }
98114
99- public static Rect ScaleRect ( Rect source ,
115+ internal static Rect ScaleRect ( Rect source ,
100116 float xScale , float yScale , float widthScale , float heightScale ,
101117 float offsetX = 0 , float offsetY = 0 , float offsetWidth = 0 , float offsetHeight = 0 ) {
102118 return new Rect (
@@ -107,63 +123,85 @@ public static Rect ScaleRect(Rect source,
107123 ) ;
108124 }
109125
110- public static string GetMemberName ( MemberInfo member ) {
126+ internal static string GetMemberName ( MemberInfo member , bool simplifed = false ) {
111127 var ret = new StringBuilder ( ) ;
112128 var props = new List < string > ( ) ;
113129 var field = member as FieldInfo ;
114130 var property = member as PropertyInfo ;
115131 var method = member as MethodInfo ;
116132 if ( field != null ) {
117133 if ( ! field . IsPublic )
118- props . Add ( "Private" ) ;
134+ props . Add ( simplifed ? "P" : "Private" ) ;
119135 if ( field . IsStatic )
120- props . Add ( "Static" ) ;
136+ props . Add ( simplifed ? "S" : "Static" ) ;
137+ if ( field . IsInitOnly )
138+ props . Add ( simplifed ? "R" : "Read Only" ) ;
139+ if ( field . IsLiteral )
140+ props . Add ( simplifed ? "C" : "Constant" ) ;
121141 } else if ( method != null ) {
122142 if ( ! method . IsPublic )
123- props . Add ( "Private" ) ;
143+ props . Add ( simplifed ? "P" : "Private" ) ;
124144 if ( method . IsStatic )
125- props . Add ( "Static" ) ;
145+ props . Add ( simplifed ? "S" : "Static" ) ;
126146 } else if ( property != null ) {
147+ if ( property . CanRead && property . CanWrite )
148+ props . Add ( simplifed ? "RW" : "Read Write" ) ;
127149 if ( property . CanRead && ( method = property . GetGetMethod ( ) ) != null ) {
150+ if ( ! property . CanWrite )
151+ props . Add ( simplifed ? "R" : "Read Only" ) ;
128152 if ( ! method . IsPublic )
129- props . Add ( "Private Get" ) ;
153+ props . Add ( simplifed ? "Pg" : "Private Get" ) ;
130154 if ( method . IsStatic )
131- props . Add ( "Static Get" ) ;
155+ props . Add ( simplifed ? "Sg" : "Static Get" ) ;
132156 }
133157 if ( property . CanWrite && ( method = property . GetSetMethod ( ) ) != null ) {
158+ if ( ! property . CanRead )
159+ props . Add ( simplifed ? "W" : "Write Only" ) ;
134160 if ( ! method . IsPublic )
135- props . Add ( "Private Set" ) ;
161+ props . Add ( simplifed ? "Ps" : "Private Set" ) ;
136162 if ( method . IsStatic )
137- props . Add ( "Static Set" ) ;
163+ props . Add ( simplifed ? "Ss" : "Static Set" ) ;
138164 }
139165 }
140166 if ( props . Count > 0 )
141167 ret . Append ( "(" ) ;
142- JoinStringList ( ret , props ) ;
168+ JoinStringList ( ret , props , simplifed ? "" : ", " ) ;
143169 if ( props . Count > 0 )
144170 ret . Append ( ") " ) ;
145171 ret . Append ( member . Name ) ;
146172 return ret . ToString ( ) ;
147173 }
148174
149- static StringBuilder JoinStringList ( StringBuilder sb , IList < string > list ) {
175+ static StringBuilder JoinStringList ( StringBuilder sb , IList < string > list , string separator ) {
150176 if ( sb == null )
151177 sb = new StringBuilder ( ) ;
152178 bool nonFirst = false ;
153179 foreach ( var item in list ) {
154180 if ( nonFirst )
155- sb . Append ( ", " ) ;
181+ sb . Append ( separator ) ;
156182 sb . Append ( item ) ;
157183 nonFirst = true ;
158184 }
159185 return sb ;
160186 }
161187
162- public static bool AssignValue ( MemberInfo info , object target , object value ) {
188+ internal static Quaternion QuaterionField ( string label , Quaternion value , params GUILayoutOption [ ] options ) {
189+ var cValue = new Vector4 ( value . x , value . y , value . z , value . w ) ;
190+ cValue = EditorGUILayout . Vector4Field ( label , cValue , options ) ;
191+ return new Quaternion ( cValue . x , cValue . y , cValue . z , cValue . w ) ;
192+ }
193+
194+ internal static Quaternion QuaterionField ( Rect position , string label , Quaternion value ) {
195+ var cValue = new Vector4 ( value . x , value . y , value . z , value . w ) ;
196+ cValue = EditorGUI . Vector4Field ( position , label , cValue ) ;
197+ return new Quaternion ( cValue . x , cValue . y , cValue . z , cValue . w ) ;
198+ }
199+
200+ internal static bool AssignValue ( MemberInfo info , object target , object value ) {
163201 try {
164202 var fieldInfo = info as FieldInfo ;
165203 var propertyInfo = info as PropertyInfo ;
166- if ( fieldInfo != null )
204+ if ( fieldInfo != null && ! fieldInfo . IsInitOnly && ! fieldInfo . IsLiteral )
167205 fieldInfo . SetValue ( target , value ) ;
168206 else if ( propertyInfo != null && propertyInfo . CanWrite )
169207 propertyInfo . SetValue ( target , value , null ) ;
@@ -175,7 +213,7 @@ public static bool AssignValue(MemberInfo info, object target, object value) {
175213 return true ;
176214 }
177215
178- public static bool FetchValue ( MemberInfo info , object target , out object value ) {
216+ internal static bool FetchValue ( MemberInfo info , object target , out object value ) {
179217 value = null ;
180218 try {
181219 var fieldInfo = info as FieldInfo ;
@@ -191,5 +229,15 @@ public static bool FetchValue(MemberInfo info, object target, out object value)
191229 }
192230 return true ;
193231 }
232+
233+ [ MenuItem ( "Window/Script Tester/Inspector+" ) ]
234+ public static void ShowInspectorPlus ( ) {
235+ EditorWindow . GetWindow ( typeof ( InspectorPlus ) ) ;
236+ }
237+
238+ [ MenuItem ( "Window/Script Tester/Method Caller" ) ]
239+ public static void ShowMethodCaller ( ) {
240+ EditorWindow . GetWindow ( typeof ( TestingScript ) ) ;
241+ }
194242 }
195243}
0 commit comments