Example #1
0
        static void CheckPrefabBySelect()
        {
            var atlasSprites = EditorResourcePaths.GetAllSpriteFilesInAtlas();

            foreach (string file in EditorResourcePaths.GetFileSelections())
            {
                if (file.EndsWith(".prefab"))
                {
                    var sprites = EditorResourcePaths.GetDependencies(new string[] { file }, EditorResourcePaths.PNG_REGEX);
                    foreach (var sprite in sprites)
                    {
                        if (!atlasSprites.Contains(sprite))
                        {
                            DebugUtil.LogWarning(file + " 包含散图 " + sprite);
                        }
                    }
                }
            }
        }
Example #2
0
        static void HandleSpriteAtlasFormat(HashSet <string> atlasFiles)
        {
            string[]      atlasFileArray   = new string[ATLAS_TYPE_NUMBER];
            SpriteAtlas[] spriteAtlasArray = new SpriteAtlas[ATLAS_TYPE_NUMBER];
            SpriteAtlasPackingSettings[] packingSettingsArray = new SpriteAtlasPackingSettings[ATLAS_TYPE_NUMBER];
            SpriteAtlasTextureSettings[] textureSettingsArray = new SpriteAtlasTextureSettings[ATLAS_TYPE_NUMBER];
            Dictionary <string, TextureImporterPlatformSettings>[] platformSettingsDictArray = new Dictionary <string, TextureImporterPlatformSettings> [ATLAS_TYPE_NUMBER];
            platformSettingsDictArray[0] = new Dictionary <string, TextureImporterPlatformSettings>();
            platformSettingsDictArray[1] = new Dictionary <string, TextureImporterPlatformSettings>();

            foreach (string file in atlasFiles)
            {
                if (file.EndsWith(LOW_ATLAS_SUFFIX))
                {
                    continue;
                }

                atlasFileArray[0] = file;
                atlasFileArray[1] = file.Replace(EditorResourcePaths.ATLAS_SUFFIX, LOW_ATLAS_SUFFIX);

                for (int i = 0; i < ATLAS_TYPE_NUMBER; i++)
                {
                    spriteAtlasArray[i]     = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(atlasFileArray[i]);
                    packingSettingsArray[i] = SpriteAtlasExtensions.GetPackingSettings(spriteAtlasArray[i]);
                    textureSettingsArray[i] = SpriteAtlasExtensions.GetTextureSettings(spriteAtlasArray[i]);
                    foreach (string platform in PLATFORMS)
                    {
                        platformSettingsDictArray[i][platform] = SpriteAtlasExtensions.GetPlatformSettings(spriteAtlasArray[i], platform);
                    }
                }

                HashSet <string> spriteSet    = EditorResourcePaths.GetDependencies(atlasFileArray, EditorResourcePaths.PNG_REGEX);
                bool             containAlpha = false;
                foreach (string spriteFile in spriteSet)
                {
                    Texture2D texture = EditorCommonUtils.ReadTexture(spriteFile);
                    if (ContainAlpha(texture))
                    {
                        containAlpha = true;
                        break;
                    }
                }

                for (int i = 0; i < ATLAS_TYPE_NUMBER; i++)
                {
                    packingSettingsArray[i].enableRotation     = false;
                    packingSettingsArray[i].enableTightPacking = false;
                    SetDefaultTextureSettings(ref textureSettingsArray[i]);
                }

                if (containAlpha)
                {
                    SetPlatformTextureSettings(platformSettingsDictArray[0]["Default"], "Default", TextureImporterFormat.RGBA32);
                    SetPlatformTextureSettings(platformSettingsDictArray[0]["Standalone"], "Standalone", TextureImporterFormat.DXT5);
                    SetPlatformTextureSettings(platformSettingsDictArray[0]["Android"], "Android", TextureImporterFormat.ETC2_RGBA8);
                    SetPlatformTextureSettings(platformSettingsDictArray[0]["iPhone"], "iPhone", IOS_NEW_RGBA);

                    SetPlatformTextureSettings(platformSettingsDictArray[1]["Default"], "Default", TextureImporterFormat.RGBA32);
                    SetPlatformTextureSettings(platformSettingsDictArray[1]["Standalone"], "Standalone", TextureImporterFormat.DXT5Crunched);
                    SetPlatformTextureSettings(platformSettingsDictArray[1]["Android"], "Android", TextureImporterFormat.ETC2_RGBA8Crunched);
                    SetPlatformTextureSettings(platformSettingsDictArray[1]["iPhone"], "iPhone", TextureImporterFormat.PVRTC_RGBA4);
                }
                else
                {
                    SetPlatformTextureSettings(platformSettingsDictArray[0]["Default"], "Default", TextureImporterFormat.RGB24);
                    SetPlatformTextureSettings(platformSettingsDictArray[0]["Standalone"], "Standalone", TextureImporterFormat.DXT1);
                    SetPlatformTextureSettings(platformSettingsDictArray[0]["Android"], "Android", TextureImporterFormat.ETC2_RGB4);
                    SetPlatformTextureSettings(platformSettingsDictArray[0]["iPhone"], "iPhone", TextureImporterFormat.PVRTC_RGB4);

                    SetPlatformTextureSettings(platformSettingsDictArray[1]["Default"], "Default", TextureImporterFormat.RGB24);
                    SetPlatformTextureSettings(platformSettingsDictArray[1]["Standalone"], "Standalone", TextureImporterFormat.DXT1Crunched);
                    SetPlatformTextureSettings(platformSettingsDictArray[1]["Android"], "Android", TextureImporterFormat.ETC_RGB4Crunched);
                    SetPlatformTextureSettings(platformSettingsDictArray[1]["iPhone"], "iPhone", TextureImporterFormat.PVRTC_RGB4);
                }

                for (int i = 0; i < ATLAS_TYPE_NUMBER; i++)
                {
                    SpriteAtlasExtensions.SetIncludeInBuild(spriteAtlasArray[i], false);
                    SpriteAtlasExtensions.SetPackingSettings(spriteAtlasArray[i], packingSettingsArray[i]);
                    SpriteAtlasExtensions.SetTextureSettings(spriteAtlasArray[i], textureSettingsArray[i]);
                    foreach (string platform in PLATFORMS)
                    {
                        SpriteAtlasExtensions.SetPlatformSettings(spriteAtlasArray[i], platformSettingsDictArray[i][platform]);
                    }
                }
                SpriteAtlasExtensions.SetIsVariant(spriteAtlasArray[1], false);
                SpriteAtlasExtensions.Remove(spriteAtlasArray[1], SpriteAtlasExtensions.GetPackables(spriteAtlasArray[1]));
                SpriteAtlasExtensions.Add(spriteAtlasArray[1], SpriteAtlasExtensions.GetPackables(spriteAtlasArray[0]));
            }
            AssetDatabase.Refresh();
        }