示例#1
0
        public void DrawResults(SpriteDatabase spriteDatabase)
        {
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, false, false);

            DrawResultsInternal(spriteDatabase);
            EditorGUILayout.EndScrollView();
        }
示例#2
0
        public override void GenerateResults(SpriteDatabase spriteDatabase)
        {
            if (spriteDatabase?.SpritesData == null)
            {
                return;
            }


            atlasToUsedSprites.Clear();
            atlasToNotUsedSprites.Clear();

            filteredAtlas = AtlasCacheUtility.GetAllKnowAtlases().Where(atlas => MatchFilter(atlas, spriteDatabase))
                            .OrderBy(atlas => atlas.name).ToArray();

            SpriteData[] validSprites = spriteDatabase.SpritesData.Where(ValidSpriteData).Where(data => data.IsInsideAtlas())
                                        .OrderBy(data => data.Sprite.name).ToArray();

            for (int i = 0; i < filteredAtlas.Length; i++)
            {
                SpriteAtlas atlas = filteredAtlas[i];

                SpriteData[] usedSpritesFromThisAtlas =
                    validSprites.Where(data =>
                                       data.IsInsideAtlas() && data.SpriteAtlas == atlas && MatchSearch(data.Sprite.name)).ToArray();
                atlasToUsedSprites.Add(atlas, usedSpritesFromThisAtlas);
                Sprite[] spritesInsideAtlas = AtlasCacheUtility.GetAllSpritesFromAtlas(atlas)
                                              .Where(sprite => MatchSearch(sprite.name)).ToArray();

                Sprite[] notUSedSprites =
                    spritesInsideAtlas.Where(sprite => usedSpritesFromThisAtlas.All(data => data.Sprite != sprite)).ToArray();

                atlasToNotUsedSprites.Add(atlas, notUSedSprites);
            }
        }
        private void LoadOrCreateDatabase()
        {
            string storedJson = EditorPrefs.GetString(ATLAS_AUDITOR_STORAGE_KEY, string.Empty);

            cachedSpriteDatabase = new SpriteDatabase();

            if (!string.IsNullOrEmpty(storedJson))
            {
                JsonWrapper.FromJson(storedJson, ref cachedSpriteDatabase);
            }

            spriteFinder.SetResult(SpriteDatabase);
            SpriteAuditorUtility.ClearMemoryDataDirty();
        }
        private void StartRecording()
        {
            if (isRecording)
            {
                return;
            }
            isRecording = true;

            AtlasCacheUtility.ClearAtlasCache();
            LoadOrCreateAtlasResult();
            SpriteDatabase.PrepareForRun();

            GameObject spriteAuditorGameObject = new GameObject("Sprite Auditor Forwarder");

            spriteAuditorEventForwarder = spriteAuditorGameObject.AddComponent <SpriteAuditorEventForwarder>();
            spriteAuditorEventForwarder.SetListener(spriteFinder);
            DontDestroyOnLoad(spriteAuditorEventForwarder.gameObject);
        }
        private void DrawSettings()
        {
            EditorGUI.BeginDisabledGroup(isRecording);
            EditorGUILayout.BeginVertical("Box");
            EditorGUILayout.LabelField("Settings", EditorStyles.toolbarDropDown);
            EditorGUILayout.Space();

            recordOnPlay = EditorGUILayout.Toggle("Record on play", recordOnPlay);

            EditorGUI.BeginChangeCheck();
            spriteUsageSizeThreshold =
                EditorGUILayout.Slider("Allowed Size Variation", spriteUsageSizeThreshold, 0, 2);
            if (EditorGUI.EndChangeCheck())
            {
                SpriteAuditorUtility.SetSizeCheckThreshold(spriteUsageSizeThreshold);
                SpriteDatabase.SizeCheckThresholdChanged();
                //TODO
                //SpriteDatabase.SetAllowedSizeVariation(spriteUsageSizeThreshold);
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginDisabledGroup(!EditorPrefs.HasKey(ATLAS_AUDITOR_STORAGE_KEY));
            if (GUILayout.Button("Clear Cache", EditorStyles.toolbarButton))
            {
                ClearCache();
            }

            if (GUILayout.Button("Pack Atlases", EditorStyles.toolbarButton))
            {
                SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget);
            }

            if (GUILayout.Button("Refresh Atlases", EditorStyles.toolbarButton))
            {
                AtlasCacheUtility.CacheKnowAtlases();
            }

            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            EditorGUI.EndDisabledGroup();
        }
        private void StartRecording()
        {
            if (isRecording)
            {
                return;
            }
            isRecording = true;

            LoadOrCreateDatabase();
            SpriteDatabase.PrepareForRun();

            GameObject spriteAuditorGameObject = new GameObject("Sprite Auditor Forwarder");

            spriteAuditorEventForwarder = spriteAuditorGameObject.AddComponent <SpriteAuditorEventForwarder>();
            spriteFinder.SetFrameInterval(frameInterval);
            spriteFinder.SetCaptureOnUpdate(recordOnUpdate);
            spriteAuditorEventForwarder.SetListener(spriteFinder);
            DontDestroyOnLoad(spriteAuditorEventForwarder.gameObject);
        }
