Ejemplo n.º 1
0
        public NEDataProperty(System.Object instance, FieldInfo info, NEDatapRropertyType propertyType)
        {
            m_Instance = instance;
            m_Info     = info;
            m_Type     = propertyType;
            //m_sName = ObjectNames.NicifyVariableName(m_Info.Name);
            m_sName       = m_Info.Name;
            m_bShowOnNode = false;
            var arr = m_Info.GetCustomAttributes(typeof(NEPropertyAttribute), false);

            if (arr.Length > 0)
            {
                NEPropertyAttribute propertyAttr = (NEPropertyAttribute)arr[0];
                m_sName       = propertyAttr.name;
                m_bShowOnNode = propertyAttr.showOnNode;
            }
            if (propertyType == NEDatapRropertyType.Array)
            {
                isShow = false;
            }
            else
            {
                isShow = true;
            }
        }
Ejemplo n.º 2
0
        public static bool GetPropertyType(FieldInfo info, out NEDatapRropertyType propertyType)
        {
            propertyType = NEDatapRropertyType.Generic;
            Type type = info.FieldType;

            if (type == typeof(int))
            {
                propertyType = NEDatapRropertyType.Integer;
                return(true);
            }

            if (type == typeof(float))
            {
                propertyType = NEDatapRropertyType.Float;
                return(true);
            }

            if (type == typeof(bool))
            {
                propertyType = NEDatapRropertyType.Boolean;
                return(true);
            }

            if (type == typeof(string))
            {
                propertyType = NEDatapRropertyType.String;
                return(true);
            }

            if (type == typeof(Vector2))
            {
                propertyType = NEDatapRropertyType.Vector2;
                return(true);
            }

            if (type == typeof(Vector3))
            {
                propertyType = NEDatapRropertyType.Vector3;
                return(true);
            }

            if (type.IsEnum)
            {
                propertyType = NEDatapRropertyType.Enum;
                return(true);
            }
            //只支持1维数组
            if (type.IsArray && type.GetArrayRank() == 1)
            {
                propertyType = NEDatapRropertyType.Array;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public static NEDataProperty[] GetProperties(System.Object obj)
        {
            List <NEDataProperty> properties = new List <NEDataProperty>();

            FieldInfo[] infos = obj.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
            foreach (FieldInfo info in infos)
            {
                NEDatapRropertyType type = NEDatapRropertyType.Integer;
                if (NEDataProperty.GetPropertyType(info, out type))
                {
                    NEDataProperty property = new NEDataProperty(obj, info, type);
                    properties.Add(property);
                }
            }

            return(properties.ToArray());
        }