Esempio n. 1
0
        bool LoadCachedData(string path, out AssetLoadInfo assetInfo, out BuildUsageTagSet buildUsage, BuildUsageTagGlobal globalUsage)
        {
            assetInfo  = default;
            buildUsage = default;

            if (!m_Parameters.UseCache || m_Cache == null)
            {
                return(false);
            }

            CacheEntry entry = GetCacheEntry(path, globalUsage);

            m_Cache.LoadCachedData(new List <CacheEntry> {
                entry
            }, out IList <CachedInfo> cachedInfos);
            var cachedInfo = cachedInfos[0];

            if (cachedInfo != null)
            {
                assetInfo  = (AssetLoadInfo)cachedInfo.Data[0];
                buildUsage = (BuildUsageTagSet)cachedInfo.Data[1];
                var objectTypes = (List <KeyValuePair <ObjectIdentifier, Type[]> >)cachedInfo.Data[2];
                BuildCacheUtility.SetTypeForObjects(objectTypes);
            }
            else
            {
                GatherAssetData(path, out assetInfo, out buildUsage, globalUsage);
                cachedInfo = GetCachedInfo(entry, assetInfo, buildUsage);
                m_Cache.SaveCachedData(new List <CachedInfo> {
                    cachedInfo
                });
            }
            return(true);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public ReturnCode Run()
        {
            TaskInput input = new TaskInput();

            input.Target     = m_Parameters.Target;
            input.TypeDB     = m_Parameters.ScriptInfo;
            input.BuildCache = m_Parameters.UseCache ? m_Cache : null;
#if NONRECURSIVE_DEPENDENCY_DATA
            input.NonRecursiveDependencies = m_Parameters.NonRecursiveDependencies;
#else
            input.NonRecursiveDependencies = false;
#endif
            input.Assets               = m_Content.Assets;
            input.ProgressTracker      = m_Tracker;
            input.DependencyUsageCache = m_DependencyData.DependencyUsageCache;
            input.GlobalUsage          = m_DependencyData.GlobalUsage;
            input.Logger               = m_Log;
            foreach (SceneDependencyInfo sceneInfo in m_DependencyData.SceneInfo.Values)
            {
                input.GlobalUsage |= sceneInfo.globalUsage;
            }

            ReturnCode code = RunInternal(input, out TaskOutput output);
            if (code == ReturnCode.Success)
            {
                foreach (AssetOutput o in output.AssetResults)
                {
                    m_DependencyData.AssetInfo.Add(o.asset, o.assetInfo);
                    m_DependencyData.AssetUsage.Add(o.asset, o.usageTags);

                    if (o.spriteData != null)
                    {
                        if (m_SpriteData == null)
                        {
                            m_SpriteData = new BuildSpriteData();
                        }
                        m_SpriteData.ImporterData.Add(o.asset, o.spriteData);
                    }

                    if (!m_Parameters.DisableVisibleSubAssetRepresentations && o.extendedData != null)
                    {
                        if (m_ExtendedAssetData == null)
                        {
                            m_ExtendedAssetData = new BuildExtendedAssetData();
                        }
                        m_ExtendedAssetData.ExtendedData.Add(o.asset, o.extendedData);
                    }

                    if (o.objectTypes != null)
                    {
                        BuildCacheUtility.SetTypeForObjects(o.objectTypes);
                    }
                }
            }

            return(code);
        }
Esempio n. 3
0
        /// <inheritdoc />
        public ReturnCode Run()
        {
            if (m_Content.Scenes.IsNullOrEmpty())
            {
                return(ReturnCode.SuccessNotRun);
            }

            IList <CachedInfo> cachedInfo   = null;
            IList <CachedInfo> uncachedInfo = null;

            if (m_Parameters.UseCache && m_Cache != null)
            {
                IList <CacheEntry> entries = m_Content.Scenes.Select(x => m_Cache.GetCacheEntry(x, Version)).ToList();
                m_Cache.LoadCachedData(entries, out cachedInfo);

                uncachedInfo = new List <CachedInfo>();
            }

            BuildSettings settings = m_Parameters.GetContentBuildSettings();

            for (int i = 0; i < m_Content.Scenes.Count; i++)
            {
                GUID   scene     = m_Content.Scenes[i];
                string scenePath = AssetDatabase.GUIDToAssetPath(scene.ToString());

                SceneDependencyInfo sceneInfo;
                BuildUsageTagSet    usageTags;
                Hash128             prefabDependency = new Hash128();

                if (cachedInfo != null && cachedInfo[i] != null)
                {
                    if (!m_Tracker.UpdateInfoUnchecked(string.Format("{0} (Cached)", scenePath)))
                    {
                        return(ReturnCode.Canceled);
                    }

                    sceneInfo        = (SceneDependencyInfo)cachedInfo[i].Data[0];
                    usageTags        = cachedInfo[i].Data[1] as BuildUsageTagSet;
                    prefabDependency = (Hash128)cachedInfo[i].Data[2];
                    var objectTypes = cachedInfo[i].Data[3] as List <KeyValuePair <ObjectIdentifier, System.Type[]> >;
                    if (objectTypes != null)
                    {
                        BuildCacheUtility.SetTypeForObjects(objectTypes);
                    }
                }
                else
                {
                    if (!m_Tracker.UpdateInfoUnchecked(scenePath))
                    {
                        return(ReturnCode.Canceled);
                    }

                    usageTags = new BuildUsageTagSet();

#if UNITY_2019_3_OR_NEWER
                    sceneInfo = ContentBuildInterface.CalculatePlayerDependenciesForScene(scenePath, settings, usageTags, m_DependencyData.DependencyUsageCache);
#else
                    string outputFolder = m_Parameters.TempOutputFolder;
                    if (m_Parameters.UseCache && m_Cache != null)
                    {
                        outputFolder = m_Cache.GetCachedArtifactsDirectory(m_Cache.GetCacheEntry(scene, Version));
                    }
                    Directory.CreateDirectory(outputFolder);

                    sceneInfo = ContentBuildInterface.PrepareScene(scenePath, settings, usageTags, m_DependencyData.DependencyUsageCache, outputFolder);
#endif
                    if (uncachedInfo != null)
                    {
                        // We only need to gather prefab dependencies and calculate the hash if we are using caching, otherwise we can skip it
                        var prefabEntries = AssetDatabase.GetDependencies(AssetDatabase.GUIDToAssetPath(scene.ToString())).Where(path => path.EndsWith(".prefab")).Select(m_Cache.GetCacheEntry);
                        prefabDependency = HashingMethods.Calculate(prefabEntries).ToHash128();
                        uncachedInfo.Add(GetCachedInfo(scene, sceneInfo.referencedObjects, sceneInfo, usageTags, prefabEntries, prefabDependency));
                    }
                }

                SetOutputInformation(scene, sceneInfo, usageTags, prefabDependency);
            }

            if (m_Parameters.UseCache && m_Cache != null)
            {
                m_Cache.SaveCachedData(uncachedInfo);
            }

            return(ReturnCode.Success);
        }