示例#7
0
        public override void GenerateResults(SpriteDatabase spriteDatabase)
        {
            if (spriteDatabase?.SpritesData == null)
            {
                return;
            }

            string[]          allTextures2DGUIDs = AssetDatabase.FindAssets("t:Texture2D");
            List <SpriteData> usedSpriteDatas    = new List <SpriteData>();
            List <Sprite>     unusedSprites      = new List <Sprite>();

            foreach (string textureGUIDs in allTextures2DGUIDs)
            {
                IEnumerable <Sprite> sprites = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GUIDToAssetPath(textureGUIDs))
                                               .Where(o => o is Sprite).Cast <Sprite>();

                foreach (Sprite sprite in sprites)
                {
                    if (spriteDatabase.TryGetSpriteDataBySprite(sprite, out SpriteData spriteData))
                    {
                        if (!MatchFilter(spriteData))
                        {
                            continue;
                        }

                        usedSpriteDatas.Add(spriteData);
                    }
                    else
                    {
                        if (!MatchFilter(sprite))
                        {
                            continue;
                        }
                        unusedSprites.Add(sprite);
                    }
                }
            }

            this.unusedSprites   = unusedSprites.ToArray();
            this.usedSpriteDatas = usedSpriteDatas.ToArray();
        }
示例#8
0
        private bool MatchFilter(SpriteAtlas atlas, SpriteDatabase spriteDatabase)
        {
            if (currentFilter.HasFlag(Filter.IncludedInBuild))
            {
                if (!atlas.IsIncludedInBuild())
                {
                    return(false);
                }
            }

            if (currentFilter.HasFlag(Filter.IsVariant))
            {
                if (!atlas.isVariant)
                {
                    return(false);
                }
            }

            if (currentFilter.HasFlag(Filter.WithUsagesFound))
            {
                for (int i = 0; i < spriteDatabase.SpritesData.Count; i++)
                {
                    SpriteData spriteData = spriteDatabase.SpritesData[i];
                    if (!spriteData.IsInsideAtlas())
                    {
                        continue;
                    }

                    if (spriteData.SpriteAtlas == atlas)
                    {
                        return(true);
                    }
                }
                return(false);
            }

            return(true);
        }
示例#9
0
        protected override void DrawResultsInternal(SpriteDatabase spriteDatabase)
        {
            EditorGUILayout.BeginVertical("Box");
            if (usedSpriteDatas.Length > 0)
            {
                if (SpriteAuditorGUIUtility.DrawStringFoldout(
                        $"Used Sprites [{usedSpriteDatas.Length}] ",
                        $"{VisualizationType.Sprite.ToString()}_used_sprites"))
                {
                    EditorGUI.indentLevel++;
                    for (int i = 0; i < usedSpriteDatas.Length; i++)
                    {
                        SpriteData usedSpriteData = usedSpriteDatas[i];
                        DrawSpriteDataField(usedSpriteData);
                    }

                    EditorGUI.indentLevel--;
                }
            }

            if (unusedSprites.Length > 0)
            {
                if (SpriteAuditorGUIUtility.DrawStringFoldout(
                        $"Unused Sprites [{unusedSprites.Length}] ",
                        $"{VisualizationType.Sprite.ToString()}_unused_sprites"))
                {
                    for (int i = 0; i < unusedSprites.Length; i++)
                    {
                        Sprite sprite = unusedSprites[i];
                        SpriteAuditorGUIUtility.DrawObjectFoldout(sprite,
                                                                  $"{VisualizationType.Sprite.ToString()}_{sprite.name}", false);
                    }
                }
            }

            EditorGUILayout.EndVertical();
        }
