超大量的更新 修复很多问题,gameplay特效初步
This commit is contained in:
+130
-166
@@ -1,45 +1,27 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
public class TeamManager : MonoBehaviour
|
||||
{
|
||||
public static TeamManager Instance {get; private set;}
|
||||
public static TeamManager Instance { get; private set; }
|
||||
|
||||
public teamSettingPanel teamSettingPanelInstance;
|
||||
/// <summary>
|
||||
/// 当前玩家存档下的所有编队配置,key为编队索引,value为该编队的角色列表,表内只有角色ID
|
||||
/// </summary>
|
||||
|
||||
public Dictionary<int, TeamSetting> currentTeamSettings = new Dictionary<int, TeamSetting>();
|
||||
/// <summary>
|
||||
/// 玩家存档下已经解锁的角色信息列表
|
||||
/// </summary>
|
||||
public List<CharacterView> SelectableCharacterList = new List<CharacterView>();
|
||||
/// <summary>
|
||||
/// 根据此字段来在编队信息页显示已有编队
|
||||
/// </summary>
|
||||
|
||||
public int currentSelectedTeam = 0;
|
||||
/// <summary>
|
||||
/// 记录被选中的编队中角色的索引,用于处理队列位置交换的逻辑。-1表示无角色被选中
|
||||
/// </summary>
|
||||
public int currentSelectedTeamCharacter = -1;
|
||||
/// <summary>
|
||||
/// 标记要被放入编队的角色
|
||||
/// </summary>
|
||||
public int currentSelectedTeamCharacter = -1;
|
||||
public CharacterView currentSelectedCharacterCard = null;
|
||||
/// <summary>
|
||||
/// 在修改被选中的编队中角色的索引时触发
|
||||
/// </summary>
|
||||
|
||||
public event Action OnSelectedCharacterChanged;
|
||||
/// <summary>
|
||||
/// 修改选定的预设队伍时触发
|
||||
/// </summary>
|
||||
public event Action OnSelectedTeamChanged;
|
||||
|
||||
void Awake()
|
||||
|
||||
private const int TeamCount = 4;
|
||||
private const int TeamSlotCount = 5;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
@@ -51,202 +33,184 @@ public class TeamManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
void testTeamSetting()
|
||||
private void Start()
|
||||
{
|
||||
SelectableCharacterList.Add(new CharacterView(1001001,"C"));
|
||||
SelectableCharacterList.Add(new CharacterView(1001002,"S"));
|
||||
|
||||
//手动向currentTeamSettings和SelectableCharacterList添加测试数据
|
||||
currentTeamSettings.Add(0,new TeamSetting(new List<CharacterView>(),1001001));
|
||||
currentTeamSettings[0].teamIdList.Add(new CharacterView(1001001,"C"));
|
||||
currentTeamSettings[0].teamIdList.Add(new CharacterView(1001002,"S"));
|
||||
currentTeamSettings[0].teamIdList.Add(new CharacterView(1001001,"C"));
|
||||
currentTeamSettings[0].teamIdList.Add( new CharacterView(1001002,"C"));
|
||||
currentTeamSettings[0].teamIdList.Add(new CharacterView(0,null));
|
||||
|
||||
currentTeamSettings.Add(1,new TeamSetting(new List<CharacterView>(),1001002));
|
||||
currentTeamSettings[1].teamIdList.Add(new CharacterView(1001001,"C"));
|
||||
currentTeamSettings[1].teamIdList.Add(new CharacterView(1001002,"B"));
|
||||
currentTeamSettings[1].teamIdList.Add(new CharacterView(1001001,"C"));
|
||||
currentTeamSettings[1].teamIdList.Add( new CharacterView(1001002,"A"));
|
||||
currentTeamSettings[1].teamIdList.Add(new CharacterView(1001002,"A"));
|
||||
//在当前版本中,就算是空队伍也要用如下填满,请等待数据结构的重构
|
||||
currentTeamSettings.Add(2,new TeamSetting(new List<CharacterView>(),-1));
|
||||
currentTeamSettings[2].teamIdList.Add(new CharacterView(0,null));
|
||||
currentTeamSettings[2].teamIdList.Add(new CharacterView(0,null));
|
||||
currentTeamSettings[2].teamIdList.Add(new CharacterView(0,null));
|
||||
currentTeamSettings[2].teamIdList.Add( new CharacterView(0,null));
|
||||
currentTeamSettings[2].teamIdList.Add(new CharacterView(0,null));
|
||||
|
||||
currentTeamSettings.Add(3,new TeamSetting(new List<CharacterView>(),-1));
|
||||
currentTeamSettings[3].teamIdList.Add(new CharacterView(0,null));
|
||||
currentTeamSettings[3].teamIdList.Add(new CharacterView(0,null));
|
||||
currentTeamSettings[3].teamIdList.Add(new CharacterView(0,null));
|
||||
currentTeamSettings[3].teamIdList.Add( new CharacterView(0,null));
|
||||
currentTeamSettings[3].teamIdList.Add(new CharacterView(0,null));
|
||||
|
||||
|
||||
Debug.Log("testTeamSetting ready");
|
||||
if (teamSettingPanelInstance == null && teamSettingPanel.Instance != null)
|
||||
teamSettingPanelInstance = teamSettingPanel.Instance;
|
||||
|
||||
EnsureDefaultTeamSettings();
|
||||
}
|
||||
|
||||
private void EnsureDefaultTeamSettings()
|
||||
{
|
||||
for (int i = 0; i < TeamCount; i++)
|
||||
{
|
||||
if (!currentTeamSettings.ContainsKey(i) || currentTeamSettings[i] == null)
|
||||
{
|
||||
currentTeamSettings[i] = CreateEmptyTeamSetting();
|
||||
}
|
||||
|
||||
EnsureTeamSlotCount(currentTeamSettings[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static TeamSetting CreateEmptyTeamSetting()
|
||||
{
|
||||
var list = new List<CharacterView>(TeamSlotCount);
|
||||
for (int i = 0; i < TeamSlotCount; i++)
|
||||
list.Add(new CharacterView(0, null));
|
||||
return new TeamSetting(list, -1);
|
||||
}
|
||||
|
||||
private static void EnsureTeamSlotCount(TeamSetting setting)
|
||||
{
|
||||
if (setting == null) return;
|
||||
if (setting.teamIdList == null)
|
||||
setting.teamIdList = new List<CharacterView>();
|
||||
|
||||
while (setting.teamIdList.Count < TeamSlotCount)
|
||||
setting.teamIdList.Add(new CharacterView(0, null));
|
||||
}
|
||||
|
||||
public void openTeamSettingPanel()
|
||||
{
|
||||
if (teamSettingPanelInstance != null)
|
||||
teamSettingPanelInstance.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void closeTeamSettingPanel()
|
||||
{
|
||||
if (teamSettingPanelInstance != null)
|
||||
teamSettingPanelInstance.gameObject.SetActive(false);
|
||||
}
|
||||
public void openTeamSettingPanel()=> teamSettingPanelInstance.gameObject.SetActive(true);
|
||||
public void closeTeamSettingPanel()=> teamSettingPanelInstance.gameObject.SetActive(false);
|
||||
|
||||
public void setCurrentSelectedTeam(int index)
|
||||
{
|
||||
if (index > 3 || index < 0)
|
||||
if (index < 0 || index >= TeamCount)
|
||||
{
|
||||
Debug.LogWarning("所选队伍预设索引超出范围");
|
||||
Debug.LogWarning($"Selected team index out of range: {index}");
|
||||
return;
|
||||
}
|
||||
currentSelectedTeam = index;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
// if(teamSettingPanelInstance == null)
|
||||
// {
|
||||
// teamSettingPanelInstance = teamSettingPanel.Instance;
|
||||
// }
|
||||
// Ensure we have a reference to the UI panel instance if available
|
||||
if (teamSettingPanelInstance == null && teamSettingPanel.Instance != null)
|
||||
teamSettingPanelInstance = teamSettingPanel.Instance;
|
||||
|
||||
testTeamSetting();//接入玩家存档后请注释掉此行
|
||||
}
|
||||
void saveTeamSetting()
|
||||
public void setcurrentTeamSettings(Dictionary<int, TeamSetting> playerTeamSettings)
|
||||
{
|
||||
//todo:我想,在接存档系统的时候这个会有用。
|
||||
currentTeamSettings = playerTeamSettings ?? new Dictionary<int, TeamSetting>();
|
||||
EnsureDefaultTeamSettings();
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取玩家存档信息后可直接在此写入编队信息
|
||||
/// </summary>
|
||||
/// <param name="playerTeamSettings"></param>
|
||||
public void setcurrentTeamSettings(Dictionary<int,TeamSetting> playerTeamSettings)
|
||||
{
|
||||
currentTeamSettings = playerTeamSettings;
|
||||
}
|
||||
/// <summary>
|
||||
/// 依据选定的队伍预设索引来获得队伍信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
public TeamSetting getCurrentSelectedTeam()
|
||||
{
|
||||
EnsureDefaultTeamSettings();
|
||||
return currentTeamSettings[currentSelectedTeam];
|
||||
}
|
||||
|
||||
public void setCurrentSelectedTeam(TeamSetting newTeamData, int teamIndex)
|
||||
{
|
||||
if (teamIndex < 0 || teamIndex >= TeamCount || newTeamData == null)
|
||||
return;
|
||||
|
||||
EnsureTeamSlotCount(newTeamData);
|
||||
currentTeamSettings[teamIndex] = newTeamData;
|
||||
}
|
||||
|
||||
public void setCurrentSelectedCharacterInTeam(int characterIndex)
|
||||
{
|
||||
if (characterIndex != currentSelectedTeamCharacter)
|
||||
{
|
||||
Debug.Log($"修改选中对象从{currentSelectedTeamCharacter}到{characterIndex}");
|
||||
currentSelectedTeamCharacter = characterIndex;
|
||||
OnSelectedCharacterChanged?.Invoke(); // 触发事件
|
||||
OnSelectedCharacterChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentSelectedTeamSetting(int teamIndex)
|
||||
{
|
||||
if(teamIndex != currentSelectedTeam)
|
||||
if (teamIndex < 0 || teamIndex >= TeamCount)
|
||||
return;
|
||||
|
||||
if (teamIndex != currentSelectedTeam)
|
||||
{
|
||||
Debug.Log($"修改选中队伍预设从{currentSelectedTeam}到{teamIndex}");
|
||||
currentSelectedTeam = teamIndex;
|
||||
OnSelectedTeamChanged?.Invoke(); // 触发事件
|
||||
OnSelectedTeamChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 交换指定索引中的两个队伍中元素的位置
|
||||
/// </summary>
|
||||
/// <param name="firstIndex">当前元素</param>
|
||||
/// <param name="secondIndex">目标元素位置</param>
|
||||
|
||||
public void swapTeamElements(int firstIndex, int secondIndex)
|
||||
{
|
||||
List<CharacterView> newCurrentTeam = getCurrentSelectedTeam().teamIdList;
|
||||
CharacterView temp = newCurrentTeam[firstIndex];
|
||||
newCurrentTeam[firstIndex] = newCurrentTeam[secondIndex];
|
||||
newCurrentTeam[secondIndex] = temp;
|
||||
currentTeamSettings[currentSelectedTeam].teamIdList = newCurrentTeam;
|
||||
teamSettingPanelInstance.updateTeamSettingElements();
|
||||
setCurrentSelectedCharacterInTeam(secondIndex);
|
||||
var team = getCurrentSelectedTeam()?.teamIdList;
|
||||
if (team == null) return;
|
||||
if (firstIndex < 0 || firstIndex >= team.Count) return;
|
||||
if (secondIndex < 0 || secondIndex >= team.Count) return;
|
||||
|
||||
CharacterView temp = team[firstIndex];
|
||||
team[firstIndex] = team[secondIndex];
|
||||
team[secondIndex] = temp;
|
||||
|
||||
currentTeamSettings[currentSelectedTeam].teamIdList = team;
|
||||
if (teamSettingPanelInstance != null)
|
||||
teamSettingPanelInstance.updateTeamSettingElements();
|
||||
|
||||
setCurrentSelectedCharacterInTeam(secondIndex);
|
||||
}
|
||||
|
||||
public void setTeamLeader(int characterID)
|
||||
{
|
||||
Debug.Log($"{characterID},{SelectableCharacterList.Count}");
|
||||
currentTeamSettings[currentSelectedTeam].LeaderId=characterID;
|
||||
teamSettingPanelInstance.updateTeamSettingElements();
|
||||
}
|
||||
/// <summary>
|
||||
/// 填入或者覆盖队伍指定位置的信息
|
||||
/// </summary>
|
||||
/// <param name="aimListIndex"></param>
|
||||
public void ResetTeamCharacter (int aimListIndex)
|
||||
{
|
||||
//如果在队伍中已有角色的情况下再次触发此方法,首先要去掉旧信息,再放新信息
|
||||
CharacterView newCharacter = currentSelectedCharacterCard;
|
||||
List<CharacterView> newCurrentTeam = getCurrentSelectedTeam().teamIdList;
|
||||
var team = getCurrentSelectedTeam();
|
||||
if (team == null) return;
|
||||
|
||||
// 修复:原代码使用 (aimListIndex > 0 || aimListIndex < Count) 永远几乎为真,
|
||||
// 会导致当 aimListIndex = 0 或越界时也进入逻辑,造成数据错乱。
|
||||
if (aimListIndex >= 0 && aimListIndex < newCurrentTeam.Count)
|
||||
{
|
||||
for(int i=0;i<newCurrentTeam.Count;i++)
|
||||
{
|
||||
if (newCurrentTeam[i].characterId == newCharacter.characterId && aimListIndex != i)//满足此条件为更换角色的队伍位置
|
||||
{
|
||||
//说明是在更换角色所在的位置下标,旧角色,位置置空
|
||||
newCurrentTeam[aimListIndex] = newCharacter;
|
||||
CharacterView characterView = new CharacterView(0, null);
|
||||
newCurrentTeam[i] = characterView;
|
||||
currentTeamSettings[currentSelectedTeam].teamIdList = newCurrentTeam;
|
||||
teamSettingPanelInstance.updateTeamSettingElements();
|
||||
return;
|
||||
}
|
||||
else if (newCurrentTeam[i].characterId == newCharacter.characterId && aimListIndex == i)
|
||||
{
|
||||
//原地点击操作,不做任何操作
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
newCurrentTeam[aimListIndex] = newCharacter;
|
||||
currentTeamSettings[currentSelectedTeam].teamIdList = newCurrentTeam;
|
||||
team.LeaderId = characterID;
|
||||
if (teamSettingPanelInstance != null)
|
||||
teamSettingPanelInstance.updateTeamSettingElements();
|
||||
}
|
||||
|
||||
public void ResetTeamCharacter(int aimListIndex)
|
||||
{
|
||||
var selected = currentSelectedCharacterCard;
|
||||
var team = getCurrentSelectedTeam()?.teamIdList;
|
||||
if (selected == null || team == null)
|
||||
return;
|
||||
if (aimListIndex < 0 || aimListIndex >= team.Count)
|
||||
{
|
||||
Debug.LogWarning($"ResetTeamCharacter index out of range: {aimListIndex}");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.LogWarning($"TeamManager.ResetTeamCharacter: aimListIndex out of range: {aimListIndex} (Count={newCurrentTeam.Count})");
|
||||
for (int i = 0; i < team.Count; i++)
|
||||
{
|
||||
if (i == aimListIndex) continue;
|
||||
if (team[i] != null && team[i].characterId == selected.characterId)
|
||||
{
|
||||
team[i] = new CharacterView(0, null);
|
||||
}
|
||||
}
|
||||
|
||||
team[aimListIndex] = selected;
|
||||
currentTeamSettings[currentSelectedTeam].teamIdList = team;
|
||||
|
||||
if (teamSettingPanelInstance != null)
|
||||
teamSettingPanelInstance.updateTeamSettingElements();
|
||||
}
|
||||
/// <summary>
|
||||
/// 移除队伍中的指定角色
|
||||
/// </summary>
|
||||
/// <param name="characterID"></param>
|
||||
|
||||
public void removeTeamCharacter(int characterId)
|
||||
{
|
||||
currentSelectedCharacterCard = null;
|
||||
List<CharacterView> newCurrentTeam = getCurrentSelectedTeam().teamIdList;
|
||||
foreach (CharacterView character in newCurrentTeam)
|
||||
var team = getCurrentSelectedTeam()?.teamIdList;
|
||||
if (team == null) return;
|
||||
|
||||
for (int i = 0; i < team.Count; i++)
|
||||
{
|
||||
if (character.characterId == characterId)
|
||||
if (team[i] != null && team[i].characterId == characterId)
|
||||
{
|
||||
character.characterId = 0;
|
||||
character.currentBoundaryLevel = null;
|
||||
team[i].characterId = 0;
|
||||
team[i].currentBoundaryLevel = null;
|
||||
}
|
||||
}
|
||||
currentTeamSettings[currentSelectedTeam].teamIdList = newCurrentTeam;
|
||||
// attempt to update UI panel safely
|
||||
|
||||
currentTeamSettings[currentSelectedTeam].teamIdList = team;
|
||||
|
||||
var panel = teamSettingPanelInstance ?? teamSettingPanel.Instance;
|
||||
if (panel != null)
|
||||
{
|
||||
panel.updateTeamSettingElements();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("TeamManager.removeTeamCharacter: teamSettingPanel instance missing, UI not updated.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user