Describes the final atlas texture.

コード例 #1
0
 /// <summary>
 /// <para>Registers a new atlas.</para>
 /// </summary>
 /// <param name="atlasName"></param>
 /// <param name="settings"></param>
 public void AddAtlas(string atlasName, AtlasSettings settings)
 {
     this.AddAtlas_Internal(atlasName, ref settings);
 }
コード例 #2
0
 private extern void AddAtlas_Internal(string atlasName, ref AtlasSettings settings);
コード例 #3
0
 public void AddAtlas(string atlasName, AtlasSettings settings)
 {
     Internal_AddAtlas(atlasName, settings);
 }
コード例 #4
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++;
                }
            }
        }
コード例 #5
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;
            }
        }
    }
コード例 #6
0
 private static extern void Internal_AddAtlas(string atlasName, AtlasSettings settings);
コード例 #7
0
 public void AddAtlas(string atlasName, AtlasSettings settings)
 {
     this.AddAtlas_Internal(atlasName, ref settings);
 }
コード例 #8
0
 private extern void AddAtlas_Internal(string atlasName, ref AtlasSettings settings);
コード例 #9
0
 private static void Internal_AddAtlas(string atlasName, AtlasSettings settings)
 {
     PackerJob.Internal_AddAtlas_Injected(atlasName, ref settings);
 }
コード例 #10
0
 private static extern void Internal_AddAtlas_Injected(string atlasName, ref AtlasSettings settings);
コード例 #11
0
        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;
                }
            }
        }
コード例 #12
0
		public extern void AddAtlas(string atlasName, AtlasSettings settings);
コード例 #13
0
        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++;
                }
            }
        }
コード例 #14
0
ファイル: PackerJob.cs プロジェクト: zhkuang/UnityDecompiled
 public extern void AddAtlas(string atlasName, AtlasSettings settings);
コード例 #15
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        = 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;
            }
        }
    }