加入测试样例,初步完善队列信息——视图转换
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Character
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色名称
|
||||
/// </summary>
|
||||
public string name{get; set;}
|
||||
/// <summary>
|
||||
/// 职业
|
||||
/// </summary>
|
||||
public string occupation{get; set;}
|
||||
/// <summary>
|
||||
/// 突破等级
|
||||
/// </summary>
|
||||
public string boundaryLevel{get; set;}
|
||||
/// <summary>
|
||||
/// 技能名称
|
||||
/// </summary>
|
||||
public string SkillName{get; set;}
|
||||
/// <summary>
|
||||
/// 是否为队长
|
||||
/// </summary>
|
||||
public bool isLeader{get; set;}
|
||||
|
||||
public Character(string name, string occupation, string boundaryLevel, string skillName)
|
||||
{
|
||||
this.name = name;
|
||||
this.occupation = occupation;
|
||||
this.boundaryLevel = boundaryLevel;
|
||||
this.SkillName = skillName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bae42af9bcfec5f46a3025f40ce5bd7b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CharacterCardView : MonoBehaviour
|
||||
{
|
||||
public GameObject charactCard;
|
||||
public Image characterImage;
|
||||
public Image levelIcon;
|
||||
public Image occupationIcon;
|
||||
public string characterName;
|
||||
|
||||
void Start()
|
||||
{
|
||||
charactCard=gameObject;
|
||||
characterImage.sprite = null;
|
||||
levelIcon.sprite = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据角色名称获取角色介绍信息
|
||||
/// </summary>
|
||||
void checkCharacterInformation()
|
||||
{
|
||||
Debug.Log("尝试获取角色介绍:"+characterName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31ac798fff192ba4b92574fbc38f7d35
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: debeba9c3c2f7334ab04c769534a1f85
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
//适用于编队 列表
|
||||
public class teamCharacterView : MonoBehaviour
|
||||
{
|
||||
public GameObject character;
|
||||
public GameObject controlButton;
|
||||
public Image levelIcon;
|
||||
public Image charcterImg;
|
||||
public TMP_Text skillName;
|
||||
|
||||
public GameObject isLeader;
|
||||
public GameObject notLeader;
|
||||
|
||||
public bool isSelected =false;
|
||||
public int listIndex;
|
||||
|
||||
void Start()
|
||||
{
|
||||
character = gameObject;
|
||||
levelIcon.sprite=null;
|
||||
charcterImg.sprite=null;
|
||||
controlButton.SetActive(isSelected);
|
||||
}
|
||||
/// <summary>
|
||||
/// 单机team列表内对象时触发选定
|
||||
/// </summary>
|
||||
public void SetSelected()
|
||||
{
|
||||
isSelected = true;
|
||||
controlButton.SetActive(true);
|
||||
TeamManager.Instance.setCurrentSelectedCharacterInTeam(listIndex);
|
||||
}
|
||||
public void SetUnSelected()
|
||||
{
|
||||
isSelected = false;
|
||||
controlButton.SetActive(false);
|
||||
if(TeamManager.Instance.currentSelectedCharacter==this.listIndex)
|
||||
TeamManager.Instance.setCurrentSelectedCharacterInTeam(-1);
|
||||
}
|
||||
/// <summary>
|
||||
/// 将当前队伍选中角色向下交换位置
|
||||
/// </summary>
|
||||
public void downChangeTeamElementIndex()
|
||||
{
|
||||
if (this.isSelected == false) return;
|
||||
if(this.listIndex == teamSettingPanel.Instance.teamElementsObj.Length-1) return;
|
||||
TeamManager.Instance.swapTeamElements(this.listIndex,this.listIndex+1);
|
||||
}
|
||||
/// <summary>
|
||||
/// 将当前队伍选中角色向上交换位置
|
||||
/// </summary>
|
||||
public void upChangeTeamElementIndex()
|
||||
{
|
||||
if (this.isSelected == false) return;
|
||||
if (this.listIndex == 0) return;
|
||||
TeamManager.Instance.swapTeamElements(this.listIndex, this.listIndex - 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fe33ff09d0ea4848ac88809df94dbc8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,156 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using utils;
|
||||
|
||||
public class teamSettingPanel : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// 编队页面顶父级对象,用于控制显示隐藏等操作
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
public GameObject teamSettingPanelObj;
|
||||
/// <summary>
|
||||
/// ui层编队显示,包含五个组件
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
public GameObject[] teamElementsObj;
|
||||
/// <summary>
|
||||
/// 左侧角色选择页组件
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
public GameObject teamCharacterPrefab;
|
||||
[SerializeField]
|
||||
public GameObject teamCharacterViewContent;
|
||||
|
||||
private TeamManager teamManager;
|
||||
|
||||
|
||||
public static teamSettingPanel Instance{get;private set;}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
teamManager = TeamManager.Instance;
|
||||
if(teamManager!=null)
|
||||
{
|
||||
teamManager.OnSelectedCharacterChanged += updateTeamCharacterSelectedStatus;
|
||||
}
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
if (teamManager != null)
|
||||
{
|
||||
teamManager.OnSelectedCharacterChanged -= updateTeamCharacterSelectedStatus;
|
||||
}
|
||||
}
|
||||
public void openTeamSettingPanel()
|
||||
{
|
||||
updateTeamSettingElements();
|
||||
getSelectableCharacterList();
|
||||
//根据获取的队伍信息处理ui组件
|
||||
//可在此补充ui动画信息
|
||||
teamSettingPanelObj.SetActive(true);
|
||||
}
|
||||
|
||||
public void closeTeamSettingPanel()
|
||||
{
|
||||
teamSettingPanelObj.SetActive(false);
|
||||
Transform transform;
|
||||
for (int i = 0; i < teamCharacterViewContent.transform.childCount; i++)
|
||||
{
|
||||
transform = teamCharacterViewContent.transform.GetChild(i);
|
||||
GameObject.Destroy(transform.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTeamSettingElements()
|
||||
{
|
||||
List<Character> currentTeam = teamManager.getCurrentSelectedTeam();
|
||||
for (int i = 0; i < teamElementsObj.Length && i < currentTeam.Count; i++)
|
||||
{
|
||||
if(teamElementsObj[i]!=null && currentTeam[i]!=null)
|
||||
{
|
||||
teamCharacterView t = teamElementsObj[i].GetComponent<teamCharacterView>();
|
||||
if(t!=null)
|
||||
{
|
||||
Sprite sprite;
|
||||
sprite = FileUtils.getImage($"TeamCharacters/TeamCharacterImg/{currentTeam[i].name}");
|
||||
t.charcterImg.sprite = sprite;
|
||||
sprite = FileUtils.getImage($"TeamCharacters/levelIcon/level{currentTeam[i].boundaryLevel}");
|
||||
t.levelIcon.sprite = sprite;
|
||||
t.isLeader.SetActive(currentTeam[i].isLeader);
|
||||
t.notLeader.SetActive(!currentTeam[i].isLeader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取当前可选入队伍的角色列表,并显示在界面上
|
||||
/// </summary>
|
||||
public void getSelectableCharacterList()
|
||||
{
|
||||
List<Character> selectAbleCharacters = teamManager.SelectableCharacterList;
|
||||
foreach (Character c in selectAbleCharacters)
|
||||
{
|
||||
GameObject characterObj = Instantiate(teamCharacterPrefab, teamCharacterViewContent.transform);
|
||||
CharacterCardView ccv = characterObj.GetComponent<CharacterCardView>();
|
||||
if (ccv != null)
|
||||
{
|
||||
ccv.characterName = c.name;
|
||||
ccv.characterImage.sprite = FileUtils.getImage($"TeamCharacters/CharacterImg/{c.name}");
|
||||
ccv.levelIcon.sprite = FileUtils.getImage($"TeamCharacters/levelIcon/level{c.boundaryLevel}");
|
||||
ccv.occupationIcon.sprite = FileUtils.getImage($"TeamCharacters/OccupationIcon/{c.occupation}");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 将当前角色向下交换位置
|
||||
/// </summary>
|
||||
public void downChangeCharcterIndex()
|
||||
{
|
||||
|
||||
}
|
||||
public void upChangeCharcterIndex()
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 用于保证team内对象的选中状态一致
|
||||
/// </summary>
|
||||
public void updateTeamCharacterSelectedStatus()
|
||||
{
|
||||
int currentSelectedCharacter = teamManager.currentSelectedCharacter;
|
||||
Debug.Log(currentSelectedCharacter+" "+$"{teamElementsObj.Length}");
|
||||
for (int i = 0; i < teamElementsObj.Length; i++)
|
||||
{
|
||||
if (i != currentSelectedCharacter)
|
||||
{
|
||||
teamCharacterView teamCharacterView = teamElementsObj[i].GetComponent<teamCharacterView>();
|
||||
if(teamCharacterView!=null)
|
||||
{
|
||||
teamCharacterView.SetUnSelected();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 若玩家更换了team成员或调整了team成员顺序,则使用此方法更新view
|
||||
/// </summary>
|
||||
public void updateTeamStatus()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc980b2fad60d68478fe827374aaf209
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user