```
feat(player): 添加玩家阵型保存功能 新增savedFormation字段用于存储玩家的阵型配置, 包括角色ID列表和对应的格子索引位置信息。 ```
This commit is contained in:
1 parent
e127da5416
commit
1abd0de32f
16 files changed
+432
-2930
No files matched your search
@@ -310,17 +310,67 @@ public class FormationManager : MonoBehaviour
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ===== 进入战斗 =====
|
||||
// ===== 保存阵型 =====
|
||||
|
||||
public void StartBattle()
|
||||
{
|
||||
FillUnplacedWithDefault();
|
||||
SaveFormation();
|
||||
SaveFormationToJson();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(battleSceneName))
|
||||
private void SaveFormationToJson()
|
||||
{
|
||||
int count = HeroCount;
|
||||
var characterIds = new string[count];
|
||||
var cells = new int[count];
|
||||
|
||||
// 初始化数组
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
SceneManager.LoadScene(battleSceneName);
|
||||
HeroEntry entry = GetHero(i);
|
||||
characterIds[i] = entry != null ? GetCharacterId(entry.prefab) : "";
|
||||
cells[i] = -1;
|
||||
}
|
||||
|
||||
// 填充已放置的格位
|
||||
foreach (var pair in placed)
|
||||
{
|
||||
int heroIndex = pair.Value.heroIndex;
|
||||
if (heroIndex >= 0 && heroIndex < count)
|
||||
{
|
||||
cells[heroIndex] = pair.Key;
|
||||
}
|
||||
}
|
||||
|
||||
// 保存到 PlayerData.json
|
||||
if (PlayerDataManager.Instance != null)
|
||||
{
|
||||
PlayerDataManager.Instance.SaveFormation(characterIds, cells);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("PlayerDataManager.Instance 未找到,无法保存阵型");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 Prefab 获取 characterId
|
||||
/// </summary>
|
||||
private string GetCharacterId(GameObject prefab)
|
||||
{
|
||||
if (prefab == null) return "";
|
||||
|
||||
// 查找对应的 CharacterData
|
||||
var allData = Resources.LoadAll<CharacterData>("Data");
|
||||
foreach (var data in allData)
|
||||
{
|
||||
if (data.unitPrefab == prefab)
|
||||
{
|
||||
return data.characterId;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private void SaveFormation()
|
||||
|
||||
Reference in new issue
Block a user