static SpriteImporterData CreateSyntheticSpriteImporterData(System.Random rnd)
        {
            SpriteImporterData spriteImporterData = new SpriteImporterData();

            spriteImporterData.PackedSprite  = true;
            spriteImporterData.SourceTexture = CreateObjectIdentifier(rnd);
            return(spriteImporterData);
        }
Пример #2
0
        public ReturnCode Run()
        {
            var globalUsage = m_DependencyData.GlobalUsage;

            foreach (SceneDependencyInfo sceneInfo in m_DependencyData.SceneInfo.Values)
            {
                globalUsage |= sceneInfo.globalUsage;
            }

            if (m_SpriteData == null)
            {
                m_SpriteData = new BuildSpriteData();
            }

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

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

                uncachedInfo = new List <CachedInfo>();
            }

            for (int i = 0; i < m_Content.Assets.Count; i++)
            {
                GUID   asset     = m_Content.Assets[i];
                string assetPath = AssetDatabase.GUIDToAssetPath(asset.ToString());

                AssetLoadInfo      assetInfo;
                BuildUsageTagSet   usageTags;
                SpriteImporterData importerData;

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

                    assetInfo    = cachedInfo[i].Data[0] as AssetLoadInfo;
                    usageTags    = cachedInfo[i].Data[1] as BuildUsageTagSet;
                    importerData = cachedInfo[i].Data[2] as SpriteImporterData;
                }
                else
                {
                    if (!m_Tracker.UpdateInfoUnchecked(assetPath))
                    {
                        return(ReturnCode.Canceled);
                    }

                    assetInfo    = new AssetLoadInfo();
                    usageTags    = new BuildUsageTagSet();
                    importerData = null;

                    assetInfo.asset = asset;
                    var includedObjects = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(asset, m_Parameters.Target);
                    assetInfo.includedObjects = new List <ObjectIdentifier>(includedObjects);
                    var referencedObjects = ContentBuildInterface.GetPlayerDependenciesForObjects(includedObjects, m_Parameters.Target, m_Parameters.ScriptInfo);
                    assetInfo.referencedObjects = new List <ObjectIdentifier>(referencedObjects);
                    ContentBuildInterface.CalculateBuildUsageTags(referencedObjects, includedObjects, globalUsage, usageTags, m_DependencyData.DependencyUsageCache);

                    var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;
                    if (importer != null && importer.textureType == TextureImporterType.Sprite)
                    {
                        importerData = new SpriteImporterData();
                        importerData.PackedSprite  = !string.IsNullOrEmpty(importer.spritePackingTag);
                        importerData.SourceTexture = includedObjects.First();
                    }

                    if (uncachedInfo != null)
                    {
                        uncachedInfo.Add(GetCachedInfo(asset, assetInfo, usageTags, importerData));
                    }
                }

                SetOutputInformation(asset, assetInfo, usageTags, importerData);
            }

            if (m_SpriteData.ImporterData.Count == 0)
            {
                m_SpriteData = null;
            }

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

            return(ReturnCode.Success);
        }
Пример #3
0
#pragma warning restore 649

        CachedInfo GetCachedInfo(GUID asset, AssetLoadInfo assetInfo, BuildUsageTagSet usageTags, SpriteImporterData importerData)
        {
            var info = new CachedInfo();

            info.Asset = m_Cache.GetCacheEntry(asset);

            var dependencies = new HashSet <CacheEntry>();

            foreach (var reference in assetInfo.referencedObjects)
            {
                dependencies.Add(m_Cache.GetCacheEntry(reference));
            }
            info.Dependencies = dependencies.ToArray();

            info.Data = new object[] { assetInfo, usageTags, importerData };

            return(info);
        }
