Exemplo n.º 1
0
        public void ReportButton(Button button)
        {
            if (button.targetGraphic == null)
            {
                return;
            }

            Image buttonImage = button.targetGraphic as Image;

            if (buttonImage == null)
            {
                return;
            }

            if (buttonImage.sprite == null)
            {
                return;
            }

            SpriteData spriteData = GetOrCreateSpriteData(buttonImage.sprite);

            spriteData.ReportUse(buttonImage);

            if (button.spriteState.disabledSprite != null)
            {
                spriteData = GetOrCreateSpriteData(button.spriteState.disabledSprite);
                spriteData.ReportUse(buttonImage);
            }

            if (button.spriteState.highlightedSprite != null)
            {
                spriteData = GetOrCreateSpriteData(button.spriteState.highlightedSprite);
                spriteData.ReportUse(buttonImage);
            }

            if (button.spriteState.pressedSprite != null)
            {
                spriteData = GetOrCreateSpriteData(button.spriteState.pressedSprite);
                spriteData.ReportUse(buttonImage);
            }
        }
Exemplo n.º 2
0
        protected void DrawSpriteReferencesPath(SpriteData spriteData)
        {
            EditorGUILayout.LabelField("Usages", EditorStyles.boldLabel);
            EditorGUI.indentLevel++;

            for (int i = 0; i < spriteData.Usages.Count; i++)
            {
                SpriteUseData spriteUseData = spriteData.Usages[i];
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(spriteUseData.DisplayFirstPath);

                if (GUILayout.Button("Select", EditorStyles.miniButton))
                {
                    TrySelect(spriteUseData);
                }

                EditorGUILayout.EndHorizontal();
            }

            EditorGUI.indentLevel--;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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();
            }
        }
Exemplo n.º 6
0
        private bool MatchFilter(SpriteData data)
        {
            if (!MatchSearch(data.Sprite.name))
            {
                return(false);
            }

            if (currentFilter.HasFlag(Filter.UsedSmallerThanSpriteSize))
            {
                if (!data.SpriteUsageFlags.HasFlag(SpriteUsageFlags.UsedSmallerThanSpriteRect))
                {
                    return(false);
                }
            }

            if (currentFilter.HasFlag(Filter.UsedBiggerThanSpriteSize))
            {
                if (!data.SpriteUsageFlags.HasFlag(SpriteUsageFlags.UsedBiggerThanSpriteRect))
                {
                    return(false);
                }
            }

            if (currentFilter.HasFlag(Filter.UsedOnlyOnOneScenes))
            {
                if (data.SceneAssets.Count > 1)
                {
                    return(false);
                }
            }

            if (currentFilter.HasFlag(Filter.UnableToDetectAllSizes))
            {
                if (!data.SpriteUsageFlags.HasFlag(SpriteUsageFlags.CantDiscoveryAllUsageSize))
                {
                    return(false);
                }
            }

            if (currentFilter.HasFlag(Filter.SingleSprites))
            {
                if (data.TextureImporter == null || data.TextureImporter.spriteImportMode != SpriteImportMode.Single)
                {
                    return(false);
                }
            }

            if (currentFilter.HasFlag(Filter.MultipleSprites))
            {
                if (data.TextureImporter == null || data.TextureImporter.spriteImportMode != SpriteImportMode.Multiple)
                {
                    return(false);
                }
            }

            if (currentFilter.HasFlag(Filter.InsideAtlasSprites))
            {
                if (!data.IsInsideAtlas())
                {
                    return(false);
                }
            }

            if (currentFilter.HasFlag(Filter.InsideScaledAtlasVariant))
            {
                if (!data.SpriteUsageFlags.HasFlag(SpriteUsageFlags.UsingScaledAtlasSize))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 7
0
        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();
        }