private void GetDependencies(UnityObject obj, Dictionary <long, UnityObject> objects)
        {
            PersistentData data = PersistentData.Create(obj);

            if (data == null)
            {
                return;
            }
            data.GetDependencies(obj, objects);
            if (obj is GameObject)
            {
                GameObject  go         = (GameObject)obj;
                Component[] components = go.GetComponents <Component>();
                for (int i = 0; i < components.Length; ++i)
                {
                    Component component = components[i];
                    if (component != null)
                    {
                        data = PersistentData.Create(component);
                        data.GetDependencies(component, objects);
                    }
                }
                foreach (Transform child in go.transform)
                {
                    GetDependencies(child.gameObject, objects);
                }
            }
        }
예제 #2
0
        protected override void GetDependencies(Dictionary <long, UnityObject> dependencies, object obj)
        {
            base.GetDependencies(dependencies, obj);

            base.ReadFrom(obj); //?


            if (baseObjectData != null)
            {
                baseObjectData.GetDependencies(obj, dependencies);
            }

            Type type = obj.GetType();

            if (!type.IsScript())
            {
                throw new ArgumentException(string.Format("obj of type {0} is not subclass of {1}", type, typeof(MonoBehaviour)), "obj");
            }

            do
            {
                FieldInfo[] fields = type.GetSerializableFields();
                for (int i = 0; i < fields.Length; ++i)
                {
                    FieldInfo field = fields[i];


                    bool isArray   = field.FieldType.IsArray;
                    Type fieldType = field.FieldType;
                    if (isArray)
                    {
                        fieldType = fieldType.GetElementType();
                    }

                    if (fieldType.IsSubclassOf(typeof(UnityObject)) || fieldType == typeof(UnityObject))
                    {
                        if (isArray)
                        {
                            UnityObject[] unityObjects = (UnityObject[])field.GetValue(obj);
                            if (unityObjects != null)
                            {
                                AddDependencies(unityObjects, dependencies);
                            }
                        }
                        else
                        {
                            UnityObject unityObject = (UnityObject)field.GetValue(obj);
                            AddDependency(unityObject, dependencies);
                        }
                    }
                    else
                    {
                        if (fieldType.IsSubclassOf(typeof(UnityEventBase)))
                        {
                            UnityEventBase unityEvent = (UnityEventBase)field.GetValue(obj);
                            if (unityEvent != null)
                            {
                                PersistentUnityEventBase persistentUnityEvent = new PersistentUnityEventBase();
                                persistentUnityEvent.GetDependencies(unityEvent, dependencies);
                            }
                        }
                        else
                        {
                            if (!field.FieldType.IsEnum())
                            {
                                object fieldValue = field.GetValue(obj);
                                if (typeof(IEnumerable).IsAssignableFrom(field.FieldType))
                                {
                                    IEnumerable enumerable = (IEnumerable)fieldValue;
                                    foreach (object o in enumerable)
                                    {
                                        if (o is IRTSerializable)
                                        {
                                            IRTSerializable rtSerializable = (IRTSerializable)o;
                                            rtSerializable.GetDependencies(dependencies);
                                        }
                                    }
                                }
                                else
                                {
                                    if (fieldValue is IRTSerializable)
                                    {
                                        IRTSerializable rtSerializable = (IRTSerializable)fieldValue;
                                        rtSerializable.GetDependencies(dependencies);
                                    }
                                }
                            }
                        }
                    }
                }

                type = type.BaseType();
            }while (type.IsScript());
        }