public override void OnInspectorGUI() { base.OnInspectorGUI(); SpriteSleeperManager myTarget = Target; var loadListeners = (myTarget.OnAtlasLoaded == null) ? 0 : myTarget.OnAtlasLoaded.GetInvocationList().Length; EditorGUILayout.LabelField("Load listeners: " + loadListeners.ToString()); var unloadListeners = (myTarget.OnAtlasUnloaded == null) ? 0 : myTarget.OnAtlasUnloaded.GetInvocationList().Length; EditorGUILayout.LabelField("Unload listeners: " + unloadListeners.ToString()); EditorGUILayout.LabelField("Managed canvases: " + myTarget.NumCanvasesPresent.ToString()); var loadedInfos = myTarget.LoadedAtlases; EditorGUILayout.LabelField("Loaded atlases: " + loadedInfos.Count.ToString()); foreach (var info in loadedInfos) { EditorGUILayout.LabelField(string.Format(" {0} : ({1} sprites), Ref: {2}", info.Tag, myTarget.NumSpritesByTag(info.Tag), info.RefCount.ToString())); } var infos = myTarget.AtlasInfo; EditorGUILayout.LabelField("Configured atlases: " + infos.Length.ToString()); foreach (var info in infos) { EditorGUILayout.LabelField(string.Format(" {0} : {1}", info.AtlasTag, info.ResourcesPath)); } EditorUtility.SetDirty(myTarget); }
static void RebuildAtlasCache() { SpriteAtlas[] atlases = FindAtlasesInResources(); SpriteAtlasList list = new SpriteAtlasList(); list.Atlases = new SpriteAtlasList.AtlasInfo[atlases.Length]; int usedAtlasPairs = 0; foreach (var atlas in atlases) { var atlasPath = AssetDatabase.GetAssetPath(atlas); int resourcesIndex = atlasPath.IndexOf(ResourcesIdentifier); if (resourcesIndex > -1) { SpriteAtlasList.AtlasInfo info = new SpriteAtlasList.AtlasInfo(); info.AtlasID = usedAtlasPairs; info.AtlasTag = atlas.tag; int startIndex = resourcesIndex + 1 + ResourcesIdentifier.Length; string relativePath = atlasPath.Substring(startIndex - 1, atlasPath.Length - startIndex + 1); info.ResourcesPath = relativePath.Substring(0, relativePath.IndexOf(".")); Sprite[] sprites = new Sprite[atlas.spriteCount]; atlas.GetSprites(sprites); List <string> spriteNames = new List <string>(); foreach (var sprite in sprites) { spriteNames.Add(sprite.name.Replace("(Clone)", "")); } info.SpriteNames = spriteNames.ToArray(); list.Atlases[usedAtlasPairs] = info; usedAtlasPairs++; } } string filePath = SpriteSleeperManager.GetSpriteSleeperDataPath(); if (!System.IO.Directory.Exists(Application.streamingAssetsPath)) { AssetDatabase.CreateFolder("Assets", "StreamingAssets"); } System.IO.File.WriteAllText(filePath, JsonUtility.ToJson(list)); AssetDatabase.Refresh(); }