Author Topic: autoupdate atlas from folder  (Read 2886 times)

Notus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
autoupdate atlas from folder
« 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.

Notus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: autoupdate atlas from folder
« Reply #1 on: September 30, 2013, 05:14:19 AM »
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);
        }
    }
}