using UnityEditor;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class UpdateAtlas {
public void StartUpdate() {
Debug.Log("Update atlases started !!");
// *** Find all atlases
UIAtlas
[] allAtlas
= (UIAtlas
[])Resources
.FindObjectsOfTypeAll(typeof (UIAtlas
)); Debug.Log("UIAtlas " + allAtlas.Length);
// *** Find and load all textures
string[] aTextureFiles = Directory.GetFiles(Application.dataPath, "*.*", SearchOption.AllDirectories);
List
<Texture2D
> textureList
= new List
<Texture2D
>(); foreach (string currentFile in aTextureFiles) {
string assetPath = "Assets" + currentFile.Replace(Application.dataPath, "").Replace('\\', '/');
Texture2D texture = NGUIEditorTools.ImportTexture(assetPath, true, false);
if (texture) {
textureList.Add(texture);
}
}
Debug.Log("Textures " + textureList.Count);
// *** Find duplicates
List
<string> duplicateNames
= new List
<string>(); List
<string> allNames
= new List
<string>(); foreach (Texture2D currentTexture in textureList) {
if (!allNames.Contains(currentTexture.name)) {
allNames.Add(currentTexture.name);
}
else {
duplicateNames.Add(currentTexture.name);
}
}
// *** List duplicates
foreach (string textureName in duplicateNames) {
Debug.Log("Found duplicate "+textureName);
}
// *** Update atlases
foreach(UIAtlas currentAtlas in allAtlas) {
BetterList<string> spriteList = currentAtlas.GetListOfSprites();
// *** Match textures
foreach (Texture2D currentTexture in textureList) {
if (spriteList.Contains(currentTexture.name) && !duplicateNames.Contains(currentTexture.name)) {
UIAtlasMaker.AddOrUpdate(currentAtlas,currentTexture);
}
}
}
}
}