示例#1
0
        /** メンバーリスト。取得。
         *
         *      継承元を含む。
         *
         */
        public static void GetMemberListAll(System.Type a_type, System.Collections.Generic.List <System.Reflection.FieldInfo> a_out_list)
        {
            try{
                System.Type t_type = a_type;
                while (true)
                {
                    //終端チェック。
                    if (t_type == null)
                    {
                        break;
                    }
                    else if (t_type == typeof(System.Object))
                    {
                        break;
                    }
                    else if (t_type == typeof(UnityEngine.Object))
                    {
                        break;
                    }

                    //メンバーリスト。
                    System.Reflection.MemberInfo[] t_memberinfo_list = Fee.ReflectionTool.Utility.GetMemberList(t_type);
                    foreach (System.Reflection.MemberInfo t_memberinfo in t_memberinfo_list)
                    {
                        if (t_memberinfo.MemberType == System.Reflection.MemberTypes.Field)
                        {
                            System.Reflection.FieldInfo t_fieldinfo = t_memberinfo as System.Reflection.FieldInfo;
                            if (t_fieldinfo != null)
                            {
                                //オブジェクト化しない。Json文字列化しない。
                                if (t_fieldinfo.IsDefined(typeof(Fee.JsonItem.Ignore), false) == true)
                                {
                                    continue;
                                }

                                //オブジェクト化しない。Json文字列化しない。
                                System.Type t_field_type = t_fieldinfo.FieldType;
                                if ((t_field_type == typeof(System.IntPtr)) || (t_field_type == typeof(System.UIntPtr)))
                                {
                                    continue;
                                }

                                a_out_list.Add(t_fieldinfo);
                            }
                        }
                    }

                    //次の継承元へ。
                    t_type = t_type.BaseType;
                }
            }catch (System.Exception t_exception) {
                Tool.DebugReThrow(t_exception);
            }
        }
        public static Component CopyComponent(this GameObject destination, Component original)
        {
            System.Type type = original.GetType();
            Component   copy = destination.AddComponent(type);

            System.Reflection.FieldInfo[] fields = type.GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            for (int x = 0; x < fields.Length; x++)
            {
                System.Reflection.FieldInfo field = fields[x];

                if (field.IsDefined(typeof(SerializeField), false))
                {
                    field.SetValue(copy, field.GetValue(original));
                }
            }
            return(copy);
        }
示例#3
0
        public virtual void DrawNodeInspectorGUI()
        {
            NodeComment = UnityEditor.EditorGUILayout.TextField("NodeComment", NodeComment);
            BTHelper.DrawSeparator();
            if (!AutoDrawNodeInspector)
            {
                return;
            }
            System.Reflection.FieldInfo[] fields = GetType().GetFields();
            for (int i = 0; i < fields.Length; i++)
            {
                System.Reflection.FieldInfo field = fields[i];
                if (field.IsDefined(typeof(NodeVariable), false))
                {
                    object v = field.GetValue(this);
                    Type   t = field.FieldType;

                    if (t.BaseType == typeof(Enum))
                    {
                        v = UnityEditor.EditorGUILayout.EnumPopup(field.Name, (Enum)v);
                    }
                    else if (t == typeof(int))
                    {
                        v = UnityEditor.EditorGUILayout.IntField(field.Name, (int)v);
                    }
                    else if (t == typeof(bool))
                    {
                        v = UnityEditor.EditorGUILayout.Toggle(field.Name, (bool)v);
                    }
                    else if (t == typeof(float))
                    {
                        v = UnityEditor.EditorGUILayout.FloatField(field.Name, (float)v);
                    }
                    else if (t == typeof(string))
                    {
                        v = UnityEditor.EditorGUILayout.TextField(field.Name, (string)v);
                    }
                    else if (t == typeof(UnityEngine.Object))
                    {
                        v = UnityEditor.EditorGUILayout.ObjectField(field.Name, (UnityEngine.Object)v, t, false);
                    }
                    else if (t == typeof(double))
                    {
                        v = UnityEditor.EditorGUILayout.DoubleField(field.Name, (double)v);
                    }
                    else if (t == typeof(Vector3))
                    {
                        v = UnityEditor.EditorGUILayout.Vector3Field(field.Name, (Vector3)v);
                    }
                    else if (t == typeof(Vector2))
                    {
                        v = UnityEditor.EditorGUILayout.Vector2Field(field.Name, (Vector2)v);
                    }
                    else if (t == typeof(AnimationCurve))
                    {
                        v = UnityEditor.EditorGUILayout.CurveField(field.Name, (AnimationCurve)v);
                    }
                    else if (t == typeof(Color))
                    {
                        v = UnityEditor.EditorGUILayout.ColorField(field.Name, (Color)v);
                    }
                    try
                    {
                        field.SetValue(this, v);
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError(ex.ToString());
                    }
                }
            }
        }
示例#4
0
        private void SerializeCustomObject(object o, System.Text.StringBuilder sb, int depth, System.Collections.Hashtable objectsInUse, JavaScriptSerializer.SerializationFormat serializationFormat)
        {
            bool flag = true;

            System.Type type = o.GetType();
            sb.Append('{');
            if (this.TypeResolver != null)
            {
                string text = this.TypeResolver.ResolveTypeId(type);
                if (text != null)
                {
                    JavaScriptSerializer.SerializeString("__type", sb);
                    sb.Append(':');
                    this.SerializeValue(text, sb, depth, objectsInUse, serializationFormat);
                    flag = false;
                }
            }
            EntityClassAttribute entityClassAttribute = JavaScriptSerializer.GetEntityClassAttribute(type);

            System.Reflection.FieldInfo[] fields = type.GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
            System.Reflection.FieldInfo[] array  = fields;
            for (int i = 0; i < array.Length; i++)
            {
                System.Reflection.FieldInfo fieldInfo = array[i];
                if (!fieldInfo.IsDefined(typeof(ScriptIgnoreAttribute), true))
                {
                    if (!flag)
                    {
                        sb.Append(',');
                    }
                    JavaScriptSerializer.SerializeString(JavaScriptSerializer.GetPropertyKey(fieldInfo, entityClassAttribute), sb);
                    sb.Append(':');
                    this.SerializeValue(fieldInfo.GetValue(o), sb, depth, objectsInUse, serializationFormat);
                    flag = false;
                }
            }
            System.Reflection.PropertyInfo[] properties = type.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.GetProperty);
            System.Reflection.PropertyInfo[] array2     = properties;
            for (int i = 0; i < array2.Length; i++)
            {
                System.Reflection.PropertyInfo propertyInfo = array2[i];
                if (!propertyInfo.IsDefined(typeof(ScriptIgnoreAttribute), true))
                {
                    System.Reflection.MethodInfo getMethod = propertyInfo.GetGetMethod();
                    if (!(getMethod == null))
                    {
                        if (getMethod.GetParameters().Length <= 0)
                        {
                            if (!flag)
                            {
                                sb.Append(',');
                            }
                            JavaScriptSerializer.SerializeString(JavaScriptSerializer.GetPropertyKey(propertyInfo, entityClassAttribute), sb);
                            sb.Append(':');
                            this.SerializeValue(getMethod.Invoke(o, null), sb, depth, objectsInUse, serializationFormat);
                            flag = false;
                        }
                    }
                }
            }
            sb.Append('}');
        }