Current Sprite Packer job definition.

 public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
 {
   List<DefaultPackerPolicy.Entry> source1 = new List<DefaultPackerPolicy.Entry>();
   foreach (int importerInstanceId in textureImporterInstanceIDs)
   {
     TextureImporter textureImporter = EditorUtility.InstanceIDToObject(importerInstanceId) as TextureImporter;
     TextureFormat desiredFormat;
     ColorSpace colorSpace;
     int compressionQuality;
     textureImporter.ReadTextureImportInstructions(target, out desiredFormat, out colorSpace, out compressionQuality);
     TextureImporterSettings dest = new TextureImporterSettings();
     textureImporter.ReadTextureSettings(dest);
     foreach (Sprite sprite in ((IEnumerable<UnityEngine.Object>) AssetDatabase.LoadAllAssetRepresentationsAtPath(textureImporter.assetPath)).Select<UnityEngine.Object, Sprite>((Func<UnityEngine.Object, Sprite>) (x => x as Sprite)).Where<Sprite>((Func<Sprite, bool>) (x => (UnityEngine.Object) x != (UnityEngine.Object) null)).ToArray<Sprite>())
       source1.Add(new DefaultPackerPolicy.Entry()
       {
         sprite = sprite,
         settings = {
           format = desiredFormat,
           colorSpace = colorSpace,
           compressionQuality = !TextureUtil.IsCompressedTextureFormat(desiredFormat) ? 0 : compressionQuality,
           filterMode = !Enum.IsDefined(typeof (UnityEngine.FilterMode), (object) textureImporter.filterMode) ? UnityEngine.FilterMode.Bilinear : textureImporter.filterMode,
           maxWidth = 2048,
           maxHeight = 2048,
           generateMipMaps = textureImporter.mipmapEnabled,
           enableRotation = this.AllowRotationFlipping,
           allowsAlphaSplitting = textureImporter.GetAllowsAlphaSplitting(),
           paddingPower = !textureImporter.mipmapEnabled ? (uint) EditorSettings.spritePackerPaddingPower : 3U
         },
         atlasName = this.ParseAtlasName(textureImporter.spritePackingTag),
         packingMode = this.GetPackingMode(textureImporter.spritePackingTag, dest.spriteMeshType),
         anisoLevel = textureImporter.anisoLevel
       });
     Resources.UnloadAsset((UnityEngine.Object) textureImporter);
   }
   foreach (IGrouping<string, DefaultPackerPolicy.Entry> source2 in source1.GroupBy<DefaultPackerPolicy.Entry, string, DefaultPackerPolicy.Entry>((Func<DefaultPackerPolicy.Entry, string>) (e => e.atlasName), (Func<DefaultPackerPolicy.Entry, DefaultPackerPolicy.Entry>) (e => e)))
   {
     int num = 0;
     IEnumerable<IGrouping<AtlasSettings, DefaultPackerPolicy.Entry>> source3 = source2.GroupBy<DefaultPackerPolicy.Entry, AtlasSettings, DefaultPackerPolicy.Entry>((Func<DefaultPackerPolicy.Entry, AtlasSettings>) (t => t.settings), (Func<DefaultPackerPolicy.Entry, DefaultPackerPolicy.Entry>) (t => t));
     foreach (IGrouping<AtlasSettings, DefaultPackerPolicy.Entry> grouping in source3)
     {
       string key1 = source2.Key;
       if (source3.Count<IGrouping<AtlasSettings, DefaultPackerPolicy.Entry>>() > 1)
         key1 += string.Format(" (Group {0})", (object) num);
       AtlasSettings key2 = grouping.Key;
       key2.anisoLevel = 1;
       if (key2.generateMipMaps)
       {
         foreach (DefaultPackerPolicy.Entry entry in (IEnumerable<DefaultPackerPolicy.Entry>) grouping)
         {
           if (entry.anisoLevel > key2.anisoLevel)
             key2.anisoLevel = entry.anisoLevel;
         }
       }
       job.AddAtlas(key1, key2);
       foreach (DefaultPackerPolicy.Entry entry in (IEnumerable<DefaultPackerPolicy.Entry>) grouping)
         job.AssignToAtlas(key1, entry.sprite, entry.packingMode, SpritePackingRotation.None);
       ++num;
     }
   }
 }
    public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
    {
        List<Entry> entries = new List<Entry>();

        foreach (int instanceID in textureImporterInstanceIDs)
        {
            TextureImporter ti = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter;

            //TextureImportInstructions ins = new TextureImportInstructions();
            //ti.ReadTextureImportInstructions(ins, target);

            TextureImporterSettings tis = new TextureImporterSettings();
            ti.ReadTextureSettings(tis);

            Sprite[] sprites = AssetDatabase.LoadAllAssetRepresentationsAtPath(ti.assetPath).Select(x => x as Sprite).Where(x => x != null).ToArray();
            foreach (Sprite sprite in sprites)
            {
                //在这里设置每个图集的参数
                Entry entry = new Entry();
                entry.sprite = sprite;
                entry.settings.format = (TextureFormat)Enum.Parse(typeof(TextureFormat), ParseTextuerFormat(ti.spritePackingTag).ToString());
                entry.settings.filterMode = FilterMode.Bilinear;
                entry.settings.colorSpace = ColorSpace.Linear;
                entry.settings.compressionQuality = (int)TextureCompressionQuality.Normal;
                entry.settings.filterMode = Enum.IsDefined(typeof(FilterMode), ti.filterMode) ? ti.filterMode : FilterMode.Bilinear;
                entry.settings.maxWidth = ParseTextureWidth(ti.spritePackingTag);
                entry.settings.maxHeight = ParseTextureHeight(ti.spritePackingTag);
                entry.atlasName = ParseAtlasName(ti.spritePackingTag);
                entry.packingMode = GetPackingMode(ti.spritePackingTag, tis.spriteMeshType);

                entries.Add(entry);
            }
            Resources.UnloadAsset(ti);
        }

        var atlasGroups =
            from e in entries
            group e by e.atlasName;
        foreach (var atlasGroup in atlasGroups)
        {
            int page = 0;
            // Then split those groups into smaller groups based on texture settings
            var settingsGroups =
                from t in atlasGroup
                group t by t.settings;
            foreach (var settingsGroup in settingsGroups)
            {
                string atlasName = atlasGroup.Key;
                if (settingsGroups.Count() > 1)
                    atlasName += string.Format(" (Group {0})", page);

                job.AddAtlas(atlasName, settingsGroup.Key);
                foreach (Entry entry in settingsGroup)
                {
                    job.AssignToAtlas(atlasName, entry.sprite, entry.packingMode, SpritePackingRotation.None);
                }
                ++page;
            }
        }
    }