示例#10
0
 private void ClearCache()
 {
     EditorPrefs.DeleteKey(ATLAS_AUDITOR_STORAGE_KEY);
     cachedSpriteDatabase = null;
 }
 private void UpdateSpriteData()
 {
     SpriteDatabase.UpdateSpriteData();
 }
        private void DrawSettings()
        {
            EditorGUI.BeginDisabledGroup(isRecording);
            EditorGUILayout.BeginVertical("Box");
            EditorGUILayout.LabelField("Settings", EditorStyles.toolbarDropDown);
            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            recordOnUpdate = EditorGUILayout.Toggle("Record Automatically", recordOnUpdate);
            if (EditorGUI.EndChangeCheck())
            {
                spriteFinder.SetCaptureOnUpdate(recordOnUpdate);
            }

            if (recordOnUpdate)
            {
                EditorGUI.BeginChangeCheck();
                frameInterval = EditorGUILayout.IntField("Frame Interval", frameInterval);
                if (EditorGUI.EndChangeCheck())
                {
                    spriteFinder.SetFrameInterval(frameInterval);
                }
            }
            else
            {
                bool guiWasEnabled = GUI.enabled;
                GUI.enabled = true;
                if (GUILayout.Button("Capture Frame"))
                {
                    spriteFinder.CaptureFrame();
                }

                GUI.enabled = guiWasEnabled;
            }

            EditorGUI.BeginChangeCheck();
            spriteUsageSizeThreshold =
                EditorGUILayout.Slider("Allowed Size Variation", spriteUsageSizeThreshold, 0, 2);
            if (EditorGUI.EndChangeCheck())
            {
                SpriteAuditorUtility.SetSizeCheckThreshold(spriteUsageSizeThreshold);
                SpriteDatabase.SizeCheckThresholdChanged();
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginDisabledGroup(!EditorPrefs.HasKey(ATLAS_AUDITOR_STORAGE_KEY));
            if (GUILayout.Button("Clear Cache", EditorStyles.toolbarButton))
            {
                ClearCache();
            }

            if (GUILayout.Button("Pack Atlases", EditorStyles.toolbarButton))
            {
                SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget);
            }

            if (GUILayout.Button("Refresh Atlases", EditorStyles.toolbarButton))
            {
                AtlasCacheUtility.CacheKnowAtlases();
            }

            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            EditorGUI.EndDisabledGroup();
        }
        public override void GenerateResults(SpriteDatabase spriteDatabase)
        {
            //This method is kinda of dumb doing a lot of repetitive task, but its just easier to read this way
            HashSet <SceneAsset> usedScenes = new HashSet <SceneAsset>();

            SpriteData[] validSprites = spriteDatabase.SpritesData
                                        .Where(ValidSpriteData)
                                        .Where(MatchFilter)
                                        .OrderBy(data => data.Sprite.name)
                                        .ToArray();

            for (int i = 0; i < validSprites.Length; i++)
            {
                SpriteData spriteData = validSprites[i];

                IEnumerable <SceneAsset> uniqueScenes = spriteData.SceneAssets.Distinct();
                foreach (SceneAsset uniqueScene in uniqueScenes)
                {
                    usedScenes.Add(uniqueScene);
                }
            }

            sceneToSingleSprites.Clear();
            foreach (SceneAsset sceneAsset in usedScenes)
            {
                sceneToSingleSprites.Add(sceneAsset, validSprites
                                         .Where(spriteData => !spriteData.IsInsideAtlas())
                                         .Where(spriteData => spriteData.SceneAssets.Contains(sceneAsset)).Distinct().ToArray());
            }

            sceneToAtlasToUsedSprites.Clear();
            foreach (SpriteData spriteData in validSprites)
            {
                if (!spriteData.IsInsideAtlas())
                {
                    continue;
                }

                foreach (SceneAsset sceneAsset  in spriteData.SceneAssets)
                {
                    if (!sceneToAtlasToUsedSprites.ContainsKey(sceneAsset))
                    {
                        sceneToAtlasToUsedSprites.Add(sceneAsset, new Dictionary <SpriteAtlas, HashSet <SpriteData> >());
                    }

                    SpriteAtlas spriteAtlas = spriteData.SpriteAtlas;
                    if (!sceneToAtlasToUsedSprites[sceneAsset].ContainsKey(spriteAtlas))
                    {
                        sceneToAtlasToUsedSprites[sceneAsset].Add(spriteAtlas, new HashSet <SpriteData>());
                    }

                    sceneToAtlasToUsedSprites[sceneAsset][spriteAtlas].Add(spriteData);
                }
            }

            sceneToSingleSprites.Add(SpriteAuditorUtility.DontDestroyOnLoadSceneAsset, validSprites
                                     .Where(data => data.SpriteUsageFlags.HasFlag(SpriteUsageFlags.UsedOnDontDestroyOrUnknowScene) &&
                                            !data.IsInsideAtlas()).Distinct().ToArray());

            sceneToAtlasToUsedSprites.Add(SpriteAuditorUtility.DontDestroyOnLoadSceneAsset, new Dictionary <SpriteAtlas, HashSet <SpriteData> >());

            IEnumerable <SpriteData> spritesInsideAtlas = validSprites
                                                          .Where(data => data.SpriteUsageFlags.HasFlag(SpriteUsageFlags.UsedOnDontDestroyOrUnknowScene) &&
                                                                 data.IsInsideAtlas()).Distinct();

            foreach (SpriteData spriteInsideAtlas in spritesInsideAtlas)
            {
                if (!sceneToAtlasToUsedSprites[SpriteAuditorUtility.DontDestroyOnLoadSceneAsset]
                    .ContainsKey(spriteInsideAtlas.SpriteAtlas))
                {
                    sceneToAtlasToUsedSprites[SpriteAuditorUtility.DontDestroyOnLoadSceneAsset]
                    .Add(spriteInsideAtlas.SpriteAtlas, new HashSet <SpriteData>());
                }

                sceneToAtlasToUsedSprites[SpriteAuditorUtility.DontDestroyOnLoadSceneAsset]
                [spriteInsideAtlas.SpriteAtlas].Add(spriteInsideAtlas);
            }

            if (sceneToSingleSprites[SpriteAuditorUtility.DontDestroyOnLoadSceneAsset].Length > 0 ||
                sceneToAtlasToUsedSprites[SpriteAuditorUtility.DontDestroyOnLoadSceneAsset].Count > 0)
            {
                usedScenes.Add(SpriteAuditorUtility.DontDestroyOnLoadSceneAsset);
            }

            uniqueUsedScenes = usedScenes.ToArray();
        }
 private void ClearCache()
 {
     EditorPrefs.DeleteKey(ATLAS_AUDITOR_STORAGE_KEY);
     cachedSpriteDatabase = null;
     SpriteAuditorUtility.SetResultViewDirty();
 }
