public static void Expose( CoherentPropertyField[] properties ) { GUILayoutOption[] emptyOptions = new GUILayoutOption[0]; EditorGUILayout.BeginVertical( emptyOptions ); foreach ( CoherentPropertyField field in properties ) { EditorGUILayout.BeginHorizontal( emptyOptions ); switch ( field.Type ) { case SerializedPropertyType.Integer: field.SetValue( EditorGUILayout.IntField( field.Name, (int)field.GetValue(), emptyOptions ) ); break; case SerializedPropertyType.Float: field.SetValue( EditorGUILayout.FloatField( field.Name, (float)field.GetValue(), emptyOptions ) ); break; case SerializedPropertyType.Boolean: field.SetValue( EditorGUILayout.Toggle( field.Name, (bool)field.GetValue(), emptyOptions ) ); break; case SerializedPropertyType.String: field.SetValue( EditorGUILayout.TextField( field.Name, (String)field.GetValue(), emptyOptions ) ); break; case SerializedPropertyType.Vector2: field.SetValue( EditorGUILayout.Vector2Field( field.Name, (Vector2)field.GetValue(), emptyOptions ) ); break; case SerializedPropertyType.Vector3: field.SetValue( EditorGUILayout.Vector3Field( field.Name, (Vector3)field.GetValue(), emptyOptions ) ); break; case SerializedPropertyType.Enum: field.SetValue(EditorGUILayout.EnumPopup(field.Name, (Enum)field.GetValue(), emptyOptions)); break; default: break; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); }
public static CoherentPropertyField[] GetProperties(System.Object obj) { List <CoherentPropertyField> fields = new List <CoherentPropertyField>(); PropertyInfo[] infos = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo info in infos) { if (!(info.CanRead && info.CanWrite)) { continue; } object[] attributes = info.GetCustomAttributes(true); bool isExposed = false; foreach (object o in attributes) { var t = o.GetType(); if (t == typeof(CoherentExposePropertyAttribute) #if UNITY_STANDALONE || t == typeof(CoherentExposePropertyStandaloneAttribute) #elif UNITY_IPHONE || UNITY_ANDROID || t == typeof(CoherentExposePropertyiOSAttribute) #endif ) { isExposed = true; break; } } if (!isExposed) { continue; } SerializedPropertyType type = SerializedPropertyType.Integer; if (CoherentPropertyField.GetPropertyType(info, out type)) { CoherentPropertyField field = new CoherentPropertyField(obj, info, type); fields.Add(field); } } return(fields.ToArray()); }
public void AddField(CoherentPropertyField f) { m_Fields.Add(f); }
public static CoherentFoldout[] GetProperties(System.Object obj) { CoherentFoldout[] foldouts = new CoherentFoldout[(int)CoherentExposePropertyInfo.FoldoutType.Count]; PropertyInfo[] infos = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo info in infos) { if (!(info.CanRead && info.CanWrite)) { continue; } object[] attributes = info.GetCustomAttributes(true); bool isExposed = false; object infoAttribute = null; foreach (object o in attributes) { var t = o.GetType(); if (t == typeof(CoherentExposePropertyAttribute) #if UNITY_STANDALONE || t == typeof(CoherentExposePropertyStandaloneAttribute) #elif UNITY_IPHONE || UNITY_ANDROID || t == typeof(CoherentExposePropertyiOSAttribute) #endif ) { infoAttribute = o; isExposed = true; break; } } if (!isExposed) { continue; } SerializedPropertyType type = SerializedPropertyType.Integer; if (CoherentPropertyField.GetPropertyType(info, out type)) { CoherentPropertyField field = new CoherentPropertyField(obj, info, type, infoAttribute); var category = CoherentExposePropertyInfo.FoldoutType.General; var attr = infoAttribute as CoherentExposePropertyInfo; if (attr != null) { category = attr.Category; } if (foldouts[(int)category] == null) { foldouts[(int)category] = new CoherentFoldout(category); } foldouts[(int)category].AddField(field); } } return(foldouts); }
public static CoherentFoldout[] GetProperties( System.Object obj ) { CoherentFoldout[] foldouts = new CoherentFoldout[(int)CoherentExposePropertyInfo.FoldoutType.Count]; PropertyInfo[] infos = obj.GetType().GetProperties( BindingFlags.Public | BindingFlags.Instance ); foreach ( PropertyInfo info in infos ) { if ( ! (info.CanRead && info.CanWrite) ) continue; object[] attributes = info.GetCustomAttributes( true ); bool isExposed = false; object infoAttribute = null; foreach( object o in attributes ) { var t = o.GetType(); if ( t == typeof( CoherentExposePropertyAttribute ) #if UNITY_STANDALONE || t == typeof(CoherentExposePropertyStandaloneAttribute) #elif UNITY_IPHONE || UNITY_ANDROID || t == typeof(CoherentExposePropertyiOSAttribute) #endif ) { infoAttribute = o; isExposed = true; break; } } if ( !isExposed ) continue; SerializedPropertyType type = SerializedPropertyType.Integer; if( CoherentPropertyField.GetPropertyType( info, out type ) ) { CoherentPropertyField field = new CoherentPropertyField( obj, info, type, infoAttribute ); var category = CoherentExposePropertyInfo.FoldoutType.General; var attr = infoAttribute as CoherentExposePropertyInfo; if(attr != null) { category = attr.Category; } if(foldouts[(int)category] == null) { foldouts[(int)category] = new CoherentFoldout(category); } foldouts[(int)category].AddField(field); } } return foldouts; }
public static CoherentPropertyField[] GetProperties( System.Object obj ) { List<CoherentPropertyField> fields = new List<CoherentPropertyField>(); PropertyInfo[] infos = obj.GetType().GetProperties( BindingFlags.Public | BindingFlags.Instance ); foreach ( PropertyInfo info in infos ) { if ( ! (info.CanRead && info.CanWrite) ) continue; object[] attributes = info.GetCustomAttributes( true ); bool isExposed = false; foreach( object o in attributes ) { var t = o.GetType(); if ( t == typeof( CoherentExposePropertyAttribute ) #if UNITY_STANDALONE || t == typeof(CoherentExposePropertyStandaloneAttribute) #elif UNITY_IPHONE || t == typeof(CoherentExposePropertyiOSAttribute) #endif ) { isExposed = true; break; } } if ( !isExposed ) continue; SerializedPropertyType type = SerializedPropertyType.Integer; if( CoherentPropertyField.GetPropertyType( info, out type ) ) { CoherentPropertyField field = new CoherentPropertyField( obj, info, type ); fields.Add( field ); } } return fields.ToArray(); }