protected void AddDep(object obj, GetDepsFromContext context)
 {
     if (obj != null && !context.Dependencies.Contains(obj))
     {
         context.Dependencies.Add(obj);
     }
 }
Ejemplo n.º 2
0
        protected override void GetDepsFromImpl(object obj, GetDepsFromContext context)
        {
            base.GetDepsFromImpl(obj, context);
            if (obj == null)
            {
                return;
            }

            object persistentCalls = m_persistentCallGroupInfo.GetValue(obj);

            if (persistentCalls == null)
            {
                return;
            }

            object calls = m_callsInfo.GetValue(persistentCalls);

            if (calls == null)
            {
                return;
            }

            IList list = (IList)calls;

            for (int i = 0; i < list.Count; ++i)
            {
                object call = list[i];
                PersistentPersistentCall persistentCall = new PersistentPersistentCall();
                persistentCall.GetDepsFrom(call, context);
            }
        }
 protected void AddDep <T>(T[] dependencies, GetDepsFromContext context)
 {
     for (int i = 0; i < dependencies.Length; ++i)
     {
         AddDep(dependencies[i], context);
     }
 }
 protected void AddSurrogateDeps(object obj, GetDepsFromContext context)
 {
     if (obj != null)
     {
         PersistentSurrogate surrogate = (PersistentSurrogate)obj;
         surrogate.GetDepsFrom(obj, context);
     }
 }
 public virtual void GetDepsFrom(object obj, GetDepsFromContext context)
 {
     if (context.VisitedObjects.Contains(this))
     {
         return;
     }
     context.VisitedObjects.Add(this);
     GetDepsFromImpl(obj, context);
 }
Ejemplo n.º 6
0
        protected override void GetDepsFromImpl(object obj, GetDepsFromContext context)
        {
            base.GetDepsFromImpl(obj, context);
            if (!(obj is GameObject))
            {
                return;
            }

            GetDependenciesFrom((GameObject)obj, context);
        }
 protected void AddDep <T>(List <T> dependencies, GetDepsFromContext context)
 {
     if (dependencies == null)
     {
         return;
     }
     for (int i = 0; i < dependencies.Count; ++i)
     {
         AddDep(dependencies[i], context);
     }
 }
 protected void AddSurrogateDeps <T>(T[] objArray, GetDepsFromContext context)
 {
     for (int i = 0; i < objArray.Length; ++i)
     {
         object obj = objArray[i];
         if (obj != null)
         {
             PersistentSurrogate surrogate = (PersistentSurrogate)obj;
             surrogate.GetDepsFrom(obj, context);
         }
     }
 }
Ejemplo n.º 9
0
        protected override void GetDepsFromImpl(object obj, GetDepsFromContext context)
        {
            base.GetDepsFromImpl(obj, context);
            if (obj == null)
            {
                return;
            }

            Initialize(obj.GetType());
            UnityObject uobjArgument = (UnityObject)m_objectArgumentFieldInfo.GetValue(obj);

            AddDep(uobjArgument, context);
        }
Ejemplo n.º 10
0
        protected override void GetDepsFromImpl(object obj, GetDepsFromContext context)
        {
            if (!(obj is Scene))
            {
                return;
            }

            Scene scene = (Scene)obj;

            GameObject[] gameObjects = scene.GetRootGameObjects();

            for (int i = 0; i < gameObjects.Length; ++i)
            {
                base.GetDepsFromImpl(gameObjects[i], context);
            }
        }
Ejemplo n.º 11
0
        private void GetDependenciesFrom(GameObject go, GetDepsFromContext context)
        {
            if (go.GetComponent <RTSL2Ignore>())
            {
                //Do not save persistent ignore objects
                return;
            }
            Type persistentType = m_typeMap.ToPersistentType(go.GetType());

            if (persistentType == null)
            {
                return;
            }

            PersistentObject goData = (PersistentObject)Activator.CreateInstance(persistentType);

            goData.GetDepsFrom(go, context);

            Component[] components = go.GetComponents <Component>().Where(c => c != null).ToArray();
            if (components.Length > 0)
            {
                for (int i = 0; i < components.Length; ++i)
                {
                    Component component = components[i];
                    Type      persistentComponentType = m_typeMap.ToPersistentType(component.GetType());
                    if (persistentComponentType == null)
                    {
                        continue;
                    }

                    PersistentObject componentData = (PersistentObject)Activator.CreateInstance(persistentComponentType);
                    componentData.GetDepsFrom(component, context);
                }
            }

            Transform transform = go.transform;

            if (transform.childCount > 0)
            {
                foreach (Transform child in transform)
                {
                    GetDependenciesFrom(child.gameObject, context);
                }
            }
        }
