Пример #1
0
    void AddOrUpdateAtlas(string name)
    {
        GameObject newPrefabs = new GameObject(name);
        UIAtlas    atlas      = newPrefabs.AddComponent <UIAtlas>();

        foreach (var sp in sprites.Values)
        {
            atlas.AddSprite(sp.Sprite);
        }

        GameObject go = PrefabUtility.ReplacePrefab(newPrefabs, uiAtlas, ReplacePrefabOptions.Default);

        uiAtlas = go.GetComponent <UIAtlas>();

        DestroyImmediate(newPrefabs);
    }
Пример #2
0
    private static void PackDir(DirectoryInfo dirInfo, string atlasName)
    {
        if (atlasName != "")
        {
            GameObject go      = new GameObject(atlasName);
            UIAtlas    uiAtlas = go.AddComponent <UIAtlas>();
            uiAtlas.atlasName = atlasName;
            foreach (FileInfo pngFile in dirInfo.GetFiles("*.png", SearchOption.TopDirectoryOnly))
            {
                string allPath   = pngFile.FullName;
                string assetPath = allPath.Substring(allPath.IndexOf("Assets"));
                Sprite sprite    = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath);
                if (null == sprite)
                {
                    Debug.LogError("PackAtlas Error. Cannot load sprite: " + assetPath);
                    continue;
                }
                uiAtlas.AddSprite(sprite);
            }

            string atlasPath = UIAtlasUtility.atlasRootPath + atlasName + ".prefab";
            PrefabUtility.CreatePrefab("Assets/" + atlasPath, go);
            GameObject.DestroyImmediate(go);
        }

        foreach (DirectoryInfo subDirInfo in dirInfo.GetDirectories())
        {
            string subAtlasName = atlasName + UIAtlasUtility.altasNameSeparator + subDirInfo.Name;
            if (atlasName == "")
            {
                subAtlasName = subDirInfo.Name;
            }

            PackDir(subDirInfo, subAtlasName);
        }
    }