Пример #4
0
        void SetOutputInformation(GUID asset, AssetLoadInfo assetInfo, BuildUsageTagSet usageTags, SpriteImporterData importerData)
        {
            // Add generated asset information to IDependencyData
            m_DependencyData.AssetInfo.Add(asset, assetInfo);
            m_DependencyData.AssetUsage.Add(asset, usageTags);

            // Add generated importer data to IBuildSpriteData
            if (importerData != null)
            {
                m_SpriteData.ImporterData.Add(asset, importerData);
            }
        }
        public ReturnCode Run()
        {
            var globalUsage = m_DependencyData.GlobalUsage;

            foreach (SceneDependencyInfo sceneInfo in m_DependencyData.SceneInfo.Values)
            {
                globalUsage |= sceneInfo.globalUsage;
            }

            if (m_SpriteData == null)
            {
                m_SpriteData = new BuildSpriteData();
            }

            if (m_ExtendedAssetData == null)
            {
                m_ExtendedAssetData = new BuildExtendedAssetData();
            }

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

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

                uncachedInfo = new List <CachedInfo>();
            }

            for (int i = 0; i < m_Content.Assets.Count; i++)
            {
                GUID   asset     = m_Content.Assets[i];
                string assetPath = AssetDatabase.GUIDToAssetPath(asset.ToString());

                AssetLoadInfo      assetInfo;
                BuildUsageTagSet   usageTags;
                SpriteImporterData importerData;
                ExtendedAssetData  assetData;

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

                    assetInfo    = cachedInfo[i].Data[0] as AssetLoadInfo;
                    usageTags    = cachedInfo[i].Data[1] as BuildUsageTagSet;
                    importerData = cachedInfo[i].Data[2] as SpriteImporterData;
                    assetData    = cachedInfo[i].Data[3] as ExtendedAssetData;
                }
                else
                {
                    if (!m_Tracker.UpdateInfoUnchecked(assetPath))
                    {
                        return(ReturnCode.Canceled);
                    }

                    assetInfo    = new AssetLoadInfo();
                    usageTags    = new BuildUsageTagSet();
                    importerData = null;
                    assetData    = null;

                    assetInfo.asset = asset;
                    var includedObjects = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(asset, m_Parameters.Target);
                    assetInfo.includedObjects = new List <ObjectIdentifier>(includedObjects);
                    var referencedObjects = ContentBuildInterface.GetPlayerDependenciesForObjects(includedObjects, m_Parameters.Target, m_Parameters.ScriptInfo);
                    assetInfo.referencedObjects = new List <ObjectIdentifier>(referencedObjects);
                    var allObjects = new List <ObjectIdentifier>(includedObjects);
                    allObjects.AddRange(referencedObjects);
                    ContentBuildInterface.CalculateBuildUsageTags(allObjects.ToArray(), includedObjects, globalUsage, usageTags, m_DependencyData.DependencyUsageCache);

                    var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;
                    if (importer != null && importer.textureType == TextureImporterType.Sprite)
                    {
                        // Legacy Sprite Packing Modes
                        if (EditorSettings.spritePackerMode == SpritePackerMode.AlwaysOn || EditorSettings.spritePackerMode == SpritePackerMode.BuildTimeOnly)
                        {
                            importerData = new SpriteImporterData();
                            importerData.PackedSprite  = !string.IsNullOrEmpty(importer.spritePackingTag);
                            importerData.SourceTexture = includedObjects.First();
                        }
                        else if (!referencedObjects.IsNullOrEmpty()) // Sprite is referencing packed data
                        {
                            importerData = new SpriteImporterData();
                            importerData.PackedSprite  = EditorSettings.spritePackerMode != SpritePackerMode.Disabled;
                            importerData.SourceTexture = includedObjects.First();
                        }
                    }

                    var representations = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath);
                    if (!representations.IsNullOrEmpty())
                    {
                        assetData = new ExtendedAssetData();
                        foreach (var representation in representations)
                        {
                            if (AssetDatabase.IsMainAsset(representation))
                            {
                                continue;
                            }

                            string guid;
                            long   localId;
                            if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(representation, out guid, out localId))
                            {
                                continue;
                            }

                            assetData.Representations.AddRange(includedObjects.Where(x => x.localIdentifierInFile == localId));
                        }
                    }

                    if (uncachedInfo != null)
                    {
                        uncachedInfo.Add(GetCachedInfo(asset, assetInfo, usageTags, importerData, assetData));
                    }
                }

                SetOutputInformation(asset, assetInfo, usageTags, importerData, assetData);
            }

            if (m_SpriteData.ImporterData.Count == 0)
            {
                m_SpriteData = null;
            }

            if (m_ExtendedAssetData.ExtendedData.Count == 0)
            {
                m_SpriteData = null;
            }

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

            return(ReturnCode.Success);
        }
        static CachedInfo GetCachedInfo(IBuildCache cache, GUID asset, AssetLoadInfo assetInfo, BuildUsageTagSet usageTags, SpriteImporterData importerData, ExtendedAssetData assetData)
        {
            var info = new CachedInfo();

            info.Asset = cache.GetCacheEntry(asset, kVersion);

            var uniqueTypes  = new HashSet <System.Type>();
            var objectTypes  = new List <KeyValuePair <ObjectIdentifier, System.Type[]> >();
            var dependencies = new HashSet <CacheEntry>();

            ExtensionMethods.ExtractCommonCacheData(cache, assetInfo.includedObjects, assetInfo.referencedObjects, uniqueTypes, objectTypes, dependencies);
            info.Dependencies = dependencies.ToArray();

            info.Data = new object[] { assetInfo, usageTags, importerData, assetData, objectTypes };
            return(info);
        }