Ejemplo n.º 12
0
        protected override void GetDepsFromImpl(object obj, GetDepsFromContext context)
        {
            base.GetDepsFromImpl(obj, context);
            if (obj == null)
            {
                return;
            }

            Initialize(obj.GetType());

            PersistentArgumentCache args = new PersistentArgumentCache();

            args.GetDepsFrom(m_argumentsFieldInfo.GetValue(obj), context);

            UnityObject target = (UnityObject)m_targetFieldInfo.GetValue(obj);

            AddDep(target, context);
        }
        protected override void ReadFromImpl(object obj)
        {
            base.ReadFromImpl(obj);
            GameObject go = (GameObject)obj;

            List <PersistentObject> data        = new List <PersistentObject>();
            List <long>             identifiers = new List <long>();
            //HashSet<int> usings = new HashSet<int>();
            GetDepsFromContext getDepsCtx = new GetDepsFromContext();

            Descriptors    = new PersistentDescriptor[1];
            Descriptors[0] = CreateDescriptorAndData(go, data, identifiers, /*usings,*/ getDepsCtx);

            Identifiers  = identifiers.ToArray();
            Data         = data.ToArray();
            Dependencies = getDepsCtx.Dependencies.OfType <UnityObject>().Select(d => m_assetDB.ToID(d)).ToArray();
            // Usings = usings.ToArray();
        }
Ejemplo n.º 14
0
        protected override void ReadFromImpl(object obj)
        {
            Scene scene = (Scene)obj;

            GameObject[] rootGameObjects = scene.GetRootGameObjects();

            List <PersistentObject>     data            = new List <PersistentObject>();
            List <long>                 identifiers     = new List <long>();
            List <PersistentDescriptor> descriptors     = new List <PersistentDescriptor>(rootGameObjects.Length);
            GetDepsFromContext          getSceneDepsCtx = new GetDepsFromContext();

            for (int i = 0; i < rootGameObjects.Length; ++i)
            {
                GameObject           rootGO     = rootGameObjects[i];
                PersistentDescriptor descriptor = CreateDescriptorAndData(rootGO, data, identifiers, getSceneDepsCtx);
                if (descriptor != null)
                {
                    descriptors.Add(descriptor);
                }
            }

            HashSet <object>    allDeps      = getSceneDepsCtx.Dependencies;
            List <UnityObject>  externalDeps = new List <UnityObject>(allDeps.OfType <UnityObject>());
            Queue <UnityObject> depsQueue    = new Queue <UnityObject>(allDeps.OfType <UnityObject>());

            List <PersistentObject> assets = new List <PersistentObject>();
            List <int> assetIdentifiers    = new List <int>();

            GetDepsFromContext getDepsCtx = new GetDepsFromContext();

            while (depsQueue.Count > 0)
            {
                UnityObject uo = depsQueue.Dequeue();
                if (!uo)
                {
                    continue;
                }
                if (!m_assetDB.IsMapped(uo))
                {
                    if (!(uo is GameObject) && !(uo is Component))
                    {
                        Type persistentType = m_typeMap.ToPersistentType(uo.GetType());
                        if (persistentType != null)
                        {
                            getDepsCtx.Clear();

                            PersistentObject persistentObject = (PersistentObject)Activator.CreateInstance(persistentType);
                            persistentObject.ReadFrom(uo);
                            persistentObject.GetDepsFrom(uo, getDepsCtx);

                            assets.Add(persistentObject);
                            assetIdentifiers.Add(uo.GetInstanceID());

                            foreach (UnityObject dep in getDepsCtx.Dependencies)
                            {
                                if (!allDeps.Contains(dep))
                                {
                                    allDeps.Add(dep);
                                    depsQueue.Enqueue(dep);
                                }
                            }
                        }
                    }
                    externalDeps.Remove(uo);
                }
            }

            Descriptors  = descriptors.ToArray();
            Identifiers  = identifiers.ToArray();
            Data         = data.ToArray();
            Dependencies = externalDeps.Select(uo => m_assetDB.ToID(uo)).ToArray();

            Assets           = assets.ToArray();
            AssetIdentifiers = assetIdentifiers.ToArray();
        }
 protected virtual void GetDepsFromImpl(object obj, GetDepsFromContext context)
 {
 }
 protected void AddSurrogateDeps <T>(T obj, Func <T, PersistentSurrogate> convert, GetDepsFromContext context)
 {
     if (obj != null)
     {
         PersistentSurrogate surrogate = convert(obj);
         surrogate.GetDepsFrom(obj, context);
     }
 }
 protected void AddSurrogateDeps <T>(T[] objArray, Func <T, PersistentSurrogate> convert, GetDepsFromContext context)
 {
     if (objArray == null)
     {
         return;
     }
     for (int i = 0; i < objArray.Length; ++i)
     {
         T obj = objArray[i];
         if (obj != null)
         {
             PersistentSurrogate surrogate = convert(obj);
             surrogate.GetDepsFrom(obj, context);
         }
     }
 }
 protected void AddSurrogateDeps <T>(List <T> objList, Func <T, PersistentSurrogate> convert, GetDepsFromContext context)
 {
     if (objList == null)
     {
         return;
     }
     for (int i = 0; i < objList.Count; ++i)
     {
         T obj = objList[i];
         if (obj != null)
         {
             PersistentSurrogate surrogate = convert(obj);
             surrogate.GetDepsFrom(obj, context);
         }
     }
 }