示例#15
0
 protected abstract void DrawResultsInternal(SpriteDatabase spriteDatabase);
示例#16
0
 public abstract void GenerateResults(SpriteDatabase spriteDatabase);
        protected override void DrawResultsInternal(SpriteDatabase spriteDatabase)
        {
            if (uniqueUsedScenes == null)
            {
                return;
            }

            for (int i = 0; i < uniqueUsedScenes.Length; i++)
            {
                SceneAsset sceneAsset = uniqueUsedScenes[i];

                EditorGUILayout.BeginVertical("Box");

                if (SpriteAuditorGUIUtility.DrawObjectFoldout(sceneAsset, sceneAsset.name))
                {
                    EditorGUI.indentLevel++;
                    if (sceneToSingleSprites[sceneAsset].Length > 0)
                    {
                        EditorGUILayout.BeginVertical("Box");

                        if (SpriteAuditorGUIUtility.DrawStringFoldout($"Sprites Without Atlas [{sceneToSingleSprites[sceneAsset].Length}] ", $"{sceneAsset.name}_SceneViewSpritesWithoutAtlas"))
                        {
                            EditorGUI.indentLevel++;
                            foreach (SpriteData spriteData in sceneToSingleSprites[sceneAsset])
                            {
                                DrawSpriteDataField(spriteData);
                            }

                            SpriteAuditorUtility.DrawDefaultSelectionOptions(sceneToSingleSprites[sceneAsset]
                                                                             .Select(spriteData => spriteData.Sprite).Cast <Object>().ToList());
                            EditorGUI.indentLevel--;
                        }
                        EditorGUILayout.EndVertical();
                    }

                    if (sceneToAtlasToUsedSprites.ContainsKey(sceneAsset))
                    {
                        foreach (var atlasToUSedSprites in sceneToAtlasToUsedSprites[sceneAsset])
                        {
                            EditorGUILayout.BeginVertical("Box");

                            {
                                if (SpriteAuditorGUIUtility.DrawObjectFoldout(atlasToUSedSprites.Key,
                                                                              $"{VisualizationType.Scene.ToString()}_{atlasToUSedSprites.Key}"))
                                {
                                    EditorGUI.indentLevel++;
                                    foreach (SpriteData spriteData in sceneToAtlasToUsedSprites[sceneAsset][
                                                 atlasToUSedSprites.Key])
                                    {
                                        DrawSpriteDataField(spriteData);
                                    }

                                    SpriteAuditorUtility.DrawDefaultSelectionOptions(
                                        sceneToAtlasToUsedSprites[sceneAsset][atlasToUSedSprites.Key]
                                        .Select(spriteData => spriteData.Sprite).Cast <Object>().ToList());
                                    EditorGUI.indentLevel--;
                                }
                            }
                            EditorGUILayout.EndVertical();
                        }
                    }

                    EditorGUI.indentLevel--;
                }
                EditorGUILayout.EndVertical();
            }
        }
