Exemple #1
0
    public static void CreateUGUIAtlas(string prefabpath, string atlaspath)
    {
        if (prefabpath == null && EditorUtility.DisplayDialog("选择预设", "选择ugui 图集预设", "OK"))
        {
            prefabpath = EditorUtility.OpenFilePanel("", "Assets/", "");
            prefabpath = EditorTools.GetUnityAssetPath(prefabpath);
        }

        if (atlaspath == null && EditorUtility.DisplayDialog("选择图集目录", "选择ugui 图集目录", "OK"))
        {
            atlaspath = EditorUtility.OpenFolderPanel("", "Assets/", "");
            atlaspath = EditorTools.GetUnityAssetPath(atlaspath);
        }

        if (!string.IsNullOrEmpty(prefabpath) && !string.IsNullOrEmpty(atlaspath))
        {
            GameObject       prefab     = AssetDatabase.LoadAssetAtPath <GameObject>(prefabpath);
            SpriteAtlasMgr   spritelist = prefab.TryAddComponent <SpriteAtlasMgr>();
            string[]         guids      = AssetDatabase.FindAssets("t:Sprite", new string[] { atlaspath });
            HashSet <string> hashset    = guids.ConvertHashSet();

            spritelist.Clear();
            foreach (string guid in hashset)
            {
                string assetpath             = AssetDatabase.GUIDToAssetPath(guid);
                UnityEngine.Object[] allsprs = AssetDatabase.LoadAllAssetsAtPath(assetpath);
                SpriteAtlas          atlas   = new SpriteAtlas();
                atlas.LoadSprites(allsprs);

                spritelist.InitSprites(atlas);
            }

            EditorUtility.SetDirty(prefab);
        }
    }