Example #1
0
        /// <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);
                }
            }
        }