加入测试样例,初步完善队列信息——视图转换
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TeamManager : MonoBehaviour
|
||||
{
|
||||
public static TeamManager Instance {get; private set;}
|
||||
|
||||
public teamSettingPanel teamSettingPanelInstance;
|
||||
/// <summary>
|
||||
/// 当前玩家存档下的所有编队配置
|
||||
/// </summary>
|
||||
public Dictionary<int, List<Character>> currentTeamSettings = new Dictionary<int, List<Character>>();
|
||||
/// <summary>
|
||||
/// 玩家存档下已经解锁的角色信息列表
|
||||
/// </summary>
|
||||
public List<Character> SelectableCharacterList = new List<Character>();
|
||||
/// <summary>
|
||||
/// 根据此字段来在编队信息页显示已有编队
|
||||
/// </summary>
|
||||
public int currentSelectedTeam = 0;
|
||||
/// <summary>
|
||||
/// 记录被选中的编队中角色的索引,用于处理队列位置交换的逻辑。-1表示无角色被选中
|
||||
/// </summary>
|
||||
public int currentSelectedCharacter = -1;
|
||||
/// <summary>
|
||||
/// 在修改被选中的编队中角色的索引时触发
|
||||
/// </summary>
|
||||
public event Action OnSelectedCharacterChanged;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void testTeamSetting()
|
||||
{
|
||||
SelectableCharacterList.Add(new Character("YUETAO","default","C","pure dissidents"));
|
||||
SelectableCharacterList.Add(new Character("AYANO","default","B","default skillName"));
|
||||
SelectableCharacterList.Add(new Character("YUETAO","default","C","pure dissidents"));
|
||||
SelectableCharacterList.Add(new Character("AYANO","default","S","default skillName"));
|
||||
|
||||
//手动向currentTeamSettings和SelectableCharacterList添加测试数据
|
||||
currentTeamSettings.Add(0,new List<Character>());
|
||||
currentTeamSettings[0].Add(new Character("YUETAO","default","C","pure dissidents"));
|
||||
currentTeamSettings[0].Add(new Character("AYANO","default","B","default skillName"));
|
||||
currentTeamSettings[0].Add(new Character("YUETAO","default","C","pure dissidents"));
|
||||
currentTeamSettings[0].Add(new Character("YUETAO","default","C","pure dissidents"));
|
||||
|
||||
currentTeamSettings.Add(1,new List<Character>());
|
||||
currentTeamSettings[1].Add(new Character("YUETAO","default","C","pure dissidents"));
|
||||
currentTeamSettings[1].Add(new Character("AYANO","default","B","default skillName"));
|
||||
currentTeamSettings[1].Add(new Character("YUETAO","default","C","pure dissidents"));
|
||||
currentTeamSettings[1].Add(new Character("YUETAO","default","C","pure dissidents"));
|
||||
|
||||
Debug.Log("testTeamSetting ready");
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(teamSettingPanelInstance == null)
|
||||
{
|
||||
teamSettingPanelInstance = teamSettingPanel.Instance;
|
||||
}
|
||||
testTeamSetting();//接入玩家存档后请注释掉此行
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取玩家存档信息后可直接在此写入编队信息
|
||||
/// </summary>
|
||||
/// <param name="playerTeamSettings"></param>
|
||||
public void setcurrentTeamSettings(Dictionary<int,List<Character>> playerTeamSettings)
|
||||
{
|
||||
currentTeamSettings = playerTeamSettings;
|
||||
}
|
||||
/// <summary>
|
||||
/// 依据选定的队伍预设索引来获得队伍信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<Character> getCurrentSelectedTeam()
|
||||
{
|
||||
return currentTeamSettings[currentSelectedTeam];
|
||||
}
|
||||
|
||||
public void setCurrentSelectedTeam(List<Character> newTeamData, int teamIndex)
|
||||
{
|
||||
currentTeamSettings[teamIndex] = newTeamData;
|
||||
}
|
||||
public void setCurrentSelectedCharacterInTeam(int characterIndex)
|
||||
{
|
||||
if (characterIndex != currentSelectedCharacter)
|
||||
{
|
||||
currentSelectedCharacter = characterIndex;
|
||||
OnSelectedCharacterChanged?.Invoke(); // 触发事件
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 交换指定索引中的两个队伍中元素的位置
|
||||
/// </summary>
|
||||
/// <param name="firstIndex"></param>
|
||||
/// <param name="secondIndex"></param>
|
||||
public void swapTeamElements(int firstIndex, int secondIndex)
|
||||
{
|
||||
List<Character> newCurrentTeam = getCurrentSelectedTeam();
|
||||
Character temp = newCurrentTeam[firstIndex];
|
||||
newCurrentTeam[firstIndex] = newCurrentTeam[secondIndex];
|
||||
newCurrentTeam[secondIndex] = temp;
|
||||
currentTeamSettings[currentSelectedTeam] = newCurrentTeam;
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user