111
This commit is contained in:
@@ -9,12 +9,20 @@ using UnityEngine;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Stary.Evo.TableTextConversion;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Stary.Evo.TableTextConversion
|
||||
{
|
||||
public class ConvertedExslDataMessage : OdinEditorWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置文件类型
|
||||
/// </summary>
|
||||
[EnumToggleButtons, HideLabel] [OnValueChanged("SetConfigurationFileType")]
|
||||
public ConfigurationFileType configurationFileType = ConfigurationFileType.Asset;
|
||||
|
||||
private static ConvertedExslDataMessage window;
|
||||
|
||||
// 读取的位置
|
||||
@@ -33,6 +41,12 @@ namespace Stary.Evo.TableTextConversion
|
||||
window.Show();
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
configurationFileType = (ConfigurationFileType)Enum.Parse(typeof(ConfigurationFileType),
|
||||
EditorPrefs.GetString("ConfigurationFileType"));
|
||||
}
|
||||
|
||||
[Title("转化配置的Exsl文件:", titleAlignment: TitleAlignments.Centered)]
|
||||
[HorizontalGroup("BuildPipeline"), HideLabel]
|
||||
@@ -50,7 +64,7 @@ namespace Stary.Evo.TableTextConversion
|
||||
|
||||
//[MenuItem("Exsl/信息表转换")]
|
||||
[Button("转化Exsl表格", ButtonSizes.Large)]
|
||||
public static void CrtateMessage()
|
||||
public void CrtateMessage()
|
||||
{
|
||||
#region 读取Excel表格并转成DataSet类型的数据
|
||||
|
||||
@@ -112,10 +126,10 @@ namespace Stary.Evo.TableTextConversion
|
||||
{
|
||||
#region 遍历表格相应的数据转换成数据
|
||||
|
||||
List<AudioTableData.MessageInfo> messageInfos = new List<AudioTableData.MessageInfo>();
|
||||
List<AudioEntity> messageInfos = new List<AudioEntity>();
|
||||
for (int j = 1; j < VoiceCount; j++)
|
||||
{
|
||||
AudioTableData.MessageInfo messageInfo = new AudioTableData.MessageInfo();
|
||||
AudioEntity messageInfo = new AudioEntity();
|
||||
//获取对话块
|
||||
messageInfo.index = j - 1;
|
||||
//文件名称
|
||||
@@ -123,16 +137,16 @@ namespace Stary.Evo.TableTextConversion
|
||||
//获取内容
|
||||
messageInfo.autype =
|
||||
Enum.TryParse(FilterTo(table.Rows[j][1].ToString()),
|
||||
out AudioTableData.AudioType auType)
|
||||
out AudioType auType)
|
||||
? auType
|
||||
: AudioTableData.AudioType.Null;
|
||||
: AudioType.Null;
|
||||
|
||||
//获取描述
|
||||
messageInfo.filename = FilterTo(table.Rows[j][2].ToString());
|
||||
|
||||
messageInfo.voice = FilterTo(table.Rows[j][3].ToString());
|
||||
|
||||
|
||||
|
||||
messageInfo.uirelated = FilterTo(table.Rows[j][4].ToString());
|
||||
//添加数据
|
||||
messageInfos.Add(messageInfo);
|
||||
@@ -140,11 +154,18 @@ namespace Stary.Evo.TableTextConversion
|
||||
|
||||
#endregion
|
||||
|
||||
ScriptObjectSave<AudioTableData>("AudioTableData", (data) =>
|
||||
if (configurationFileType == ConfigurationFileType.Asset)
|
||||
{
|
||||
data.infos = new List<AudioTableData.MessageInfo>();
|
||||
data.infos = messageInfos;
|
||||
});
|
||||
ScriptObjectSave<AudioTableData>("AudioTableData", (data) =>
|
||||
{
|
||||
data.infos = new List<AudioEntity>();
|
||||
data.infos = messageInfos;
|
||||
});
|
||||
}
|
||||
else if (configurationFileType == ConfigurationFileType.Json)
|
||||
{
|
||||
JsonSave<List<AudioEntity>>("AudioTableData", () => { return messageInfos; });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -155,10 +176,10 @@ namespace Stary.Evo.TableTextConversion
|
||||
{
|
||||
#region 遍历表格相应的数据转换成数据
|
||||
|
||||
List<VideoTableData.MessageInfo> messageInfos = new List<VideoTableData.MessageInfo>();
|
||||
List<VideoEntity> messageInfos = new List<VideoEntity>();
|
||||
for (int j = 1; j < VoiceCount; j++)
|
||||
{
|
||||
VideoTableData.MessageInfo messageInfo = new VideoTableData.MessageInfo();
|
||||
VideoEntity messageInfo = new VideoEntity();
|
||||
//获取对话块
|
||||
messageInfo.index = j - 1;
|
||||
//文件名称
|
||||
@@ -179,19 +200,27 @@ namespace Stary.Evo.TableTextConversion
|
||||
? true
|
||||
: false;
|
||||
messageInfo.videoframeName = FilterTo(table.Rows[j][6].ToString());
|
||||
|
||||
|
||||
|
||||
|
||||
//添加数据
|
||||
messageInfos.Add(messageInfo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
ScriptObjectSave<VideoTableData>("VideoTableData", (data) =>
|
||||
|
||||
if (configurationFileType == ConfigurationFileType.Asset)
|
||||
{
|
||||
data.infos = new List<VideoTableData.MessageInfo>();
|
||||
data.infos = messageInfos;
|
||||
});
|
||||
ScriptObjectSave<VideoTableData>("VideoTableData", (data) =>
|
||||
{
|
||||
data.infos = new List<VideoEntity>();
|
||||
data.infos = messageInfos;
|
||||
});
|
||||
}
|
||||
else if (configurationFileType == ConfigurationFileType.Json)
|
||||
{
|
||||
JsonSave<List<VideoEntity>>("VideoTableData", () => { return messageInfos; });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -202,9 +231,9 @@ namespace Stary.Evo.TableTextConversion
|
||||
{
|
||||
#region 遍历表格相应的数据转换成数据
|
||||
|
||||
List<UITableData.MessageInfo> messageInfos = new List<UITableData.MessageInfo>();
|
||||
UITableData.MessageInfo messageInfo = null;
|
||||
List<UITableData.SubtitleInfo> subtitle = null;
|
||||
List<UIEntity> messageInfos = new List<UIEntity>();
|
||||
UIEntity messageInfo = null;
|
||||
List<SubtitleInfo> subtitle = null;
|
||||
int infoIndex = 0;
|
||||
for (int j = 1; j < VoiceCount; j++)
|
||||
{
|
||||
@@ -212,8 +241,8 @@ namespace Stary.Evo.TableTextConversion
|
||||
if (!table.Rows[j][0].ToString().Equals(""))
|
||||
{
|
||||
Debug.Log(table.Rows[j][0].ToString());
|
||||
messageInfo = new UITableData.MessageInfo();
|
||||
subtitle = new List<UITableData.SubtitleInfo>();
|
||||
messageInfo = new UIEntity();
|
||||
subtitle = new List<SubtitleInfo>();
|
||||
messageInfo.subtitle = subtitle;
|
||||
//获取对话块
|
||||
messageInfo.index = infoIndex;
|
||||
@@ -227,7 +256,7 @@ namespace Stary.Evo.TableTextConversion
|
||||
|
||||
if (!table.Rows[j][3].ToString().Equals(""))
|
||||
{
|
||||
var subtitleInfo = new UITableData.SubtitleInfo();
|
||||
var subtitleInfo = new SubtitleInfo();
|
||||
subtitleInfo.lineid = FilterTo(table.Rows[j][3].ToString());
|
||||
subtitleInfo.subtitle = FilterTo(table.Rows[j][4].ToString());
|
||||
subtitleInfo.start =
|
||||
@@ -242,7 +271,7 @@ namespace Stary.Evo.TableTextConversion
|
||||
messageInfo.subtitle.Add(subtitleInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//添加数据
|
||||
messageInfos.Add(messageInfo);
|
||||
infoIndex++;
|
||||
@@ -251,7 +280,7 @@ namespace Stary.Evo.TableTextConversion
|
||||
{
|
||||
if (!table.Rows[j][3].ToString().Equals(""))
|
||||
{
|
||||
var subtitleInfo = new UITableData.SubtitleInfo();
|
||||
var subtitleInfo = new SubtitleInfo();
|
||||
subtitleInfo.lineid = FilterTo(table.Rows[j][3].ToString());
|
||||
subtitleInfo.subtitle = FilterTo(table.Rows[j][4].ToString());
|
||||
subtitleInfo.start =
|
||||
@@ -270,11 +299,18 @@ namespace Stary.Evo.TableTextConversion
|
||||
|
||||
#endregion
|
||||
|
||||
ScriptObjectSave<UITableData>("UITableData", (data) =>
|
||||
if (configurationFileType == ConfigurationFileType.Asset)
|
||||
{
|
||||
data.infos = new List<UITableData.MessageInfo>();
|
||||
data.infos = messageInfos;
|
||||
});
|
||||
ScriptObjectSave<UITableData>("UITableData", (data) =>
|
||||
{
|
||||
data.infos = new List<UIEntity>();
|
||||
data.infos = messageInfos;
|
||||
});
|
||||
}
|
||||
else if (configurationFileType == ConfigurationFileType.Json)
|
||||
{
|
||||
JsonSave<List<UIEntity>>("UITableData", () => { return messageInfos; });
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -322,6 +358,39 @@ namespace Stary.Evo.TableTextConversion
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ScriptObject数据保存类
|
||||
/// </summary>
|
||||
/// <param name="assetName"></param>
|
||||
/// <param name="action">写入数据的一个回调</param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
private static void JsonSave<T>(string assetName, Func<T> func) where T : IEnumerable, new()
|
||||
{
|
||||
// 创建数据实例
|
||||
T data = new T();
|
||||
//放写入数据操作
|
||||
data = func.Invoke();
|
||||
// 确保保存目录存在
|
||||
if (!Directory.Exists(Assetpath))
|
||||
{
|
||||
Directory.CreateDirectory(Assetpath);
|
||||
}
|
||||
|
||||
// 构建完整的保存路径
|
||||
string jsonFilePath = Path.Combine(Assetpath, $"{assetName}.json");
|
||||
|
||||
// 序列化数据为JSON
|
||||
string jsonContent = JsonConvert.SerializeObject(data, Formatting.Indented);
|
||||
|
||||
// 写入文件
|
||||
File.WriteAllText(jsonFilePath, jsonContent);
|
||||
|
||||
// 刷新AssetDatabase
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
Debug.Log($"UnityEvo: JSON文件已保存到 {jsonFilePath}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@@ -363,7 +432,7 @@ namespace Stary.Evo.TableTextConversion
|
||||
string[] xlsxFiles = Directory.GetFiles(docFolderPath, "*.xlsx");
|
||||
|
||||
result = xlsxFiles.Select(file => Path.GetFileNameWithoutExtension(file)).ToList();
|
||||
|
||||
selectedExslNames = EditorPrefs.GetString("BuildExslNames");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -371,15 +440,25 @@ namespace Stary.Evo.TableTextConversion
|
||||
{
|
||||
DocFolderPath = Path.Combine(GetDocFolderPath(), newValue + ".xlsx");
|
||||
newDataName = newValue;
|
||||
EditorPrefs.SetString("BuildExslNames", newDataName);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取全部作用域名
|
||||
/// </summary>
|
||||
public static List<string> GetCreatDomainAllName()
|
||||
public List<string> GetCreatDomainAllName()
|
||||
{
|
||||
string domainPath = $"{Application.dataPath}/Domain";
|
||||
string domainPath = "";
|
||||
if (configurationFileType == ConfigurationFileType.Asset)
|
||||
{
|
||||
domainPath = $"{Application.dataPath}/Domain";
|
||||
}
|
||||
else if (configurationFileType == ConfigurationFileType.Json)
|
||||
{
|
||||
domainPath = $"{Application.dataPath}/Modules";
|
||||
}
|
||||
|
||||
string[] domains;
|
||||
// 新增目录获取代码
|
||||
if (Directory.Exists(domainPath))
|
||||
@@ -395,12 +474,53 @@ namespace Stary.Evo.TableTextConversion
|
||||
domains = Array.Empty<string>();
|
||||
}
|
||||
|
||||
return domains.Select(file => Path.GetFileNameWithoutExtension(file)).ToList();
|
||||
if (configurationFileType == ConfigurationFileType.Asset)
|
||||
{
|
||||
selectedDomainNames = EditorPrefs.GetString("CurrentDomainName");
|
||||
}
|
||||
else if (configurationFileType == ConfigurationFileType.Json)
|
||||
{
|
||||
selectedDomainNames = EditorPrefs.GetString("CurrentModulesName");
|
||||
}
|
||||
|
||||
return domains.ToList();
|
||||
}
|
||||
|
||||
private void SetCurrentDomainName(string newValue)
|
||||
{
|
||||
Assetpath = Application.dataPath + "/Domain/" + newValue + "/AddressableRes/Config/";
|
||||
if (configurationFileType == ConfigurationFileType.Asset)
|
||||
{
|
||||
Assetpath = Application.dataPath + "/Domain/" + newValue + "/AddressableRes/Config/";
|
||||
EditorPrefs.SetString("CurrentDomainName", newValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assetpath = Application.dataPath + "/Modules/" + newValue + "/Main/Res/Config/";
|
||||
EditorPrefs.SetString("CurrentModulesName", newValue);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(Assetpath))
|
||||
{
|
||||
Directory.CreateDirectory(Assetpath);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetConfigurationFileType()
|
||||
{
|
||||
EditorPrefs.SetString("ConfigurationFileType", configurationFileType.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public enum ConfigurationFileType
|
||||
{
|
||||
/// <summary>
|
||||
/// json类型
|
||||
/// </summary>
|
||||
Json,
|
||||
|
||||
/// <summary>
|
||||
/// asset类型
|
||||
/// </summary>
|
||||
Asset
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user