/// <summary> /// Create ClassField from specified field. /// </summary> /// <param name="field">Field.</param> /// <returns>ClassField instance if field type is allowed; otherwise null.</returns> public static ClassField Create(FieldInfo field) { if (!IsAllowedType(field.FieldType)) { return(null); } var result = new ClassField() { FieldName = field.Name, WidgetFieldName = field.Name, FieldTypeName = Utilites.GetFriendlyTypeName(field.FieldType), FieldType = field.FieldType, }; return(result); }
/// <summary> /// Create ClassField from specified property. /// </summary> /// <param name="property">Property.</param> /// <returns>ClassField instance if property type is allowed; otherwise null.</returns> public static ClassField Create(PropertyInfo property) { if (!property.CanRead) { return(null); } if (!IsAllowedType(property.PropertyType)) { return(null); } var result = new ClassField() { FieldName = property.Name, WidgetFieldName = property.Name, FieldTypeName = Utilites.GetFriendlyTypeName(property.PropertyType), FieldType = property.PropertyType, CanRead = property.CanRead, CanWrite = property.CanWrite, }; return(result); }
/// <summary> /// Initializes a new instance of the <see cref="ClassInfo"/> class. /// </summary> /// <param name="type">Type.</param> public ClassInfo(Type type) { if (type == null) { return; } // ignore Unity objects except scriptable objects var is_unity_object = typeof(UnityEngine.Object).IsAssignableFrom(type); var is_unity_scriptable_object = typeof(ScriptableObject).IsAssignableFrom(type); if (is_unity_object && !is_unity_scriptable_object) { return; } // ignore static types if (type.IsAbstract && type.IsSealed) { return; } // ignore generic type if (type.IsGenericTypeDefinition) { return; } InfoType = type; Namespace = type.Namespace; FullTypeName = type.FullName; ShortTypeName = type.Name; InputField = typeof(UnityEngine.UI.InputField); InputText = typeof(UnityEngine.UI.Text); #if UIWIDGETS_TMPRO_SUPPORT IsTMProText = true; TextFieldType = typeof(TMPro.TextMeshProUGUI); TMProInputField = Utilites.GetType("TMPro.TMP_InputField"); IsTMProInputField = TMProInputField != null; if (IsTMProInputField) { InputField = TMProInputField; InputText = TextFieldType; } #else IsTMProText = false; TextFieldType = typeof(UnityEngine.UI.Text); TMProInputField = null; IsTMProInputField = false; #endif var prohibited_names = new HashSet <string>(); if (typeof(ScriptableObject).IsAssignableFrom(type)) { prohibited_names.Add("name"); prohibited_names.Add("hideFlags"); } foreach (var field in type.GetFields()) { if (prohibited_names.Contains(field.Name)) { continue; } var option = ClassField.Create(field); if (option != null) { Fields.Add(option); } } foreach (var property in type.GetProperties()) { if (prohibited_names.Contains(property.Name)) { continue; } var option = ClassField.Create(property); if (option != null) { Fields.Add(option); } } }