Пример #3
0
 public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
 {
     List<Entry> source = new List<Entry>();
     foreach (int num in textureImporterInstanceIDs)
     {
         TextureFormat format;
         ColorSpace space;
         int num3;
         TextureImporter assetToUnload = EditorUtility.InstanceIDToObject(num) as TextureImporter;
         assetToUnload.ReadTextureImportInstructions(target, out format, out space, out num3);
         TextureImporterSettings dest = new TextureImporterSettings();
         assetToUnload.ReadTextureSettings(dest);
         if (<>f__am$cache0 == null)
         {
Пример #4
0
        public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
        {
            List <Entry> source = new List <Entry>();

            foreach (int num in textureImporterInstanceIDs)
            {
                TextureFormat   format;
                ColorSpace      space;
                int             num3;
                TextureImporter assetToUnload = EditorUtility.InstanceIDToObject(num) as TextureImporter;
                assetToUnload.ReadTextureImportInstructions(target, out format, out space, out num3);
                TextureImporterSettings dest = new TextureImporterSettings();
                assetToUnload.ReadTextureSettings(dest);
                if (< > f__am$cache0 == null)
                {
 public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
 {
     List<Entry> list = new List<Entry>();
     string targetName = "";
     if (target != BuildTarget.NoTarget)
     {
         targetName = BuildPipeline.GetBuildTargetName(target);
     }
     foreach (int num in textureImporterInstanceIDs)
     {
         TextureFormat format;
         ColorSpace space;
         int num3;
         TextureImporter ti = EditorUtility.InstanceIDToObject(num) as TextureImporter;
         ti.ReadTextureImportInstructions(target, out format, out space, out num3);
         TextureImporterSettings dest = new TextureImporterSettings();
         ti.ReadTextureSettings(dest);
         bool flag = (targetName != "") && this.HasPlatformEnabledAlphaSplittingForCompression(targetName, ti);
         if (<>f__am$cache0 == null)
         {
Пример #6
0
        public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
        {
            List <Entry> list       = new List <Entry>();
            string       targetName = "";

            if (target != BuildTarget.NoTarget)
            {
                targetName = BuildPipeline.GetBuildTargetName(target);
            }
            foreach (int num in textureImporterInstanceIDs)
            {
                TextureFormat   format;
                ColorSpace      space;
                int             num3;
                TextureImporter ti = EditorUtility.InstanceIDToObject(num) as TextureImporter;
                ti.ReadTextureImportInstructions(target, out format, out space, out num3);
                TextureImporterSettings dest = new TextureImporterSettings();
                ti.ReadTextureSettings(dest);
                bool flag = (targetName != "") && this.HasPlatformEnabledAlphaSplittingForCompression(targetName, ti);
                if (< > f__am$cache0 == null)
                {
Пример #7
0
    public void OnGroupAtlases(BuildTarget target, UnityEditor.Sprites.PackerJob job, int[] textureImporterInstanceIDs)
    {
        List <Entry> entries = new List <Entry>();

        foreach (int instanceID in textureImporterInstanceIDs)
        {
            TextureImporter ti = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter;

            TextureFormat desiredFormat;
            ColorSpace    colorSpace;
            int           compressionQuality;
            ti.ReadTextureImportInstructions(target, out desiredFormat, out colorSpace, out compressionQuality);

            TextureImporterSettings tis = new TextureImporterSettings();
            ti.ReadTextureSettings(tis);

            Sprite[] sprites =
                AssetDatabase.LoadAllAssetRepresentationsAtPath(ti.assetPath)
                .Select(x => x as Sprite)
                .Where(x => x != null)
                .ToArray();
            foreach (Sprite sprite in sprites)
            {
                Entry entry = new Entry();
                entry.sprite              = sprite;
                entry.settings.format     = desiredFormat;
                entry.settings.colorSpace = colorSpace;
                // Use Compression Quality for Grouping later only for Compressed Formats. Otherwise leave it Empty.
                entry.settings.compressionQuality = IsCompressedFormat(desiredFormat) ? compressionQuality : 0;
                entry.settings.filterMode         = Enum.IsDefined(typeof(FilterMode), ti.filterMode)
                    ? ti.filterMode
                    : FilterMode.Bilinear;
                entry.settings.maxWidth        = 4096;
                entry.settings.maxHeight       = 4096;
                entry.settings.generateMipMaps = ti.mipmapEnabled;
                entry.settings.enableRotation  = AllowRotationFlipping;
                if (ti.mipmapEnabled)
                {
                    entry.settings.paddingPower = kDefaultPaddingPower;
                }
                else
                {
                    entry.settings.paddingPower = (uint)EditorSettings.spritePackerPaddingPower;
                }
                entry.atlasName   = ParseAtlasName(ti.spritePackingTag);
                entry.packingMode = GetPackingMode(ti.spritePackingTag, tis.spriteMeshType);
                entry.anisoLevel  = ti.anisoLevel;

                entries.Add(entry);
            }

            Resources.UnloadAsset(ti);
        }

        // First split sprites into groups based on atlas name
        var atlasGroups =
            from e in entries
            group e by e.atlasName;

        foreach (var atlasGroup in atlasGroups)
        {
            int page = 0;
            // Then split those groups into smaller groups based on texture settings
            var settingsGroups =
                from t in atlasGroup
                group t by t.settings;
            foreach (var settingsGroup in settingsGroups)
            {
                string atlasName = atlasGroup.Key;
                if (settingsGroups.Count() > 1)
                {
                    atlasName += string.Format(" (Group {0})", page);
                }

                UnityEditor.Sprites.AtlasSettings settings = settingsGroup.Key;
                settings.anisoLevel = 1;
                // Use the highest aniso level from all entries in this atlas
                if (settings.generateMipMaps)
                {
                    foreach (Entry entry in settingsGroup)
                    {
                        if (entry.anisoLevel > settings.anisoLevel)
                        {
                            settings.anisoLevel = entry.anisoLevel;
                        }
                    }
                }

                job.AddAtlas(atlasName, settings);
                foreach (Entry entry in settingsGroup)
                {
                    job.AssignToAtlas(atlasName, entry.sprite, entry.packingMode, SpritePackingRotation.None);
                }

                ++page;
            }
        }
    }
		public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
		{
			List<DefaultPackerPolicy.Entry> list = new List<DefaultPackerPolicy.Entry>();
			for (int i = 0; i < textureImporterInstanceIDs.Length; i++)
			{
				int instanceID = textureImporterInstanceIDs[i];
				TextureImporter textureImporter = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter;
				TextureFormat format;
				ColorSpace colorSpace;
				int compressionQuality;
				textureImporter.ReadTextureImportInstructions(target, out format, out colorSpace, out compressionQuality);
				TextureImporterSettings textureImporterSettings = new TextureImporterSettings();
				textureImporter.ReadTextureSettings(textureImporterSettings);
				Sprite[] array = (
					from x in AssetDatabase.LoadAllAssetRepresentationsAtPath(textureImporter.assetPath)
					select x as Sprite into x
					where x != null
					select x).ToArray<Sprite>();
				Sprite[] array2 = array;
				for (int j = 0; j < array2.Length; j++)
				{
					Sprite sprite = array2[j];
					DefaultPackerPolicy.Entry entry = new DefaultPackerPolicy.Entry();
					entry.sprite = sprite;
					entry.settings.format = format;
					entry.settings.colorSpace = colorSpace;
					entry.settings.compressionQuality = compressionQuality;
					entry.settings.filterMode = ((!Enum.IsDefined(typeof(FilterMode), textureImporter.filterMode)) ? FilterMode.Bilinear : textureImporter.filterMode);
					entry.settings.maxWidth = 2048;
					entry.settings.maxHeight = 2048;
					entry.settings.generateMipMaps = textureImporter.mipmapEnabled;
					if (textureImporter.mipmapEnabled)
					{
						entry.settings.paddingPower = 2u;
					}
					entry.atlasName = this.ParseAtlasName(textureImporter.spritePackingTag);
					entry.packingMode = this.GetPackingMode(textureImporter.spritePackingTag, textureImporterSettings.spriteMeshType);
					entry.anisoLevel = textureImporter.anisoLevel;
					list.Add(entry);
				}
				Resources.UnloadAsset(textureImporter);
			}
			IEnumerable<IGrouping<string, DefaultPackerPolicy.Entry>> enumerable = 
				from e in list
				group e by e.atlasName;
			foreach (IGrouping<string, DefaultPackerPolicy.Entry> current in enumerable)
			{
				int num = 0;
				IEnumerable<IGrouping<AtlasSettings, DefaultPackerPolicy.Entry>> enumerable2 = 
					from t in current
					group t by t.settings;
				foreach (IGrouping<AtlasSettings, DefaultPackerPolicy.Entry> current2 in enumerable2)
				{
					string text = current.Key;
					if (enumerable2.Count<IGrouping<AtlasSettings, DefaultPackerPolicy.Entry>>() > 1)
					{
						text += string.Format(" (Group {0})", num);
					}
					AtlasSettings key = current2.Key;
					key.anisoLevel = 1;
					if (key.generateMipMaps)
					{
						foreach (DefaultPackerPolicy.Entry current3 in current2)
						{
							if (current3.anisoLevel > key.anisoLevel)
							{
								key.anisoLevel = current3.anisoLevel;
							}
						}
					}
					job.AddAtlas(text, key);
					foreach (DefaultPackerPolicy.Entry current4 in current2)
					{
						job.AssignToAtlas(text, current4.sprite, current4.packingMode, SpritePackingRotation.None);
					}
					num++;
				}
			}
		}
        public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
        {
            List <Entry> list = new List <Entry>();

            string text = "";

            if (target != BuildTarget.NoTarget)
            {
                text = target.ToString();
            }

            for (int i = 0; i < textureImporterInstanceIDs.Length; i++)
            {
                TextureFormat textureFormat;
                ColorSpace    colorSpace;
                int           compressionQuality;

                int instanceID = textureImporterInstanceIDs[i];

                TextureImporter textureImporter = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter;
                textureImporter.ReadTextureImportInstructions(target, out textureFormat, out colorSpace, out compressionQuality);

                TextureImporterSettings textureImporterSettings = new TextureImporterSettings();
                textureImporter.ReadTextureSettings(textureImporterSettings);

                bool flag = text != "" && this.HasPlatformEnabledAlphaSplittingForCompression(text, textureImporter);

                Sprite[] array = (from x in AssetDatabase.LoadAllAssetRepresentationsAtPath(textureImporter.assetPath)
                                  select x as Sprite into x
                                  where x != null
                                  select x).ToArray <Sprite>();
                Sprite[] array2 = array;

                for (int j = 0; j < array2.Length; j++)
                {
                    Sprite sprite = array2[j];

                    Entry entry = new Entry();

                    entry.sprite                        = sprite;
                    entry.settings.format               = textureFormat;
                    entry.settings.colorSpace           = colorSpace;
                    entry.settings.compressionQuality   = compressionQuality;
                    entry.settings.filterMode           = ((!Enum.IsDefined(typeof(FilterMode), textureImporter.filterMode)) ? FilterMode.Bilinear : textureImporter.filterMode);
                    entry.settings.maxWidth             = atlasMaxWidth;
                    entry.settings.maxHeight            = atlasMaxHeight;
                    entry.settings.generateMipMaps      = textureImporter.mipmapEnabled;
                    entry.settings.enableRotation       = this.AllowRotationFlipping;
                    entry.settings.allowsAlphaSplitting = (textureFormat == TextureFormat.ETC_RGB4 && flag);

                    if (textureImporter.mipmapEnabled)
                    {
                        entry.settings.paddingPower = kDefaultPaddingPower;
                    }
                    else
                    {
                        entry.settings.paddingPower = ( uint )EditorSettings.spritePackerPaddingPower;
                    }

                    entry.atlasName   = this.ParseAtlasName(textureImporter.spritePackingTag);
                    entry.packingMode = this.GetPackingMode(textureImporter.spritePackingTag, textureImporterSettings.spriteMeshType);
                    entry.anisoLevel  = textureImporter.anisoLevel;

                    list.Add(entry);
                }

                Resources.UnloadAsset(textureImporter);
            }

            IEnumerable <IGrouping <string, Entry> > enumerable = from e in list
                                                                  group e by e.atlasName;

            foreach (IGrouping <string, Entry> current in enumerable)
            {
                int num2 = 0;
                IEnumerable <IGrouping <AtlasSettings, Entry> > enumerable2 = from t in current
                                                                              group t by t.settings;
                foreach (IGrouping <AtlasSettings, Entry> current2 in enumerable2)
                {
                    string text2 = current.Key;

                    if (enumerable2.Count <IGrouping <AtlasSettings, Entry> >() > 1)
                    {
                        text2 += string.Format(" (Group {0})", num2);
                    }

                    AtlasSettings key = current2.Key;
                    key.anisoLevel = 1;

                    if (key.generateMipMaps)
                    {
                        foreach (Entry current3 in current2)
                        {
                            if (current3.anisoLevel > key.anisoLevel)
                            {
                                key.anisoLevel = current3.anisoLevel;
                            }
                        }
                    }

                    job.AddAtlas(text2, key);

                    foreach (Entry current4 in current2)
                    {
                        job.AssignToAtlas(text2, current4.sprite, current4.packingMode, SpritePackingRotation.None);
                    }

                    num2++;
                }
            }
        }
Пример #10
0
 public void AddAtlas(string atlasName, AtlasSettings settings)
 {
     PackerJob.Internal_AddAtlas(atlasName, settings);
 }
Пример #11
0
 private static void Internal_AddAtlas(string atlasName, AtlasSettings settings)
 {
     PackerJob.Internal_AddAtlas_Injected(atlasName, ref settings);
 }
        public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
        {
            List <DefaultPackerPolicy.Entry> source1 = new List <DefaultPackerPolicy.Entry>();

            foreach (int importerInstanceId in textureImporterInstanceIDs)
            {
                TextureImporter textureImporter = EditorUtility.InstanceIDToObject(importerInstanceId) as TextureImporter;
                TextureFormat   desiredFormat;
                ColorSpace      colorSpace;
                int             compressionQuality;
                textureImporter.ReadTextureImportInstructions(target, out desiredFormat, out colorSpace, out compressionQuality);
                TextureImporterSettings dest = new TextureImporterSettings();
                textureImporter.ReadTextureSettings(dest);
                foreach (Sprite sprite in ((IEnumerable <UnityEngine.Object>)AssetDatabase.LoadAllAssetRepresentationsAtPath(textureImporter.assetPath)).Select <UnityEngine.Object, Sprite>((Func <UnityEngine.Object, Sprite>)(x => x as Sprite)).Where <Sprite>((Func <Sprite, bool>)(x => (UnityEngine.Object)x != (UnityEngine.Object)null)).ToArray <Sprite>())
                {
                    source1.Add(new DefaultPackerPolicy.Entry()
                    {
                        sprite   = sprite,
                        settings =
                        {
                            format               = desiredFormat,
                            colorSpace           = colorSpace,
                            compressionQuality   = !TextureUtil.IsCompressedTextureFormat(desiredFormat) ? 0 : compressionQuality,
                            filterMode           = !Enum.IsDefined(typeof(UnityEngine.FilterMode),                                (object)textureImporter.filterMode) ? UnityEngine.FilterMode.Bilinear : textureImporter.filterMode,
                            maxWidth             =                                                                           2048,
                            maxHeight            =                                                                           2048,
                            generateMipMaps      = textureImporter.mipmapEnabled,
                            enableRotation       = this.AllowRotationFlipping,
                            allowsAlphaSplitting = textureImporter.GetAllowsAlphaSplitting(),
                            paddingPower         = !textureImporter.mipmapEnabled ? (uint)EditorSettings.spritePackerPaddingPower : 3U
                        },
                        atlasName   = this.ParseAtlasName(textureImporter.spritePackingTag),
                        packingMode = this.GetPackingMode(textureImporter.spritePackingTag, dest.spriteMeshType),
                        anisoLevel  = textureImporter.anisoLevel
                    });
                }
                Resources.UnloadAsset((UnityEngine.Object)textureImporter);
            }
            foreach (IGrouping <string, DefaultPackerPolicy.Entry> source2 in source1.GroupBy <DefaultPackerPolicy.Entry, string, DefaultPackerPolicy.Entry>((Func <DefaultPackerPolicy.Entry, string>)(e => e.atlasName), (Func <DefaultPackerPolicy.Entry, DefaultPackerPolicy.Entry>)(e => e)))
            {
                int num = 0;
                IEnumerable <IGrouping <AtlasSettings, DefaultPackerPolicy.Entry> > source3 = source2.GroupBy <DefaultPackerPolicy.Entry, AtlasSettings, DefaultPackerPolicy.Entry>((Func <DefaultPackerPolicy.Entry, AtlasSettings>)(t => t.settings), (Func <DefaultPackerPolicy.Entry, DefaultPackerPolicy.Entry>)(t => t));
                foreach (IGrouping <AtlasSettings, DefaultPackerPolicy.Entry> grouping in source3)
                {
                    string key1 = source2.Key;
                    if (source3.Count <IGrouping <AtlasSettings, DefaultPackerPolicy.Entry> >() > 1)
                    {
                        key1 += string.Format(" (Group {0})", (object)num);
                    }
                    AtlasSettings key2 = grouping.Key;
                    key2.anisoLevel = 1;
                    if (key2.generateMipMaps)
                    {
                        foreach (DefaultPackerPolicy.Entry entry in (IEnumerable <DefaultPackerPolicy.Entry>)grouping)
                        {
                            if (entry.anisoLevel > key2.anisoLevel)
                            {
                                key2.anisoLevel = entry.anisoLevel;
                            }
                        }
                    }
                    job.AddAtlas(key1, key2);
                    foreach (DefaultPackerPolicy.Entry entry in (IEnumerable <DefaultPackerPolicy.Entry>)grouping)
                    {
                        job.AssignToAtlas(key1, entry.sprite, entry.packingMode, SpritePackingRotation.None);
                    }
                    ++num;
                }
            }
        }
Пример #13
0
    public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
    {
        var entries = new List<Entry>();

        foreach (int instanceID in textureImporterInstanceIDs)
        {
            var ti = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter;
            TextureFormat textureFormat;
            ColorSpace colorSpace;
            int compressionQuality;
            if (ti == null)
                continue;
            ti.ReadTextureImportInstructions(target, out textureFormat, out colorSpace, out compressionQuality);

            var tis = new TextureImporterSettings();
            ti.ReadTextureSettings(tis);
            ti.isReadable = true;
            tis.readable = true;

            Sprite[] sprites = AssetDatabase.LoadAllAssetRepresentationsAtPath(ti.assetPath).Select(x => x as Sprite).Where(x => x != null).ToArray();

            foreach (Sprite sprite in sprites)
            {
                var entry = new Entry();
                entry.sprite = sprite;
                entry.settings.format = textureFormat;
                entry.settings.colorSpace = colorSpace;
                entry.settings.compressionQuality = compressionQuality;
                entry.settings.filterMode = Enum.IsDefined(typeof(FilterMode), ti.filterMode) ? ti.filterMode : FilterMode.Bilinear;
                entry.settings.maxWidth = 2048;
                entry.settings.maxHeight = 2048;
                entry.settings.generateMipMaps = ti.mipmapEnabled;
                if (ti.mipmapEnabled)
                    entry.settings.paddingPower = kDefaultPaddingPower;
                entry.atlasName = ParseAtlasName(ti.spritePackingTag);
                entry.packingMode = GetPackingMode(ti.spritePackingTag, tis.spriteMeshType);
                entry.anisoLevel = ti.anisoLevel;

                entries.Add(entry);
            }

            Resources.UnloadAsset(ti);

            foreach (var sprite in sprites)
            {
                var m_tex = sprite.texture;
                AlphaMapCreater.Create(m_tex);
            }
        }

        // First split sprites into groups based on atlas name
        var atlasGroups =
            from e in entries
            group e by e.atlasName;
        foreach (var atlasGroup in atlasGroups)
        {
            int page = 0;
            // Then split those groups into smaller groups based on texture settings
            var settingsGroups =
                from t in atlasGroup
                group t by t.settings;
            foreach (var settingsGroup in settingsGroups)
            {
                string atlasName = atlasGroup.Key;
                if (settingsGroups.Count() > 1)
                    atlasName += string.Format(" (Group {0})", page);

                AtlasSettings settings = settingsGroup.Key;
                settings.anisoLevel = 1;

                // Use the highest aniso level from all entries in this atlas
                if (settings.generateMipMaps)
                    foreach (Entry entry in settingsGroup)
                        if (entry.anisoLevel > settings.anisoLevel)
                            settings.anisoLevel = entry.anisoLevel;

                job.AddAtlas(atlasName, settings);

                foreach (Entry entry in settingsGroup)
                {
                    job.AssignToAtlas(atlasName, entry.sprite, entry.packingMode, SpritePackingRotation.None);
                }

                ++page;
            }

        }
    }
Пример #14
0
    public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs) {
        List<Entry> entries = new List<Entry>();

        foreach (int instanceID in textureImporterInstanceIDs) {
            TextureImporter ti = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter;
            var texture = AssetDatabase.LoadAssetAtPath(ti.assetPath, typeof(Texture2D)) as Texture2D;
            int paddingPower = ComputePaddingPower(texture);
            

#if UNITY_4_6
            TextureImportInstructions ins = new TextureImportInstructions();
            ti.ReadTextureImportInstructions(ins, target);
#else // Unity 5
            ColorSpace colorSpace;
            int compression;
            TextureFormat format;
            
            ti.ReadTextureImportInstructions(target, out format, out colorSpace, out compression);
            TextureImporterSettings tis = new TextureImporterSettings();
            ti.ReadTextureSettings(tis);
#endif


            Sprite[] sprites = AssetDatabase.LoadAllAssetRepresentationsAtPath(ti.assetPath).Select(x => x as Sprite).Where(x => x != null).ToArray();
            foreach (Sprite sprite in sprites) {
                Entry entry = new Entry();
                entry.sprite = sprite;

#if UNITY_4_6
                entry.settings.format = ins.desiredFormat;
                entry.settings.usageMode = TextureUsageMode.Default;
                entry.settings.colorSpace = ins.colorSpace;
                entry.settings.compressionQuality = ins.compressionQuality;
#else // Unity 5
                entry.settings.format = format;
                entry.settings.colorSpace = colorSpace;
                entry.settings.compressionQuality = compression;
#endif

                entry.settings.filterMode = Enum.IsDefined(typeof(FilterMode), ti.filterMode) ? ti.filterMode : FilterMode.Bilinear;
                entry.settings.maxWidth = 2048;
                entry.settings.maxHeight = 2048;
                entry.settings.generateMipMaps = ti.mipmapEnabled;
                //if (ti.mipmapEnabled)
                entry.paddingPower = (uint)paddingPower;

                // using padding power group as a hack to group sprites with similar padding power
                entry.settings.paddingPower = PaddingPowerGroup(paddingPower);
                Debug.Log("Groupping " + paddingPower + " to " + entry.settings.paddingPower);

                entry.atlasName = ParseAtlasName(ti.spritePackingTag);
                entry.packingMode = SpritePackingMode.Rectangle;
                entry.anisoLevel = ti.anisoLevel;

                entries.Add(entry);
            }

            Resources.UnloadAsset(ti);
            Resources.UnloadAsset(texture);
        }

        // First split sprites into groups based on atlas name
        var atlasGroups =
        from e in entries
        group e by e.atlasName;
        foreach (var atlasGroup in atlasGroups) {
            int page = 0;
            // Then split those groups into smaller groups based on texture settings
            var settingsGroup =
            from t in atlasGroup
            group t by t.settings;

            foreach (var settingGroup in settingsGroup) {
                string atlasName = atlasGroup.Key;
                if (page > 0)
                    atlasName += string.Format(" (Group {0})", page);

                AtlasSettings settings = settingGroup.Key;

                settings.anisoLevel = 1;
                // Use the highest aniso level from all entries in this atlas
                if (settings.generateMipMaps)
                    foreach (Entry entry in settingGroup)
                        if (entry.anisoLevel > settings.anisoLevel)
                            settings.anisoLevel = entry.anisoLevel;

                // apply now the padding power because grouping would fail earlier
                uint biggest = BiggestPadding(settingGroup);
                settings.paddingPower = biggest;

                job.AddAtlas(atlasName, settings);

                foreach (Entry entry in settingGroup) {
                    job.AssignToAtlas(atlasName, entry.sprite, SpritePackingMode.Rectangle, SpritePackingRotation.None);
                }

                ++page;
            }
        }
    }
Пример #15
0
        public void OnGroupAtlases(BuildTarget target, PackerJob job, int[] textureImporterInstanceIDs)
        {
            List <DefaultPackerPolicy.Entry> list = new List <DefaultPackerPolicy.Entry>();

            for (int i = 0; i < textureImporterInstanceIDs.Length; i++)
            {
                int             instanceID      = textureImporterInstanceIDs[i];
                TextureImporter textureImporter = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter;
                TextureFormat   format;
                ColorSpace      colorSpace;
                int             compressionQuality;
                textureImporter.ReadTextureImportInstructions(target, out format, out colorSpace, out compressionQuality);
                TextureImporterSettings textureImporterSettings = new TextureImporterSettings();
                textureImporter.ReadTextureSettings(textureImporterSettings);
                Sprite[] array = (
                    from x in AssetDatabase.LoadAllAssetRepresentationsAtPath(textureImporter.assetPath)
                    select x as Sprite into x
                    where x != null
                    select x).ToArray <Sprite>();
                Sprite[] array2 = array;
                for (int j = 0; j < array2.Length; j++)
                {
                    Sprite sprite = array2[j];
                    DefaultPackerPolicy.Entry entry = new DefaultPackerPolicy.Entry();
                    entry.sprite                      = sprite;
                    entry.settings.format             = format;
                    entry.settings.colorSpace         = colorSpace;
                    entry.settings.compressionQuality = compressionQuality;
                    entry.settings.filterMode         = ((!Enum.IsDefined(typeof(FilterMode), textureImporter.filterMode)) ? FilterMode.Bilinear : textureImporter.filterMode);
                    entry.settings.maxWidth           = 2048;
                    entry.settings.maxHeight          = 2048;
                    entry.settings.generateMipMaps    = textureImporter.mipmapEnabled;
                    if (textureImporter.mipmapEnabled)
                    {
                        entry.settings.paddingPower = 2u;
                    }
                    entry.atlasName   = this.ParseAtlasName(textureImporter.spritePackingTag);
                    entry.packingMode = this.GetPackingMode(textureImporter.spritePackingTag, textureImporterSettings.spriteMeshType);
                    entry.anisoLevel  = textureImporter.anisoLevel;
                    list.Add(entry);
                }
                Resources.UnloadAsset(textureImporter);
            }
            IEnumerable <IGrouping <string, DefaultPackerPolicy.Entry> > enumerable =
                from e in list
                group e by e.atlasName;

            foreach (IGrouping <string, DefaultPackerPolicy.Entry> current in enumerable)
            {
                int num = 0;
                IEnumerable <IGrouping <AtlasSettings, DefaultPackerPolicy.Entry> > enumerable2 =
                    from t in current
                    group t by t.settings;
                foreach (IGrouping <AtlasSettings, DefaultPackerPolicy.Entry> current2 in enumerable2)
                {
                    string text = current.Key;
                    if (enumerable2.Count <IGrouping <AtlasSettings, DefaultPackerPolicy.Entry> >() > 1)
                    {
                        text += string.Format(" (Group {0})", num);
                    }
                    AtlasSettings key = current2.Key;
                    key.anisoLevel = 1;
                    if (key.generateMipMaps)
                    {
                        foreach (DefaultPackerPolicy.Entry current3 in current2)
                        {
                            if (current3.anisoLevel > key.anisoLevel)
                            {
                                key.anisoLevel = current3.anisoLevel;
                            }
                        }
                    }
                    job.AddAtlas(text, key);
                    foreach (DefaultPackerPolicy.Entry current4 in current2)
                    {
                        job.AssignToAtlas(text, current4.sprite, current4.packingMode, SpritePackingRotation.None);
                    }
                    num++;
                }
            }
        }
Пример #16
0
 public void AssignToAtlas(string atlasName, Sprite sprite, SpritePackingMode packingMode, SpritePackingRotation packingRotation)
 {
     PackerJob.Internal_AssignToAtlas(atlasName, sprite, packingMode, packingRotation);
 }
    public void OnGroupAtlases(BuildTarget target, UnityEditor.Sprites.PackerJob job, int[] textureImporterInstanceIDs)
    {
        List <Entry> entries = new List <Entry>();

        foreach (int instanceID in textureImporterInstanceIDs)
        {
            TextureImporter ti = EditorUtility.InstanceIDToObject(instanceID) as TextureImporter;

            TextureFormat desiredFormat;
            ColorSpace    colorSpace;
            int           compressionQuality;
            ti.ReadTextureImportInstructions(target, out desiredFormat, out colorSpace, out compressionQuality);

            TextureImporterSettings tis = new TextureImporterSettings();
            ti.ReadTextureSettings(tis);

            Sprite[] sprites =
                AssetDatabase.LoadAllAssetRepresentationsAtPath(ti.assetPath)
                .Select(x => x as Sprite)
                .Where(x => x != null)
                .ToArray();
            foreach (Sprite sprite in sprites)
            {
                Entry entry = new Entry();
                entry.sprite              = sprite;
                entry.settings.format     = desiredFormat;
                entry.settings.colorSpace = colorSpace;
                // Use Compression Quality for Grouping later only for Compressed Formats. Otherwise leave it Empty.
                entry.settings.compressionQuality = IsCompressedFormat(desiredFormat) ? compressionQuality : 0;
                entry.settings.filterMode         = Enum.IsDefined(typeof(FilterMode), ti.filterMode)
                                        ? ti.filterMode
                                        : FilterMode.Bilinear;
                entry.settings.maxWidth        = 2048;
                entry.settings.maxHeight       = 2048;
                entry.settings.generateMipMaps = ti.mipmapEnabled;
                entry.settings.enableRotation  = AllowRotationFlipping;
                if (ti.mipmapEnabled)
                {
                    entry.settings.paddingPower = kDefaultPaddingPower;
                }
                else
                {
                    entry.settings.paddingPower = (uint)EditorSettings.spritePackerPaddingPower;
                }
                                #if ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION
                //закомменчено, чтобы спрайты не попадали в разные группы
                //entry.settings.allowsAlphaSplitting = ti.GetAllowsAlphaSplitting ();
                                #endif //ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION

                entry.atlasName   = ParseAtlasName(ti.spritePackingTag);
                entry.packingMode = GetPackingMode(ti.spritePackingTag, tis.spriteMeshType);
                //anisoLevel не важен
                entry.anisoLevel = ti.anisoLevel;
                //entry.anisoLevel = 0;
                //Debug.Log (entry.settings.generateMipMaps);

#if UNITY_IOS
                entry.settings.generateMipMaps = false;
#else
                //entry.settings.generateMipMaps = true;
                //ti.mipmapFilter = TextureImporterMipFilter.KaiserFilter;
#endif
                entries.Add(entry);

                if (entry.sprite.name == "pixel" || entry.sprite.name == "button icon music")
                {
                    Debug.Log(entry.sprite.name);
                    Debug.Log(entry.settings.format);
                    Debug.Log(entry.settings.colorSpace);
                    Debug.Log(entry.settings.compressionQuality);
                    Debug.Log(entry.settings.filterMode);
                    Debug.Log(entry.settings.paddingPower);
                    Debug.Log(entry.settings.allowsAlphaSplitting);
                    Debug.Log(entry.atlasName);
                    Debug.Log(entry.packingMode);
                    Debug.Log(entry.anisoLevel);
                    Debug.Log(entry.settings.generateMipMaps);
                    //entry.settings.filterMode
                }
            }

            Resources.UnloadAsset(ti);
        }

        // First split sprites into groups based on atlas name
        var atlasGroups =
            from e in entries
            group e by e.atlasName;
        foreach (var atlasGroup in atlasGroups)
        {
            int page = 0;
            // Then split those groups into smaller groups based on texture settings
            var settingsGroups =
                from t in atlasGroup
                group t by t.settings;
            foreach (var settingsGroup in settingsGroups)
            {
                string atlasName = atlasGroup.Key;
                if (settingsGroups.Count() > 1)
                {
                    atlasName += string.Format(" (Group {0})", page);
                }
                //Debug.Log (atlasName);
                UnityEditor.Sprites.AtlasSettings settings = settingsGroup.Key;
                settings.anisoLevel = 1;
                // Use the highest aniso level from all entries in this atlas
                if (settings.generateMipMaps)
                {
                    foreach (Entry entry in settingsGroup)
                    {
                        if (entry.anisoLevel > settings.anisoLevel)
                        {
                            settings.anisoLevel = entry.anisoLevel;
                        }
                    }
                }

                job.AddAtlas(atlasName, settings);
                foreach (Entry entry in settingsGroup)
                {
                    job.AssignToAtlas(atlasName, entry.sprite, entry.packingMode, SpritePackingRotation.None);
                }

                ++page;
            }
        }
    }