修复音乐重复播放问题,增加繁中,优化编辑器

This commit is contained in:
wuwenbo 2025-05-29 15:25:54 +08:00
parent 862e22c0c6
commit 5f53414f89
6 changed files with 50 additions and 20 deletions

View File

@ -7,7 +7,6 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

View File

@ -46,7 +46,7 @@ namespace Logic.Audio
public void PlayMusic(string musicName, float fadeIn, float fadeOut, bool isLoop)
{
if (!_clips.ContainsKey(musicName)) return;
if (_musicPlayer != null && _musicPlayer.State == PlayerState.Playing) _musicPlayer.Stop();
if (_musicPlayer != null) _musicPlayer.Stop();
_musicPlayer = GetPlayer();
_musicPlayer.Clip = _clips[musicName];
_musicPlayer.IsLoop = isLoop;
@ -138,6 +138,7 @@ namespace Logic.Audio
public void Stop()
{
if (State == PlayerState.Finished || State == PlayerState.Prepare) return;
State = PlayerState.FadeOut;
EndTime = Time.time;
}

View File

@ -37,6 +37,7 @@ namespace Logic.Editor
private Dictionary<string, uint> _zhStrDict = new Dictionary<string, uint>();
private uint _idIndex;
private int _showIndex = 0;
[MenuItem("Tools/多语言编辑器")]
@ -129,11 +130,26 @@ namespace Logic.Editor
deleteSet.Add(_asset.FontGroups[i]);
}
foreach (var deleteGroup in deleteSet)_asset.FontGroups.Remove(deleteGroup);
foreach (var item in _asset.Items) ShowMultilingualItem(item);
ShowAllMultilingualItem();
EditorGUILayout.EndScrollView();
}
private void ShowAllMultilingualItem()
{
int maxIndex = (_asset.Items.Count - 1) / 10;
_showIndex = Mathf.Clamp(_showIndex, 0, maxIndex);
EditorGUILayout.BeginHorizontal();
if (_showIndex > 0 && InspectorUtils.InspectorButtonWithTextWidth("上一页")) _showIndex--;
if (_showIndex < maxIndex && InspectorUtils.InspectorButtonWithTextWidth("下一页")) _showIndex++;
EditorGUILayout.EndHorizontal();
for (int i = _showIndex * 10; i < (_showIndex + 1) * 10; i++)
{
if (i < 0 || i >= _asset.Items.Count) continue;
ShowMultilingualItem(_asset.Items[i]);
}
}
private bool ShowFontGroup(MultilingualFontGroup fontGroup)
{
var isDelete = false;
@ -143,6 +159,7 @@ namespace Logic.Editor
if (InspectorUtils.InspectorButtonWithTextWidth("x")) isDelete = true;
EditorGUILayout.EndHorizontal();
fontGroup.ZHFont = (TMP_FontAsset)EditorGUILayout.ObjectField(fontGroup.ZHFont, typeof(TMP_FontAsset), false);
fontGroup.TDZHFont = (TMP_FontAsset)EditorGUILayout.ObjectField(fontGroup.TDZHFont, typeof(TMP_FontAsset), false);
fontGroup.ENFont = (TMP_FontAsset)EditorGUILayout.ObjectField(fontGroup.ENFont, typeof(TMP_FontAsset), false);
fontGroup.JPFont = (TMP_FontAsset)EditorGUILayout.ObjectField(fontGroup.JPFont, typeof(TMP_FontAsset), false);
fontGroup.KRFont = (TMP_FontAsset)EditorGUILayout.ObjectField(fontGroup.KRFont, typeof(TMP_FontAsset), false);
@ -156,6 +173,8 @@ namespace Logic.Editor
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
InspectorUtils.InspectorTextWidthRich($"<b>{item.ID} : </b>");
InspectorUtils.InspectorTextWidthRich($" <b>中文:</b> {item.ZH}");
if (!string.IsNullOrEmpty(item.TDZH))
InspectorUtils.InspectorTextWidthRich($" <b>繁中:</b> {item.TDZH}");
if (!string.IsNullOrEmpty(item.EN))
InspectorUtils.InspectorTextWidthRich($" <b>英语:</b> {item.EN}");
if (!string.IsNullOrEmpty(item.JP))
@ -233,9 +252,10 @@ namespace Logic.Editor
item.ID = id;
if (cells.Length >= 2) item.ZH = RemoveCsvQuotes(cells[1]);
if (cells.Length >= 3) item.EN = RemoveCsvQuotes(cells[2]);
if (cells.Length >= 4) item.JP = RemoveCsvQuotes(cells[3]);
if (cells.Length >= 5) item.KR = RemoveCsvQuotes(cells[4]);
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]);
}
}
@ -308,7 +328,7 @@ namespace Logic.Editor
StringBuilder sb = new StringBuilder();
foreach (var item in _asset.Items)
{
sb.Append($"{item.ID}%$#@!{item.ZH}%$#@!{item.EN}%$#@!{item.JP}%$#@!{item.KR}!@#$%");
sb.Append($"{item.ID}%$#@!{item.ZH}%$#@!{item.TDZH}%$#@!{item.EN}%$#@!{item.JP}%$#@!{item.KR}!@#$%");
}
sw.Write(sb.ToString());
}
@ -386,7 +406,8 @@ namespace Logic.Editor
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
CreateNoWindow = true,
StandardErrorEncoding = Encoding.UTF8
};
using (var process = Process.Start(start))
@ -412,7 +433,8 @@ namespace Logic.Editor
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
CreateNoWindow = true,
StandardErrorEncoding = Encoding.UTF8
};
using (var process = Process.Start(start))

