using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEditor;
|
using System.IO;
|
using UnityEngine.UI;
|
using System.Windows.Forms;
|
using vnxbqy.UI;
|
|
|
//导出已打开的(或者指定名)界面用到的图片
|
public class ExportPrefabsIMG : EditorWindow {
|
|
private static string topFilePath= "Assets/ResourcesOut/UI/Window/";
|
private static string builtInFilePath = "Assets/ResourcesOut/BuiltIn/Prefabs/";
|
private static string priorityWindowFilePath = "Assets/ResourcesOut/UI/PriorityWindow/";
|
|
private static ExportPrefabsIMG window = null;
|
private Vector2 scrollPosition;
|
private static int exportType = 0; //0 运行时界面 1 builtin目录界面 2 window目录界面 3 priorityWindow目录界面
|
|
|
public class FileToggleInfo
|
{
|
public FileToggleInfo(string fileName, bool sel)
|
{
|
fileInfo = fileName;
|
isSelect = sel;
|
}
|
|
public string fileInfo = null;
|
public bool isSelect = false;
|
}
|
|
private static List<FileToggleInfo> _tableNameLst = new List<FileToggleInfo>(); //所有表名字列表
|
|
|
[UnityEditor.MenuItem("策划工具/导出指定界面的图片", false)]
|
static void Init()
|
{
|
exportType = 0;
|
window = GetWindow(typeof(ExportPrefabsIMG), false, "导出界面图片,运行时导出会更准确") as ExportPrefabsIMG;
|
window.position = new Rect(UnityEngine.Screen.width / 2, UnityEngine.Screen.height / 2, 300, 700);
|
window.Show();
|
}
|
|
private void OnGUI()
|
{
|
GUILayout.BeginVertical();
|
|
scrollPosition = GUILayout.BeginScrollView(scrollPosition);
|
ShowTableNames();
|
GUILayout.EndScrollView();
|
|
GUILayout.FlexibleSpace();
|
|
GUILayout.BeginHorizontal();
|
if (GUILayout.Button("刷新运行时界面"))
|
{
|
exportType = 0;
|
GetDicFiles();
|
}
|
GUILayout.EndHorizontal();
|
GUILayout.BeginHorizontal();
|
if (GUILayout.Button("刷新builtIn界面"))
|
{
|
exportType = 1;
|
GetDicFiles();
|
}
|
GUILayout.EndHorizontal();
|
GUILayout.BeginHorizontal();
|
if (GUILayout.Button("刷新Window界面"))
|
{
|
exportType = 2;
|
GetDicFiles();
|
}
|
GUILayout.EndHorizontal();
|
GUILayout.BeginHorizontal();
|
if (GUILayout.Button("刷新PriorityWindow界面"))
|
{
|
exportType = 3;
|
GetDicFiles();
|
}
|
GUILayout.EndHorizontal();
|
GUILayout.BeginHorizontal();
|
if (GUILayout.Button("全选"))
|
{
|
SelectAll();
|
}
|
GUILayout.EndHorizontal();
|
|
GUILayout.BeginHorizontal();
|
if (GUILayout.Button("导出图片"))
|
{
|
Export();
|
MessageBox.Show("导出图片成功!(查看根目录的OpenWindowImages)");
|
AssetDatabase.Refresh();
|
}
|
GUILayout.EndHorizontal();
|
|
|
GUIUtility.ExitGUI();
|
}
|
|
private void ShowTableNames()
|
{
|
if (_tableNameLst == null)
|
{
|
return;
|
}
|
for (int i = 0; i < _tableNameLst.Count; i++)
|
{
|
string tableName = _tableNameLst[i].fileInfo;
|
|
_tableNameLst[i].isSelect = GUILayout.Toggle(_tableNameLst[i].isSelect, tableName);
|
|
}
|
}
|
|
// 0 运行时界面 1 builtin目录界面 2 window目录界面
|
private void GetDicFiles()
|
{
|
_tableNameLst.Clear();
|
if (exportType == 0)
|
{
|
if (!EditorApplication.isPlaying || WindowCenter.Instance.openWinNames.IsNullOrEmpty())
|
{
|
MessageBox.Show("请在游戏运行时打开界面");
|
return;
|
}
|
|
foreach (var item in WindowCenter.Instance.openWinNames)
|
{
|
_tableNameLst.Add(new FileToggleInfo(item.Key, false));
|
}
|
}
|
else if (exportType == 1)
|
{
|
DirectoryInfo folder = new DirectoryInfo(@builtInFilePath);
|
if (folder != null)
|
{
|
FileInfo[] fileInfoArr = folder.GetFiles("*.prefab");
|
if (fileInfoArr == null || fileInfoArr.Length <= 0)
|
{
|
return;
|
}
|
for (int i = 0, length = fileInfoArr.Length; i < length; i++)
|
{
|
_tableNameLst.Add(new FileToggleInfo(fileInfoArr[i].Name.Split('.')[0], false));
|
}
|
}
|
}
|
else if (exportType == 2)
|
{
|
DirectoryInfo folder = new DirectoryInfo(@topFilePath);
|
if (folder != null)
|
{
|
FileInfo[] fileInfoArr = folder.GetFiles("*.prefab");
|
if (fileInfoArr == null || fileInfoArr.Length <= 0)
|
{
|
return;
|
}
|
for (int i = 0, length = fileInfoArr.Length; i < length; i++)
|
{
|
_tableNameLst.Add(new FileToggleInfo(fileInfoArr[i].Name.Split('.')[0], false));
|
}
|
}
|
}
|
else if (exportType == 3)
|
{
|
DirectoryInfo folder = new DirectoryInfo(@priorityWindowFilePath);
|
if (folder != null)
|
{
|
FileInfo[] fileInfoArr = folder.GetFiles("*.prefab");
|
if (fileInfoArr == null || fileInfoArr.Length <= 0)
|
{
|
return;
|
}
|
for (int i = 0, length = fileInfoArr.Length; i < length; i++)
|
{
|
_tableNameLst.Add(new FileToggleInfo(fileInfoArr[i].Name.Split('.')[0], false));
|
}
|
}
|
}
|
|
}
|
|
private void SelectAll()
|
{
|
if (_tableNameLst == null)
|
{
|
MessageBox.Show("请先刷新界面");
|
return;
|
}
|
for (int i = 0; i < _tableNameLst.Count; i++)
|
{
|
if (_tableNameLst[i] == null)
|
{
|
continue;
|
}
|
if (_tableNameLst[i].fileInfo == null)
|
{
|
continue;
|
}
|
_tableNameLst[i].isSelect = true;
|
}
|
}
|
|
private void Export()
|
{
|
//导出指定界面 或者 选中已打开的界面
|
if (!Directory.Exists("OpenWindowImages"))
|
Directory.CreateDirectory("OpenWindowImages");
|
|
if (_tableNameLst == null)
|
{
|
MessageBox.Show("先刷新界面");
|
return;
|
}
|
for (int i = 0; i < _tableNameLst.Count; i++)
|
{
|
if (!_tableNameLst[i].isSelect)
|
{
|
continue;
|
}
|
|
string fileName = _tableNameLst[i].fileInfo;
|
string filePath;
|
if (exportType == 0)
|
{
|
if (WindowCenter.Instance.openWinNames[fileName])
|
{
|
filePath = builtInFilePath + _tableNameLst[i].fileInfo + ".prefab";
|
}
|
else
|
{
|
filePath = topFilePath + _tableNameLst[i].fileInfo + ".prefab";
|
}
|
if (!File.Exists(filePath))
|
{
|
filePath = priorityWindowFilePath + _tableNameLst[i].fileInfo + ".prefab";
|
}
|
}
|
else if (exportType == 1)
|
{
|
filePath = builtInFilePath + _tableNameLst[i].fileInfo + ".prefab";
|
}
|
else if (exportType == 2)
|
{
|
filePath = topFilePath + _tableNameLst[i].fileInfo + ".prefab";
|
}
|
else
|
{
|
filePath = priorityWindowFilePath + _tableNameLst[i].fileInfo + ".prefab";
|
}
|
|
GameObject _prefab = AssetDatabase.LoadAssetAtPath<GameObject>(filePath);
|
if (_prefab == null)
|
{
|
Debug.LogFormat("无法取得文件 {0}", filePath);
|
continue;
|
}
|
Image[] transArr14 = _prefab.GetComponentsInChildren<Image>(true);
|
foreach (Image item in transArr14)
|
{
|
var path = AssetDatabase.GetAssetPath(item.sprite.GetInstanceID());
|
if (string.IsNullOrEmpty(path)) continue;
|
if (!path.Contains("ResourcesOut")) continue;
|
if (!Directory.Exists("OpenWindowImages/" + fileName))
|
Directory.CreateDirectory("OpenWindowImages/" + fileName);
|
|
var arr = path.Replace("Sprite","@").Split("@");
|
if (arr.Length == 2)
|
{
|
var aa = arr[1].Split("/");
|
if (aa.Length != 1)
|
{
|
if (!Directory.Exists("OpenWindowImages/" + fileName + "/" + aa[1]))
|
Directory.CreateDirectory("OpenWindowImages/" + fileName + "/" + aa[1]);
|
if (!File.Exists("OpenWindowImages/" + fileName + "/" + aa[1] + "/" + item.sprite.name + ".png"))
|
File.Copy(path, "OpenWindowImages/" + fileName + "/" + aa[1] + "/" + item.sprite.name + ".png");
|
|
if (!File.Exists("OpenWindowImages/" + fileName + "/" + aa[1] + "/" + item.sprite.name + ".png.meta"))
|
File.Copy(path, "OpenWindowImages/" + fileName + "/" + aa[1] + "/" + item.sprite.name + ".png.meta");
|
}
|
}
|
|
//if (!File.Exists("OpenWindowImages/" + fileName + "/" + item.sprite.name + ".png"))
|
// File.Copy(path, "OpenWindowImages/" + fileName + "/" + item.sprite.name + ".png");
|
}
|
}
|
|
|
}
|
|
|
}
|