Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Notus on September 28, 2013, 05:28:52 AM
-
Hello. Can anybody help me to create script that will update a atlas from special folder. (before build or may be by menu options)
need: autoupdate sprites, autoadd new sprites.
-
if anybody want - you can use code like this: (use from editor script)
public static string PathAtlas = "Assets/w_Test/testautoatlas.prefab";
public static string PathSource = "/w_Test/autosprites";
[MenuItem("project/Update Test Atlas")]
private static void UpdateAtlas()
{
UIAtlas teastatlas = null;
GameObject go = AssetDatabase.LoadAssetAtPath(PathAtlas, typeof(GameObject)) as GameObject;
if (go != null)
{
teastatlas = go.GetComponent<UIAtlas>();
}
string[] spritesStr = Directory.GetFiles(Application.dataPath + PathSource, "*.png");
foreach (var str in spritesStr)
{
string assetPath = "Assets" + str.Replace(Application.dataPath, "").Replace('\\', '/');
Texture tex = (Texture2D)AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D));
if (tex != null)
{
UIAtlasMaker.AddOrUpdate(teastatlas, (Texture2D) tex);
}
}
}