View File

@ -17,6 +17,7 @@ namespace Logic.Multilingual
public enum MultilingualType
{
ZH,
TDZH,
EN,
JP,
KR,
@ -40,6 +41,7 @@ namespace Logic.Multilingual
return type switch
{
MultilingualType.ZH => item.ZH,
MultilingualType.TDZH => item.TDZH,
MultilingualType.EN => item.EN,
MultilingualType.JP => item.JP,
MultilingualType.KR => item.KR,
@ -56,6 +58,7 @@ namespace Logic.Multilingual
return type switch
{
MultilingualType.ZH => group.ZHFont,
MultilingualType.TDZH => group.TDZHFont,
MultilingualType.EN => group.ENFont,
MultilingualType.JP => group.JPFont,
MultilingualType.KR => group.KRFont,
@ -91,6 +94,7 @@ namespace Logic.Multilingual
{
public uint ID;
public string ZH;
public string TDZH;
public string EN;
public string JP;
public string KR;
@ -99,6 +103,7 @@ namespace Logic.Multilingual
public void Refresh()
{
ZH = ZH.Replace("\r\n", "\n");
TDZH = TDZH.Replace("\r\n", "\n");
EN = EN.Replace("\r\n", "\n");
JP = JP.Replace("\r\n", "\n");
KR = KR.Replace("\r\n", "\n");
@ -111,6 +116,7 @@ namespace Logic.Multilingual
{
public uint FontID;
public TMP_FontAsset ZHFont;
public TMP_FontAsset TDZHFont;
public TMP_FontAsset ENFont;
public TMP_FontAsset JPFont;
public TMP_FontAsset KRFont;

View File

@ -1,4 +1,5 @@
import sys
# -*- coding: utf-8 -*-
import sys
import openpyxl
import os
from datetime import datetime
@ -15,7 +16,7 @@ def parse_special_format(content):
continue
# 按字段分割
fields = [f.strip() for f in record.split('%$#@!')]
if len(fields) == 5: # ID,ZH,EN,JP,KR
if len(fields) == 6: # ID,ZH,EN,JP,KR
records.append(fields)
else:
log(f"忽略格式错误的记录: {record}")
@ -35,7 +36,7 @@ def convert_file():
wb = openpyxl.Workbook()
ws = wb.active
ws.append(["ID", "中文", "英文", "日文", "韩文"]) # 添加标题行
ws.append(["ID", "中文", "繁中", "英文", "日文", "韩文"]) # 添加标题行
for row in records:
ws.append(row)

View File

@ -1,4 +1,5 @@
import sys
# -*- coding: utf-8 -*-
import sys
import openpyxl
import os
from datetime import datetime
@ -16,12 +17,12 @@ def convert_excel_to_txt():
ws = wb.active
records = []
for row in ws.iter_rows(min_row=2, values_only=True):
# 确保总是有5个字段,空值转为空字符串
# 确保总是有6个字段,空值转为空字符串
normalized_row = [str(cell).strip() if cell is not None else "" for cell in row]
if len(normalized_row) >= 5: # 只取前5
records.append(normalized_row[:5])
else: # 不足5列则补齐空字符串
records.append(normalized_row + [""]*(5-len(normalized_row)))
if len(normalized_row) >= 6: # 只取前6
records.append(normalized_row[:6])
else: # 不足6列则补齐空字符串
records.append(normalized_row + [""]*(6-len(normalized_row)))
if not records:
log("错误Excel中没有有效数据")
@ -31,7 +32,7 @@ def convert_excel_to_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:
# 确保总是5个字段,空字段也会保留分隔符
# 确保总是6个字段,空字段也会保留分隔符
line = '%$#@!'.join(field for field in record) + '!@#$%'
f.write(line)