2025-04-01 18:26:48 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using Excel;
|
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
|
|
using Sirenix.OdinInspector.Editor;
|
|
|
|
|
|
using System.Linq;
|
2025-11-12 14:22:04 +08:00
|
|
|
|
using Newtonsoft.Json;
|
2025-04-01 18:26:48 +08:00
|
|
|
|
using Stary.Evo.TableTextConversion;
|
2025-11-12 14:22:04 +08:00
|
|
|
|
using UnityEngine.Serialization;
|
2025-04-01 18:26:48 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Stary.Evo.TableTextConversion
|
|
|
|
|
|
{
|
|
|
|
|
|
public class ConvertedExslDataMessage : OdinEditorWindow
|
|
|
|
|
|
{
|
2025-11-12 14:22:04 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 配置文件类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[EnumToggleButtons, HideLabel] [OnValueChanged("SetConfigurationFileType")]
|
|
|
|
|
|
public ConfigurationFileType configurationFileType = ConfigurationFileType.Asset;
|
|
|
|
|
|
|
2025-04-01 18:26:48 +08:00
|
|
|
|
private static ConvertedExslDataMessage window;
|
|
|
|
|
|
|
|
|
|
|
|
// 读取的位置
|
|
|
|
|
|
private static string DocFolderPath;
|
|
|
|
|
|
|
|
|
|
|
|
// 生成配置文件的位置
|
|
|
|
|
|
private static string Assetpath;
|
2025-04-21 11:11:02 +08:00
|
|
|
|
|
2025-04-01 18:26:48 +08:00
|
|
|
|
// 转化表的名称
|
|
|
|
|
|
private static string newDataName;
|
|
|
|
|
|
|
2025-04-11 11:10:16 +08:00
|
|
|
|
[MenuItem("Evo/Exsl配置表/信息表转换")]
|
2025-04-01 18:26:48 +08:00
|
|
|
|
static void ShowWindows()
|
|
|
|
|
|
{
|
|
|
|
|
|
window = (ConvertedExslDataMessage)EditorWindow.GetWindow(typeof(ConvertedExslDataMessage));
|
2025-11-12 15:03:21 +08:00
|
|
|
|
// 添加空值检查,确保selectedDomainNames不会为null
|
|
|
|
|
|
window.selectedDomainNames = EditorPrefs.GetString("CurrentModulesName", "");
|
|
|
|
|
|
window.configurationFileType = (ConfigurationFileType)Enum.Parse(typeof(ConfigurationFileType),
|
|
|
|
|
|
EditorPrefs.GetString("ConfigurationFileType"));
|
2025-04-01 18:26:48 +08:00
|
|
|
|
window.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Title("转化配置的Exsl文件:", titleAlignment: TitleAlignments.Centered)]
|
|
|
|
|
|
[HorizontalGroup("BuildPipeline"), HideLabel]
|
|
|
|
|
|
[ValueDropdown("GetBuildExslNames")]
|
|
|
|
|
|
[OnValueChanged("SetBuildExslNames")]
|
|
|
|
|
|
public string selectedExslNames;
|
|
|
|
|
|
|
|
|
|
|
|
[Title("转化文件存储的作用域:", titleAlignment: TitleAlignments.Centered)]
|
|
|
|
|
|
[HorizontalGroup("BuildPipeline"), HideLabel]
|
|
|
|
|
|
[ValueDropdown("GetCreatDomainAllName")]
|
|
|
|
|
|
[OnValueChanged("SetCurrentDomainName")]
|
|
|
|
|
|
public string selectedDomainNames;
|
|
|
|
|
|
|
|
|
|
|
|
#region 信息表转存
|
|
|
|
|
|
|
|
|
|
|
|
//[MenuItem("Exsl/信息表转换")]
|
|
|
|
|
|
[Button("转化Exsl表格", ButtonSizes.Large)]
|
2025-11-12 14:22:04 +08:00
|
|
|
|
public void CrtateMessage()
|
2025-04-01 18:26:48 +08:00
|
|
|
|
{
|
|
|
|
|
|
#region 读取Excel表格并转成DataSet类型的数据
|
|
|
|
|
|
|
|
|
|
|
|
if (DocFolderPath == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("UnityEvo:请先选择Exsl文件");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Assetpath == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("UnityEvo:请先选择生成配置文件的位置");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*if (!Directory.Exists(DocFolderPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("UnityEvo:Exsl文件不存在");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(Assetpath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("UnityEvo:生成配置文件的位置不存在");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-04-21 11:11:02 +08:00
|
|
|
|
|
2025-04-01 18:26:48 +08:00
|
|
|
|
FileStream stream = File.Open(DocFolderPath, FileMode.Open, FileAccess.Read);
|
|
|
|
|
|
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
|
|
|
|
|
|
//获取结果
|
|
|
|
|
|
DataSet result = excelReader.AsDataSet();
|
2025-04-21 11:11:02 +08:00
|
|
|
|
if (result.Tables.Count > 0)
|
2025-04-01 18:26:48 +08:00
|
|
|
|
{
|
2025-04-21 11:11:02 +08:00
|
|
|
|
for (int i = 0; i < result.Tables.Count; i++)
|
2025-04-01 18:26:48 +08:00
|
|
|
|
{
|
2025-04-25 10:02:32 +08:00
|
|
|
|
var table = result.Tables[i];
|
2025-04-21 11:11:02 +08:00
|
|
|
|
//开始遍历说有table表
|
2025-04-25 10:02:32 +08:00
|
|
|
|
int oneRows = table.Rows.Count; //行数
|
2025-04-21 11:11:02 +08:00
|
|
|
|
Dictionary<int, int> dict_Question = new Dictionary<int, int>();
|
|
|
|
|
|
Dictionary<int, int> dict_Menu = new Dictionary<int, int>();
|
|
|
|
|
|
|
|
|
|
|
|
#region 通过遍历一遍表格所有行的第一列【序号】不为空
|
|
|
|
|
|
|
|
|
|
|
|
int VoiceCount = 0;
|
|
|
|
|
|
for (int j = 0; j < oneRows; j++)
|
|
|
|
|
|
{
|
2025-04-25 10:02:32 +08:00
|
|
|
|
// string key = FilterTo(table.Rows[j][0].ToString());
|
|
|
|
|
|
// if (!string.IsNullOrEmpty(key))
|
|
|
|
|
|
// {
|
2025-11-17 14:48:50 +08:00
|
|
|
|
if (table.Rows[j].ItemArray.Length > 0 &&
|
|
|
|
|
|
!string.IsNullOrEmpty(FilterTo(table.Rows[j][0].ToString())))
|
|
|
|
|
|
{
|
|
|
|
|
|
VoiceCount++;
|
|
|
|
|
|
}
|
2025-04-25 10:02:32 +08:00
|
|
|
|
// }
|
2025-04-21 11:11:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region AudioTableData
|
|
|
|
|
|
|
2025-11-17 14:48:50 +08:00
|
|
|
|
if (table.TableName.ToLower().Contains("au"))
|
2025-04-21 11:11:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
#region 遍历表格相应的数据转换成数据
|
|
|
|
|
|
|
2025-11-12 14:22:04 +08:00
|
|
|
|
List<AudioEntity> messageInfos = new List<AudioEntity>();
|
2025-04-21 11:11:02 +08:00
|
|
|
|
for (int j = 1; j < VoiceCount; j++)
|
|
|
|
|
|
{
|
2025-11-12 14:22:04 +08:00
|
|
|
|
AudioEntity messageInfo = new AudioEntity();
|
2025-04-21 11:11:02 +08:00
|
|
|
|
//获取对话块
|
|
|
|
|
|
messageInfo.index = j - 1;
|
|
|
|
|
|
//文件名称
|
2025-04-25 10:02:32 +08:00
|
|
|
|
messageInfo.auid = FilterTo(table.Rows[j][0].ToString());
|
2025-04-21 11:11:02 +08:00
|
|
|
|
//获取内容
|
2025-04-25 10:02:32 +08:00
|
|
|
|
messageInfo.autype =
|
|
|
|
|
|
Enum.TryParse(FilterTo(table.Rows[j][1].ToString()),
|
2025-11-12 14:22:04 +08:00
|
|
|
|
out AudioType auType)
|
2025-04-25 10:02:32 +08:00
|
|
|
|
? auType
|
2025-11-12 14:22:04 +08:00
|
|
|
|
: AudioType.Null;
|
2025-04-21 11:11:02 +08:00
|
|
|
|
|
|
|
|
|
|
//获取描述
|
2025-04-25 10:02:32 +08:00
|
|
|
|
messageInfo.filename = FilterTo(table.Rows[j][2].ToString());
|
|
|
|
|
|
|
|
|
|
|
|
messageInfo.voice = FilterTo(table.Rows[j][3].ToString());
|
2025-04-21 11:11:02 +08:00
|
|
|
|
|
2025-11-12 14:22:04 +08:00
|
|
|
|
|
2025-05-14 18:18:39 +08:00
|
|
|
|
messageInfo.uirelated = FilterTo(table.Rows[j][4].ToString());
|
2025-04-21 11:11:02 +08:00
|
|
|
|
//添加数据
|
|
|
|
|
|
messageInfos.Add(messageInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2025-11-12 14:22:04 +08:00
|
|
|
|
if (configurationFileType == ConfigurationFileType.Asset)
|
|
|
|
|
|
{
|
|
|
|
|
|
ScriptObjectSave<AudioTableData>("AudioTableData", (data) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
data.infos = new List<AudioEntity>();
|
|
|
|
|
|
data.infos = messageInfos;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (configurationFileType == ConfigurationFileType.Json)
|
2025-04-21 11:11:02 +08:00
|
|
|
|
{
|
2025-11-12 14:22:04 +08:00
|
|
|
|
JsonSave<List<AudioEntity>>("AudioTableData", () => { return messageInfos; });
|
|
|
|
|
|
}
|
2025-04-21 11:11:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2025-04-25 10:02:32 +08:00
|
|
|
|
|
2025-04-21 15:46:47 +08:00
|
|
|
|
#region VideoTableData
|
2025-04-21 11:11:02 +08:00
|
|
|
|
|
2025-11-17 14:48:50 +08:00
|
|
|
|
if (table.TableName.ToLower().Contains("vid"))
|
2025-04-21 11:11:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
#region 遍历表格相应的数据转换成数据
|
|
|
|
|
|
|
2025-11-12 14:22:04 +08:00
|
|
|
|
List<VideoEntity> messageInfos = new List<VideoEntity>();
|
2025-04-21 11:11:02 +08:00
|
|
|
|
for (int j = 1; j < VoiceCount; j++)
|
|
|
|
|
|
{
|
2025-11-12 14:22:04 +08:00
|
|
|
|
VideoEntity messageInfo = new VideoEntity();
|
2025-04-21 11:11:02 +08:00
|
|
|
|
//获取对话块
|
|
|
|
|
|
messageInfo.index = j - 1;
|
|
|
|
|
|
//文件名称
|
2025-04-25 10:02:32 +08:00
|
|
|
|
messageInfo.vidid = FilterTo(table.Rows[j][0].ToString());
|
2025-04-21 11:11:02 +08:00
|
|
|
|
//获取内容
|
2025-04-25 10:02:32 +08:00
|
|
|
|
messageInfo.filename = FilterTo(table.Rows[j][1].ToString());
|
2025-04-21 11:11:02 +08:00
|
|
|
|
|
|
|
|
|
|
//获取描述
|
2025-04-25 10:02:32 +08:00
|
|
|
|
messageInfo.vidtype = FilterTo(table.Rows[j][2].ToString());
|
|
|
|
|
|
|
|
|
|
|
|
messageInfo.location = FilterTo(table.Rows[j][3].ToString());
|
|
|
|
|
|
|
|
|
|
|
|
messageInfo.time =
|
|
|
|
|
|
float.TryParse(FilterTo(table.Rows[j][4].ToString()), out float start)
|
|
|
|
|
|
? start
|
|
|
|
|
|
: 0;
|
|
|
|
|
|
messageInfo.subtitle = FilterTo(table.Rows[j][5].ToString()).Equals("是")
|
|
|
|
|
|
? true
|
|
|
|
|
|
: false;
|
2025-08-01 20:00:14 +08:00
|
|
|
|
messageInfo.videoframeName = FilterTo(table.Rows[j][6].ToString());
|
2025-11-12 14:22:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-21 11:11:02 +08:00
|
|
|
|
//添加数据
|
|
|
|
|
|
messageInfos.Add(messageInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2025-11-12 14:22:04 +08:00
|
|
|
|
|
|
|
|
|
|
if (configurationFileType == ConfigurationFileType.Asset)
|
2025-04-21 11:11:02 +08:00
|
|
|
|
{
|
2025-11-12 14:22:04 +08:00
|
|
|
|
ScriptObjectSave<VideoTableData>("VideoTableData", (data) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
data.infos = new List<VideoEntity>();
|
|
|
|
|
|
data.infos = messageInfos;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (configurationFileType == ConfigurationFileType.Json)
|
|
|
|
|
|
{
|
|
|
|
|
|
JsonSave<List<VideoEntity>>("VideoTableData", () => { return messageInfos; });
|
|
|
|
|
|
}
|
2025-04-21 11:11:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2025-04-25 10:02:32 +08:00
|
|
|
|
|
2025-04-21 15:46:47 +08:00
|
|
|
|
#region UITableData
|
|
|
|
|
|
|
2025-11-17 14:48:50 +08:00
|
|
|
|
if (table.TableName.ToLower().Contains("ui"))
|
2025-04-21 15:46:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
#region 遍历表格相应的数据转换成数据
|
|
|
|
|
|
|
2025-11-12 14:22:04 +08:00
|
|
|
|
List<UIEntity> messageInfos = new List<UIEntity>();
|
|
|
|
|
|
UIEntity messageInfo = null;
|
|
|
|
|
|
List<SubtitleInfo> subtitle = null;
|
2025-04-25 10:02:32 +08:00
|
|
|
|
int infoIndex = 0;
|
2025-04-21 15:46:47 +08:00
|
|
|
|
for (int j = 1; j < VoiceCount; j++)
|
|
|
|
|
|
{
|
2025-04-25 10:02:32 +08:00
|
|
|
|
Debug.Log(j);
|
|
|
|
|
|
if (!table.Rows[j][0].ToString().Equals(""))
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log(table.Rows[j][0].ToString());
|
2025-11-12 14:22:04 +08:00
|
|
|
|
messageInfo = new UIEntity();
|
|
|
|
|
|
subtitle = new List<SubtitleInfo>();
|
2025-04-25 10:02:32 +08:00
|
|
|
|
messageInfo.subtitle = subtitle;
|
|
|
|
|
|
//获取对话块
|
|
|
|
|
|
messageInfo.index = infoIndex;
|
|
|
|
|
|
//文件名称
|
|
|
|
|
|
messageInfo.uiid = FilterTo(table.Rows[j][0].ToString());
|
|
|
|
|
|
//获取内容
|
|
|
|
|
|
messageInfo.filename = FilterTo(table.Rows[j][1].ToString());
|
|
|
|
|
|
|
|
|
|
|
|
//获取描述
|
|
|
|
|
|
messageInfo.uitype = FilterTo(table.Rows[j][2].ToString());
|
|
|
|
|
|
|
|
|
|
|
|
if (!table.Rows[j][3].ToString().Equals(""))
|
|
|
|
|
|
{
|
2025-11-12 14:22:04 +08:00
|
|
|
|
var subtitleInfo = new SubtitleInfo();
|
2025-04-25 10:02:32 +08:00
|
|
|
|
subtitleInfo.lineid = FilterTo(table.Rows[j][3].ToString());
|
|
|
|
|
|
subtitleInfo.subtitle = FilterTo(table.Rows[j][4].ToString());
|
|
|
|
|
|
subtitleInfo.start =
|
|
|
|
|
|
float.TryParse(FilterTo(table.Rows[j][5].ToString()),
|
|
|
|
|
|
out float start)
|
|
|
|
|
|
? start
|
|
|
|
|
|
: 0;
|
|
|
|
|
|
subtitleInfo.end = float.TryParse(FilterTo(table.Rows[j][6].ToString()),
|
|
|
|
|
|
out float end)
|
|
|
|
|
|
? end
|
|
|
|
|
|
: 0;
|
|
|
|
|
|
messageInfo.subtitle.Add(subtitleInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-12 14:22:04 +08:00
|
|
|
|
|
2025-04-25 10:02:32 +08:00
|
|
|
|
//添加数据
|
|
|
|
|
|
messageInfos.Add(messageInfo);
|
|
|
|
|
|
infoIndex++;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!table.Rows[j][3].ToString().Equals(""))
|
|
|
|
|
|
{
|
2025-11-12 14:22:04 +08:00
|
|
|
|
var subtitleInfo = new SubtitleInfo();
|
2025-04-25 10:02:32 +08:00
|
|
|
|
subtitleInfo.lineid = FilterTo(table.Rows[j][3].ToString());
|
|
|
|
|
|
subtitleInfo.subtitle = FilterTo(table.Rows[j][4].ToString());
|
|
|
|
|
|
subtitleInfo.start =
|
|
|
|
|
|
float.TryParse(FilterTo(table.Rows[j][5].ToString()),
|
|
|
|
|
|
out float start)
|
|
|
|
|
|
? start
|
|
|
|
|
|
: 0;
|
|
|
|
|
|
subtitleInfo.end = float.TryParse(FilterTo(table.Rows[j][6].ToString()),
|
|
|
|
|
|
out float end)
|
|
|
|
|
|
? end
|
|
|
|
|
|
: 0;
|
|
|
|
|
|
messageInfo.subtitle.Add(subtitleInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-21 15:46:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2025-11-12 14:22:04 +08:00
|
|
|
|
if (configurationFileType == ConfigurationFileType.Asset)
|
2025-04-21 15:46:47 +08:00
|
|
|
|
{
|
2025-11-12 14:22:04 +08:00
|
|
|
|
ScriptObjectSave<UITableData>("UITableData", (data) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
data.infos = new List<UIEntity>();
|
|
|
|
|
|
data.infos = messageInfos;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (configurationFileType == ConfigurationFileType.Json)
|
|
|
|
|
|
{
|
|
|
|
|
|
JsonSave<List<UIEntity>>("UITableData", () => { return messageInfos; });
|
|
|
|
|
|
}
|
2025-04-21 15:46:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2025-04-25 10:02:32 +08:00
|
|
|
|
|
2025-04-21 11:11:02 +08:00
|
|
|
|
#endregion
|
2025-04-01 18:26:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 过滤:去掉首尾空格和换行符【\n】
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static string FilterTo(string self)
|
|
|
|
|
|
{
|
|
|
|
|
|
self = self.TrimStart();
|
|
|
|
|
|
self = self.TrimEnd();
|
|
|
|
|
|
self = self.Replace("\n", "");
|
|
|
|
|
|
return self;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// ScriptObject数据保存类
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="assetName"></param>
|
|
|
|
|
|
/// <param name="action">写入数据的一个回调</param>
|
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
|
private static void ScriptObjectSave<T>(string assetName, Action<T> action) where T : ScriptableObject
|
|
|
|
|
|
{
|
|
|
|
|
|
string jsonPath = $"{Assetpath}{assetName}.asset";
|
|
|
|
|
|
if (File.Exists(jsonPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorFrameworkUtils.DeleteFile(Assetpath, assetName + ".asset");
|
|
|
|
|
|
AssetDatabase.SaveAssets();
|
|
|
|
|
|
AssetDatabase.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
jsonPath = jsonPath.Substring(jsonPath.IndexOf("Assets"));
|
|
|
|
|
|
// Debug.Log($"要创建的为{jsonPath}");
|
|
|
|
|
|
var data = ScriptableObject.CreateInstance<T>();
|
|
|
|
|
|
//放写入数据操作
|
|
|
|
|
|
action.Invoke(data);
|
|
|
|
|
|
|
|
|
|
|
|
AssetDatabase.CreateAsset(data, jsonPath);
|
|
|
|
|
|
AssetDatabase.SaveAssets();
|
|
|
|
|
|
AssetDatabase.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-12 14:22:04 +08:00
|
|
|
|
/// <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}");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-01 18:26:48 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取Doc文件夹的路径
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private string GetDocFolderPath()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取 Assets 文件夹的路径
|
|
|
|
|
|
string assetsPath = Application.dataPath;
|
|
|
|
|
|
|
|
|
|
|
|
// 获取项目的根目录路径
|
|
|
|
|
|
string projectRootPath = Path.GetDirectoryName(assetsPath);
|
|
|
|
|
|
|
|
|
|
|
|
// 构造 Doc 文件夹的路径
|
|
|
|
|
|
string docFolderPath = Path.Combine(projectRootPath, "Doc");
|
|
|
|
|
|
|
|
|
|
|
|
return docFolderPath;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取Doc文件夹下所有的Exsl名
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private List<string> GetBuildExslNames()
|
|
|
|
|
|
{
|
|
|
|
|
|
string docFolderPath = GetDocFolderPath();
|
|
|
|
|
|
|
|
|
|
|
|
// 检查 Doc 文件夹是否存在
|
|
|
|
|
|
if (!Directory.Exists(docFolderPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"UnityEvo:Doc 文件夹不存在,请检查路径:{docFolderPath}");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<string> result = new List<string>();
|
2025-11-17 14:48:50 +08:00
|
|
|
|
result.Add("null");
|
2025-04-01 18:26:48 +08:00
|
|
|
|
// 遍历 Doc 文件夹中的所有 .xlsx 文件
|
|
|
|
|
|
string[] xlsxFiles = Directory.GetFiles(docFolderPath, "*.xlsx");
|
|
|
|
|
|
|
2025-11-17 14:48:50 +08:00
|
|
|
|
result.AddRange(xlsxFiles.Select(file => Path.GetFileNameWithoutExtension(file)).ToList());
|
2025-11-12 14:22:04 +08:00
|
|
|
|
selectedExslNames = EditorPrefs.GetString("BuildExslNames");
|
2025-04-01 18:26:48 +08:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetBuildExslNames(string newValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
DocFolderPath = Path.Combine(GetDocFolderPath(), newValue + ".xlsx");
|
|
|
|
|
|
newDataName = newValue;
|
2025-11-12 14:22:04 +08:00
|
|
|
|
EditorPrefs.SetString("BuildExslNames", newDataName);
|
2025-04-01 18:26:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取全部作用域名
|
|
|
|
|
|
/// </summary>
|
2025-11-12 14:22:04 +08:00
|
|
|
|
public List<string> GetCreatDomainAllName()
|
2025-04-01 18:26:48 +08:00
|
|
|
|
{
|
2025-11-12 14:22:04 +08:00
|
|
|
|
string domainPath = "";
|
|
|
|
|
|
if (configurationFileType == ConfigurationFileType.Asset)
|
|
|
|
|
|
{
|
|
|
|
|
|
domainPath = $"{Application.dataPath}/Domain";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (configurationFileType == ConfigurationFileType.Json)
|
|
|
|
|
|
{
|
|
|
|
|
|
domainPath = $"{Application.dataPath}/Modules";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-17 14:48:50 +08:00
|
|
|
|
List<string> domains = new List<string>();
|
|
|
|
|
|
domains.Add("null");
|
2025-04-01 18:26:48 +08:00
|
|
|
|
// 新增目录获取代码
|
|
|
|
|
|
if (Directory.Exists(domainPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
var dirInfo = new DirectoryInfo(domainPath);
|
|
|
|
|
|
// 获取直接子目录(不递归)
|
2025-11-17 14:48:50 +08:00
|
|
|
|
domains.AddRange(dirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly)
|
|
|
|
|
|
.Select(d => d.Name).ToList());
|
2025-04-01 18:26:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-12 14:22:04 +08:00
|
|
|
|
if (configurationFileType == ConfigurationFileType.Asset)
|
|
|
|
|
|
{
|
|
|
|
|
|
selectedDomainNames = EditorPrefs.GetString("CurrentDomainName");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (configurationFileType == ConfigurationFileType.Json)
|
|
|
|
|
|
{
|
|
|
|
|
|
selectedDomainNames = EditorPrefs.GetString("CurrentModulesName");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return domains.ToList();
|
2025-04-01 18:26:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetCurrentDomainName(string newValue)
|
|
|
|
|
|
{
|
2025-11-12 14:22:04 +08:00
|
|
|
|
if (configurationFileType == ConfigurationFileType.Asset)
|
|
|
|
|
|
{
|
|
|
|
|
|
Assetpath = Application.dataPath + "/Domain/" + newValue + "/AddressableRes/Config/";
|
2025-11-12 15:03:21 +08:00
|
|
|
|
string valueToSave = string.IsNullOrEmpty(selectedDomainNames) ? "" : selectedDomainNames;
|
|
|
|
|
|
EditorPrefs.SetString("CurrentDomainName", valueToSave);
|
2025-11-12 14:22:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Assetpath = Application.dataPath + "/Modules/" + newValue + "/Main/Res/Config/";
|
2025-11-12 15:03:21 +08:00
|
|
|
|
string valueToSave = string.IsNullOrEmpty(selectedDomainNames) ? "" : selectedDomainNames;
|
|
|
|
|
|
EditorPrefs.SetString("CurrentModulesName", valueToSave);
|
2025-11-12 14:22:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(Assetpath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(Assetpath);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetConfigurationFileType()
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorPrefs.SetString("ConfigurationFileType", configurationFileType.ToString());
|
2025-04-01 18:26:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-12 14:22:04 +08:00
|
|
|
|
|
|
|
|
|
|
public enum ConfigurationFileType
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// json类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
Json,
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// asset类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
Asset
|
|
|
|
|
|
}
|
2025-04-01 18:26:48 +08:00
|
|
|
|
}
|