多语言修改和版本号降低至0

This commit is contained in:
wuwenbo 2026-01-06 17:35:18 +08:00
parent b5377a3d5d
commit 57ced35080
6 changed files with 126 additions and 56 deletions

View File

@ -1,11 +1,17 @@
# -*- coding: utf-8 -*-
import sys
import io
# 强制 UTF-8 输出
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
import openpyxl
import os
from datetime import datetime
def log(message):
print(f"[{datetime.now()}] {message}", file=sys.stderr)
print(f"[{datetime.now()}] {message}")
def parse_special_format(content):
"""解析特殊标记格式的数据"""
@ -16,7 +22,7 @@ def parse_special_format(content):
continue
# 按字段分割
fields = [f.strip() for f in record.split('%$#@!')]
if len(fields) == 7: # ID,ZH,EN,JP,KR
if len(fields) == 11: # ID,ZH,EN,JP,KR
records.append(fields)
else:
log(f"忽略格式错误的记录: {record}")
@ -36,7 +42,7 @@ def convert_file():
wb = openpyxl.Workbook()
ws = wb.active
ws.append(["ID", "中文", "繁中", "英文", "日文", "韩文"]) # 添加标题行
ws.append(["ID", "是否存在", "中文", "繁中", "英文", "日文", "韩文", "专有名词", "台词", "台词说话者", "已废弃"]) # 添加标题行
for row in records:
ws.append(row)
@ -45,7 +51,7 @@ def convert_file():
log(f"成功转换 {len(records)} 条记录")
return True
except Exception as e:
log(f"转换失败: {str(e)}")
print(f"转换失败: {str(e)}", file=sys.stderr) # 只有错误才输出到 stderr
return False

View File

@ -1,38 +1,40 @@
# -*- coding: utf-8 -*-
import sys
import io
# 强制 UTF-8 输出
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
import openpyxl
import os
from datetime import datetime
def log(message):
print(f"[{datetime.now()}] {message}", file=sys.stderr)
print(f"[{datetime.now()}] {message}") # 移除 file=sys.stderr
def convert_excel_to_txt():
try:
excel_path = r"../Tools/Multilingual.xlsx"
txt_path = r"../Tools/MultilingualTxt.txt"
# 读取Excel文件跳过标题行
wb = openpyxl.load_workbook(excel_path)
ws = wb.active
records = []
for row in ws.iter_rows(min_row=2, values_only=True):
# 确保总是有6个字段空值转为空字符串
normalized_row = [str(cell).strip() if cell is not None else "" for cell in row]
if len(normalized_row) >= 7: # 只取前6列
records.append(normalized_row[:7])
else: # 不足6列则补齐空字符串
records.append(normalized_row + [""]*(7-len(normalized_row)))
if len(normalized_row) >= 10:
records.append(normalized_row[:10])
else:
records.append(normalized_row + [""]*(10-len(normalized_row)))
if not records:
log("错误Excel中没有有效数据")
log("错误:Excel中没有有效数据")
return False
# 写入TXT文件使用指定分隔符格式
os.makedirs(os.path.dirname(txt_path), exist_ok=True)
with open(txt_path, 'w', encoding='utf-8') as f:
for record in records:
# 确保总是6个字段空字段也会保留分隔符
line = '%$#@!'.join(field for field in record) + '!@#$%'
f.write(line)
@ -40,7 +42,7 @@ def convert_excel_to_txt():
return True
except Exception as e:
log(f"转换失败: {str(e)}")
print(f"转换失败: {str(e)}", file=sys.stderr) # 只有错误才输出到 stderr
return False
if __name__ == "__main__":

File diff suppressed because one or more lines are too long

View File

