fix(android): 安卓兼容

This commit is contained in:
2026-07-01 19:48:33 +08:00
parent 107a2411e3
commit 73e6b86579
5 changed files with 86 additions and 66 deletions
+19 -33
View File
@@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using AibisDream.Kit;
using AibisDream.SaveSystem;
using AibisDream.Utility;
using UnityEngine;
@@ -19,9 +20,9 @@ namespace AibisDream
{
// 获取存档并提取章节信息
var cacheChapter = string.Empty;
if (ChapterData.TryGetSaveFilePath(out var saveFilePath))
if (ChapterData.TryGetLatestSaveSceneSoName(out var sceneSoName))
{
cacheChapter = ParseChapterTitle(saveFilePath);
cacheChapter = sceneSoName;
}
var sourceList = GameManager.Instance.GetAllSceneSos();
@@ -43,23 +44,6 @@ namespace AibisDream
return chapterList;
}
private static string ParseChapterTitle(string filePath)
{
var fileName = Path.GetFileNameWithoutExtension(filePath);
var parts = fileName.Split('_');
// 文件名格式: yyyyMMdd-HHmmss_{sceneSoName}_{gameStage}
// sceneSoName 可能包含下划线,但时间戳(第0段)和游戏阶段(最后1段)不会
if (parts.Length < 3)
{
Debug.LogWarning($"存档文件名格式异常: {fileName}");
return string.Empty;
}
var sceneSoName = string.Join("_", parts, 1, parts.Length - 2);
Debug.Log($"ParseChapterTitle: 从 {fileName} 解析出章节名 = {sceneSoName}");
return sceneSoName;
}
public void StartWithChapter(ChapterVo chapterVo)
{
GameManager.Instance.StartWithLevel(chapterVo.chapterSo);
@@ -67,15 +51,14 @@ namespace AibisDream
public void StartWithSaveFile()
{
// 获取当前存档
if (!ChapterData.TryGetSaveFilePath(out var saveFilePath))
var slotIndex = SlotManager.GetLatestSlotIndex() ?? SlotIndex.Auto;
if (!SlotDirectory.Exists(slotIndex))
{
Debug.LogError("未找到存档");
return;
}
else
{
GameManager.Instance.StartWithSaveFile(saveFilePath);
}
GameManager.Instance.StartWithSlot(slotIndex);
}
public void UnlockChapter(TalkSceneSO chapterSo)
@@ -116,19 +99,22 @@ namespace AibisDream
JsonUtil.SaveArray(unlockedChapterList.ToArray(), ConstRef.ChapterProgressPath);
}
public bool TryGetSaveFilePath(out string saveFilePath)
public bool TryGetLatestSaveSceneSoName(out string sceneSoName)
{
var files = Directory.GetFiles(ConstRef.SaveFilePath, "*.json")
.OrderByDescending(fileName => fileName)
.ToArray();
if (files.Length <= 0)
sceneSoName = string.Empty;
var slotIndex = SlotManager.GetLatestSlotIndex() ?? SlotIndex.Auto;
if (!SlotDirectory.Exists(slotIndex))
{
saveFilePath = string.Empty;
return false;
}
saveFilePath = files[0];
var meta = SlotManager.LoadMeta(slotIndex);
if (meta == null || string.IsNullOrEmpty(meta.sceneSoName))
{
return false;
}
sceneSoName = meta.sceneSoName;
return true;
}
}