示例#18
0
        protected override void DrawResultsInternal(SpriteDatabase spriteDatabase)
        {
            for (int i = 0; i < filteredAtlas.Length; i++)
            {
                SpriteAtlas atlas = filteredAtlas[i];

                EditorGUILayout.BeginVertical("Box");

                if (SpriteAuditorGUIUtility.DrawObjectFoldout(atlas,
                                                              $"{VisualizationType.Atlas.ToString()}_{atlas.name}"))
                {
                    EditorGUI.indentLevel++;

                    if (atlasToUsedSprites[atlas].Length > 0)
                    {
                        if (SpriteAuditorGUIUtility.DrawStringFoldout(
                                $"Used Sprites [{atlasToUsedSprites[atlas].Length}] ",
                                $"{VisualizationType.Atlas.ToString()}_{atlas.name}_used_sprites"))
                        {
                            EditorGUI.indentLevel++;

                            for (int j = 0; j < atlasToUsedSprites[atlas].Length; j++)
                            {
                                SpriteData spriteData = atlasToUsedSprites[atlas][j];
                                DrawSpriteDataField(spriteData);
                            }

                            EditorGUI.indentLevel--;
                        }
                    }

                    if (atlasToNotUsedSprites[atlas].Length > 0)
                    {
                        if (SpriteAuditorGUIUtility.DrawStringFoldout(
                                $"Not Used Sprites [{atlasToNotUsedSprites[atlas].Length}] ",
                                $"{VisualizationType.Atlas.ToString()}_{atlas.name}_not_used_sprites"))
                        {
                            EditorGUI.indentLevel++;

                            for (int j = 0; j < atlasToNotUsedSprites[atlas].Length; j++)
                            {
                                Sprite sprite = atlasToNotUsedSprites[atlas][j];
                                if (sprite == null)
                                {
                                    continue;
                                }

                                SpriteAuditorGUIUtility.DrawObjectFoldout(sprite,
                                                                          $"{VisualizationType.Atlas.ToString()}_{atlas.name}_{sprite.name}", false);
                            }

                            EditorGUI.indentLevel--;
                        }
                    }

                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.EndVertical();
            }
        }
示例#19
0
 public void SetResult(SpriteDatabase targetResult)
 {
     result = targetResult;
 }