using System.Collections; 
 | 
using System.Collections.Generic; 
 | 
using UnityEngine; 
 | 
using UnityEditor; 
 | 
using System.IO; 
 | 
using UnityEngine.UI; 
 | 
  
 | 
public class ExportUIPackage 
 | 
{ 
 | 
  
 | 
    static string exportFileName = Application.dataPath + "/UIPackage.unitypackage"; 
 | 
    static string uiroot = "Assets/ResourcesOut/UI"; 
 | 
    static string builtIn = "Assets/ResourcesOut/BuiltIn/Prefabs"; 
 | 
    static string windowreferenceTable = "Assets/Editor/Config/Windows.txt"; 
 | 
  
 | 
    [MenuItem("策划工具/导出UI Package", false, 4)] 
 | 
    public static void Export() 
 | 
    { 
 | 
        var windowGuids = new List<string>(); 
 | 
        windowGuids.AddRange(AssetDatabase.FindAssets("Win t:prefab", new string[] { builtIn })); 
 | 
        windowGuids.AddRange(AssetDatabase.FindAssets("Win t:prefab", new string[] { uiroot })); 
 | 
  
 | 
        var windowReferenceConfigRoot = Application.dataPath + "/WindowAssets/"; 
 | 
        if (!Directory.Exists(windowReferenceConfigRoot)) 
 | 
        { 
 | 
            Directory.CreateDirectory(windowReferenceConfigRoot); 
 | 
        } 
 | 
  
 | 
        var windowAssets = new List<string>(); 
 | 
        foreach (var item in windowGuids) 
 | 
        { 
 | 
            var path = AssetDatabase.GUIDToAssetPath(item); 
 | 
            var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path); 
 | 
            var fileName = Path.GetFileNameWithoutExtension(path); 
 | 
  
 | 
            var sprites = new List<string>(); 
 | 
            var components = prefab.GetComponentsInChildren<Image>(true); 
 | 
            foreach (var image in components) 
 | 
            { 
 | 
                if (image.sprite != null) 
 | 
                { 
 | 
                    var spritePath = AssetDatabase.GetAssetPath(image.sprite).Replace("Assets/", ""); 
 | 
                    if (!sprites.Contains(spritePath)) 
 | 
                    { 
 | 
                        sprites.Add(spritePath); 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
  
 | 
            File.WriteAllLines(windowReferenceConfigRoot + fileName + ".txt", sprites.ToArray(), System.Text.Encoding.UTF8); 
 | 
        } 
 | 
  
 | 
        var guids = new List<string>(); 
 | 
        guids.AddRange(AssetDatabase.FindAssets("t:TextAsset", new string[] { "Assets/WindowAssets" })); 
 | 
        guids.AddRange(AssetDatabase.FindAssets("t:prefab", new string[] { builtIn })); 
 | 
        guids.AddRange(AssetDatabase.FindAssets("Font", new string[] { uiroot })); 
 | 
        guids.AddRange(AssetDatabase.FindAssets("t:prefab", new string[] { uiroot })); 
 | 
        guids.AddRange(AssetDatabase.FindAssets("t:Texture2D", new string[] { uiroot })); 
 | 
        guids.AddRange(AssetDatabase.FindAssets("t:Sprite", new string[] { uiroot })); 
 | 
  
 | 
        var assets = new List<string>(); 
 | 
        foreach (var item in guids) 
 | 
        { 
 | 
            assets.Add(AssetDatabase.GUIDToAssetPath(item)); 
 | 
        } 
 | 
  
 | 
        assets.Add(windowreferenceTable); 
 | 
        AssetDatabase.ExportPackage(assets.ToArray(), exportFileName, ExportPackageOptions.Default); 
 | 
    } 
 | 
  
 | 
    [MenuItem("策划工具/生成window参照表", false, 5)] 
 | 
    public static void ExportAllWindowNames() 
 | 
    { 
 | 
        var lines = new List<string>(); 
 | 
        var filePath = Application.dataPath + "/Editor/Config/Windows.txt"; 
 | 
        if (File.Exists(filePath)) 
 | 
        { 
 | 
            lines.AddRange(File.ReadAllLines(filePath, System.Text.Encoding.UTF8)); 
 | 
        } 
 | 
  
 | 
        var windowNames = new List<string>(); 
 | 
        foreach (var item in lines) 
 | 
        { 
 | 
            windowNames.Add(item.Split('\t')[0]); 
 | 
        } 
 | 
  
 | 
        var guids = new List<string>(); 
 | 
        guids.AddRange(AssetDatabase.FindAssets("Win t:prefab", new string[] { builtIn })); 
 | 
        guids.AddRange(AssetDatabase.FindAssets("Win t:prefab", new string[] { uiroot })); 
 | 
  
 | 
        var assets = new List<string>(); 
 | 
        foreach (var item in guids) 
 | 
        { 
 | 
            var name = Path.GetFileNameWithoutExtension(AssetDatabase.GUIDToAssetPath(item)); 
 | 
            if (!windowNames.Contains(name)) 
 | 
            { 
 | 
                lines.Add(StringUtility.Contact(name, "\t")); 
 | 
            } 
 | 
        } 
 | 
  
 | 
        File.WriteAllLines(filePath, lines.ToArray(), System.Text.Encoding.UTF8); 
 | 
    } 
 | 
  
 | 
} 
 |