Ejemplo n.º 19
0
        private static void CreateAssetLibraryFromScene(Scene scene, int index, AssetLibraryAsset asset, AssetFolderInfo folder, HashSet <UnityObject> hs)
        {
            TypeMap typeMap = new TypeMap();
            AssetDB assetDB = new AssetDB();

            IOC.Register <ITypeMap>(typeMap);
            IOC.Register <IAssetDB>(assetDB);

            PersistentRuntimeScene rtScene = new PersistentRuntimeScene();

            GetDepsFromContext ctx = new GetDepsFromContext();

            rtScene.GetDepsFrom(scene, ctx);

            IOC.Unregister <ITypeMap>(typeMap);
            IOC.Unregister <IAssetDB>(assetDB);

            int identity = asset.AssetLibrary.Identity;

            foreach (UnityObject obj in ctx.Dependencies)
            {
                if (hs.Contains(obj))
                {
                    continue;
                }

                if (obj is GameObject)
                {
                    GameObject go = (GameObject)obj;
                    if (go.IsPrefab())
                    {
                        AssetInfo assetInfo = new AssetInfo(go.name, 0, identity);
                        assetInfo.Object = go;
                        identity++;

                        List <PrefabPartInfo> prefabParts = new List <PrefabPartInfo>();
                        AssetLibraryAssetsGUI.CreatePefabParts(go, ref identity, prefabParts);
                        if (prefabParts.Count >= AssetLibraryInfo.MAX_ASSETS - AssetLibraryInfo.INITIAL_ID)
                        {
                            EditorUtility.DisplayDialog("Unable Create AssetLibrary", string.Format("Max 'Indentity' value reached. 'Identity' ==  {0}", AssetLibraryInfo.MAX_ASSETS), "OK");
                            return;
                        }

                        if (identity >= AssetLibraryInfo.MAX_ASSETS)
                        {
                            SaveAssetLibrary(asset, scene, index);
                            index++;

                            asset  = ScriptableObject.CreateInstance <AssetLibraryAsset>();
                            folder = asset.AssetLibrary.Folders.Where(f => f.depth == 0).First();

                            identity = asset.AssetLibrary.Identity;
                        }

                        assetInfo.PrefabParts       = prefabParts;
                        asset.AssetLibrary.Identity = identity;
                        folder.Assets.Add(assetInfo);
                    }
                }
                else
                {
                    AssetInfo assetInfo = new AssetInfo(obj.name, 0, identity);
                    assetInfo.Object = obj;
                    identity++;

                    if (identity >= AssetLibraryInfo.MAX_ASSETS)
                    {
                        SaveAssetLibrary(asset, scene, index);
                        index++;

                        asset    = ScriptableObject.CreateInstance <AssetLibraryAsset>();
                        folder   = asset.AssetLibrary.Folders.Where(f => f.depth == 0).First();
                        identity = asset.AssetLibrary.Identity;
                    }

                    asset.AssetLibrary.Identity = identity;
                    folder.Assets.Add(assetInfo);
                }
            }

            SaveAssetLibrary(asset, scene, index);
            index++;

            Selection.activeObject = asset;
            EditorGUIUtility.PingObject(asset);
        }
        protected PersistentDescriptor CreateDescriptorAndData(GameObject go, List <PersistentObject> persistentData, List <long> persistentIdentifiers, /*HashSet<int> usings,*/ GetDepsFromContext getDepsFromCtx, PersistentDescriptor parentDescriptor = null)
        {
            if (go.GetComponent <RTSL2Ignore>())
            {
                //Do not save persistent ignore objects
                return(null);
            }
            Type persistentType = m_typeMap.ToPersistentType(go.GetType());

            if (persistentType == null)
            {
                return(null);
            }

            long persistentID = ToID(go);
            //if(m_assetDB.IsResourceID(persistentID))
            //{
            //    int ordinal = m_assetDB.ToOrdinal(persistentID);
            //    usings.Add(ordinal);
            //}

            PersistentDescriptor descriptor = new PersistentDescriptor(m_typeMap.ToGuid(persistentType), persistentID, go.name);

            descriptor.Parent = parentDescriptor;

            PersistentObject goData = (PersistentObject)Activator.CreateInstance(persistentType);

            goData.ReadFrom(go);
            goData.GetDepsFrom(go, getDepsFromCtx);
            persistentData.Add(goData);
            persistentIdentifiers.Add(persistentID);

            Component[] components = go.GetComponents <Component>().Where(c => c != null).ToArray();
            if (components.Length > 0)
            {
                List <PersistentDescriptor> componentDescriptors = new List <PersistentDescriptor>();
                for (int i = 0; i < components.Length; ++i)
                {
                    Component component = components[i];
                    Type      persistentComponentType = m_typeMap.ToPersistentType(component.GetType());
                    if (persistentComponentType == null)
                    {
                        continue;
                    }

                    long componentID = ToID(component);
                    //if (m_assetDB.IsResourceID(componentID))
                    //{
                    //    int ordinal = m_assetDB.ToOrdinal(componentID);
                    //    usings.Add(ordinal);
                    //}
                    PersistentDescriptor componentDescriptor = new PersistentDescriptor(m_typeMap.ToGuid(persistentComponentType), componentID, component.name);
                    componentDescriptor.Parent = descriptor;
                    componentDescriptors.Add(componentDescriptor);

                    PersistentObject componentData = (PersistentObject)Activator.CreateInstance(persistentComponentType);
                    componentData.ReadFrom(component);
                    componentData.GetDepsFrom(component, getDepsFromCtx);
                    persistentData.Add(componentData);
                    persistentIdentifiers.Add(componentID);
                }

                if (componentDescriptors.Count > 0)
                {
                    descriptor.Components = componentDescriptors.ToArray();
                }
            }

            Transform transform = go.transform;

            if (transform.childCount > 0)
            {
                List <PersistentDescriptor> children = new List <PersistentDescriptor>();
                foreach (Transform child in transform)
                {
                    PersistentDescriptor childDescriptor = CreateDescriptorAndData(child.gameObject, persistentData, persistentIdentifiers, /*usings,*/ getDepsFromCtx, descriptor);
                    if (childDescriptor != null)
                    {
                        children.Add(childDescriptor);
                    }
                }

                descriptor.Children = children.ToArray();
            }

            return(descriptor);
        }