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);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create Persistent Data for all GameObjects and Components, write it to PersistentData list
        /// </summary>
        /// <param name="go">gameObject (initially root)</param>
        /// <param name="data">list which will be populated with PersistentData objects</param>
        private static void CreatePersistentData(GameObject go, List <PersistentData> data)
        {
            PersistentIgnore persistentIgnore = go.GetComponent <PersistentIgnore>();

            if (persistentIgnore != null /* && persistentIgnore.ReplacementPrefab == null*/)
            {
                //Do not save persistent ignore objects without replacement prefab
                return;
            }
            PersistentData goData = Create(go);

            if (goData != null)
            {
                goData.ActiveSelf = go.activeSelf;
                goData.ReadFrom(go);
                data.Add(goData);
            }

            Component[] components;
            if (persistentIgnore == null)
            {
                components = go.GetComponents <Component>().Where(c => c != null && !PersistentDescriptor.IgnoreTypes.Contains(c.GetType())).ToArray();
            }
            else
            {
                //if PersistentIgnore component exists save only Transform and PersistentIgnore components
                components = go.GetComponents <Transform>();
                Array.Resize(ref components, components.Length + 1);
                components[components.Length - 1] = persistentIgnore;
            }

            for (int i = 0; i < components.Length; ++i)
            {
                Component      component     = components[i];
                PersistentData componentData = PersistentData.Create(component);
                if (componentData != null)
                {
                    componentData.ReadFrom(component);
                    data.Add(componentData);
                }
            }

            Transform transform = go.transform;

            foreach (Transform childTransform in transform)
            {
                //Do not create childDescriptor for replacementPrefab child & for persistentIgnore without ReplacementPrefab
                if (persistentIgnore == null /* || persistentIgnore.ReplacementPrefab != null && !persistentIgnore.IsChildOfReplacementPrefab(childTransform)*/)
                {
                    //only for independent child
                    CreatePersistentData(childTransform.gameObject, data);
                }
            }
        }