@ -80,6 +80,15 @@ namespace Logic.Editor
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
// 所有已存在的版本号主版本号降低至0
if (InspectorUtils.InspectorButtonWithTextWidth("主版本号降低至0"))
{
foreach (var version in _asset.Versions)
{
version.MajorVersion = 0;
_asset.Versions = _asset.Versions.OrderByDescending(v => v.VersionId).ToList();
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();

View File

@ -43,6 +43,11 @@ namespace Logic.Editor
private List<TMP_FontAsset> _assets = new List<TMP_FontAsset>();
private HashSet<char> characterSet = new HashSet<char>();
private bool _isActive = true;
private bool _isProperNoun = true;
private bool _isDialogue = true;
private bool _isDeprecated = false;
[MenuItem("Tools/多语言编辑器")]
private static void ShowWindow()
@ -204,9 +209,25 @@ namespace Logic.Editor
{
OnBuildChineseTxt();
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
EditorGUILayout.BeginVertical(_redBoxStyle);
_isActive = EditorGUILayout.Toggle("筛选活跃文本", _isActive);
_isProperNoun = EditorGUILayout.Toggle("筛选专有名词", _isProperNoun);
_isDialogue = EditorGUILayout.Toggle("筛选对话文本", _isDialogue);
_isDeprecated = EditorGUILayout.Toggle("筛选已废弃文本", _isDeprecated);
if (InspectorUtils.InspectorButtonWithTextWidth("导出 Excel 筛选类型文本"))
{
AssetExportToExcel(true);
}
if (InspectorUtils.InspectorButtonWithTextWidth("导出 Excel Prefab 筛选类型文本"))
{
AssetExportToExcelPrefab(true);
}
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
EditorGUILayout.BeginVertical(_whiteBoxStyle);
if (_asset.TargetTypes.Count != 5)
{
@ -371,11 +392,15 @@ namespace Logic.Editor
}
item.ID = id;
if (cells.Length >= 2) item.ZH = RemoveCsvQuotes(cells[1]);
if (cells.Length >= 3) item.TDZH = RemoveCsvQuotes(cells[2]);
if (cells.Length >= 4) item.EN = RemoveCsvQuotes(cells[3]);
if (cells.Length >= 5) item.JP = RemoveCsvQuotes(cells[4]);
if (cells.Length >= 6) item.KR = RemoveCsvQuotes(cells[5]);
if (cells.Length >= 3) item.ZH = RemoveCsvQuotes(cells[2]);
if (cells.Length >= 4) item.TDZH = RemoveCsvQuotes(cells[3]);
if (cells.Length >= 5) item.EN = RemoveCsvQuotes(cells[4]);
if (cells.Length >= 6) item.JP = RemoveCsvQuotes(cells[5]);
if (cells.Length >= 7) item.KR = RemoveCsvQuotes(cells[6]);
if (cells.Length >= 8) item.IsProperNoun = MultilingualItem.ParseBoolStr(RemoveCsvQuotes(cells[7]));
if (cells.Length >= 9) item.IsDialogue = MultilingualItem.ParseBoolStr(RemoveCsvQuotes(cells[8]));
if (cells.Length >= 10) item.DialogueSpeaker = RemoveCsvQuotes(cells[9]);
if (cells.Length >= 11) item.IsDeprecated = MultilingualItem.ParseBoolStr(RemoveCsvQuotes(cells[10]));
}
EditorUtility.SetDirty(_asset);
@ -383,7 +408,7 @@ namespace Logic.Editor
AssetDatabase.Refresh();
}
private void AssetExportToExcel()
private void AssetExportToExcel(bool isFilter = false)
{
DuplicateRemoval();
_zhStrDict.Clear();
@ -464,8 +489,16 @@ namespace Logic.Editor
StringBuilder sb = new StringBuilder();
foreach (var item in _asset.Items)
{
var active = _activeSet.Contains(item.ID) ? 1 : 0;
sb.Append($"{item.ID}%$#@!{item.ZH}%$#@!{item.TDZH}%$#@!{item.EN}%$#@!{item.JP}%$#@!{item.KR}%$#@!{active}!@#$%");
if (isFilter)
{
if (_isActive && !_activeSet.Contains(item.ID)) continue;
if (_isProperNoun && !item.IsProperNoun) continue;
if (_isDialogue && !item.IsDialogue) continue;
if (_isDeprecated && !item.IsDeprecated) continue;
}
var active = _activeSet.Contains(item.ID);
sb.Append($"{item.ID}%$#@!{active}%$#@!{item.ZH}%$#@!{item.TDZH}%$#@!{item.EN}%$#@!{item.JP}%$#@!{item.KR}" +
$"%$#@!{item.IsProperNoun}%$#@!{item.IsDialogue}%$#@!{item.DialogueSpeaker}%$#@!{item.IsDeprecated}!@#$%");
}
sw.Write(sb.ToString());
}
@ -476,7 +509,7 @@ namespace Logic.Editor
AssetDatabase.Refresh();
}
private void AssetExportToExcelPrefab()
private void AssetExportToExcelPrefab(bool isFilter = false)
{
DuplicateRemoval();
_zhStrDict.Clear();
@ -551,8 +584,16 @@ namespace Logic.Editor
StringBuilder sb = new StringBuilder();
foreach (var item in _asset.Items)
{
if (isFilter)
{
if (_isActive && !_activeSet.Contains(item.ID)) continue;
if (_isProperNoun && !item.IsProperNoun) continue;
if (_isDialogue && !item.IsDialogue) continue;
if (_isDeprecated && !item.IsDeprecated) continue;
}
var active = _activeSet.Contains(item.ID) ? 1 : 0;
sb.Append($"{item.ID}%$#@!{item.ZH}%$#@!{item.TDZH}%$#@!{item.EN}%$#@!{item.JP}%$#@!{item.KR}%$#@!{active}!@#$%");
sb.Append($"{item.ID}%$#@!{active}%$#@!{item.ZH}%$#@!{item.TDZH}%$#@!{item.EN}%$#@!{item.JP}%$#@!{item.KR}" +
$"%$#@!{item.IsProperNoun}%$#@!{item.IsDialogue}%$#@!{item.DialogueSpeaker}%$#@!{item.IsDeprecated}!@#$%");
}
sw.Write(sb.ToString());
}

View File

@ -10,6 +10,7 @@ using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
@ -117,8 +118,12 @@ namespace Logic.Multilingual
public string EN;
public string JP;
public string KR;
public bool IsProperNoun;
public bool IsDialogue;
public string DialogueSpeaker;
public bool IsDeprecated;
public void Refresh()
{
ZH = ZH.Replace("\r\n", "\n");
@ -126,6 +131,13 @@ namespace Logic.Multilingual
EN = EN.Replace("\r\n", "\n");
JP = JP.Replace("\r\n", "\n");
KR = KR.Replace("\r\n", "\n");
DialogueSpeaker = DialogueSpeaker.Replace("\r\n", "\n");
}
// 不分大小写将 True 或者 False 字符串转换为布尔值
public static bool ParseBoolStr(string str)
{
return string.Equals(str, "True", StringComparison.OrdinalIgnoreCase);
}
}