设置scriptable存储角色信息,调整编队系统部分代码逻辑
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,11 @@ using UnityEngine.UI;
|
||||
|
||||
public class CharacterCardView : MonoBehaviour
|
||||
{
|
||||
public int characterID;
|
||||
public GameObject charactCard;
|
||||
public Image characterImage;
|
||||
public Image levelIcon;
|
||||
public Image occupationIcon;
|
||||
public string characterName;
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -17,11 +17,6 @@ public class CharacterCardView : MonoBehaviour
|
||||
characterImage.sprite = null;
|
||||
levelIcon.sprite = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据角色名称获取角色介绍信息
|
||||
/// </summary>
|
||||
void checkCharacterInformation()
|
||||
{
|
||||
Debug.Log("尝试获取角色介绍:"+characterName);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class TeamManager : MonoBehaviour
|
||||
@@ -9,13 +10,13 @@ public class TeamManager : MonoBehaviour
|
||||
|
||||
public teamSettingPanel teamSettingPanelInstance;
|
||||
/// <summary>
|
||||
/// 当前玩家存档下的所有编队配置
|
||||
/// 当前玩家存档下的所有编队配置,key为编队索引,value为该编队的角色列表,表内只有角色ID
|
||||
/// </summary>
|
||||
public Dictionary<int, List<Character>> currentTeamSettings = new Dictionary<int, List<Character>>();
|
||||
public Dictionary<int, TeamSetting> currentTeamSettings = new Dictionary<int, TeamSetting>();
|
||||
/// <summary>
|
||||
/// 玩家存档下已经解锁的角色信息列表
|
||||
/// </summary>
|
||||
public List<Character> SelectableCharacterList = new List<Character>();
|
||||
public List<CharacterView> SelectableCharacterList = new List<CharacterView>();
|
||||
/// <summary>
|
||||
/// 根据此字段来在编队信息页显示已有编队
|
||||
/// </summary>
|
||||
@@ -43,40 +44,44 @@ public class TeamManager : MonoBehaviour
|
||||
|
||||
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"));
|
||||
SelectableCharacterList.Add(new CharacterView(1001001,"C"));
|
||||
SelectableCharacterList.Add(new CharacterView(1001002,"S"));
|
||||
SelectableCharacterList.Add(new CharacterView(1001001,"C"));
|
||||
SelectableCharacterList.Add(new CharacterView(1001002,"C"));
|
||||
|
||||
//手动向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(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.Add(1,new TeamSetting(new List<CharacterView>(),1001002));
|
||||
currentTeamSettings[0].teamIdList.Add(new CharacterView(1001001,"C"));
|
||||
currentTeamSettings[0].teamIdList.Add(new CharacterView(1001002,"B"));
|
||||
currentTeamSettings[0].teamIdList.Add(new CharacterView(1001001,"C"));
|
||||
currentTeamSettings[0].teamIdList.Add( new CharacterView(1001002,"A"));
|
||||
currentTeamSettings[0].teamIdList.Add(new CharacterView(1001002,"A"));
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
public void openTeamSettingPanel()=> teamSettingPanelInstance.gameObject.SetActive(true);
|
||||
public void closeTeamSettingPanel()=> teamSettingPanelInstance.gameObject.SetActive(false);
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(teamSettingPanelInstance == null)
|
||||
{
|
||||
teamSettingPanelInstance = teamSettingPanel.Instance;
|
||||
}
|
||||
// if(teamSettingPanelInstance == null)
|
||||
// {
|
||||
// teamSettingPanelInstance = teamSettingPanel.Instance;
|
||||
// }
|
||||
testTeamSetting();//接入玩家存档后请注释掉此行
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取玩家存档信息后可直接在此写入编队信息
|
||||
/// </summary>
|
||||
/// <param name="playerTeamSettings"></param>
|
||||
public void setcurrentTeamSettings(Dictionary<int,List<Character>> playerTeamSettings)
|
||||
public void setcurrentTeamSettings(Dictionary<int,TeamSetting> playerTeamSettings)
|
||||
{
|
||||
currentTeamSettings = playerTeamSettings;
|
||||
}
|
||||
@@ -84,12 +89,12 @@ public class TeamManager : MonoBehaviour
|
||||
/// 依据选定的队伍预设索引来获得队伍信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<Character> getCurrentSelectedTeam()
|
||||
public TeamSetting getCurrentSelectedTeam()
|
||||
{
|
||||
return currentTeamSettings[currentSelectedTeam];
|
||||
}
|
||||
|
||||
public void setCurrentSelectedTeam(List<Character> newTeamData, int teamIndex)
|
||||
public void setCurrentSelectedTeam(TeamSetting newTeamData, int teamIndex)
|
||||
{
|
||||
currentTeamSettings[teamIndex] = newTeamData;
|
||||
}
|
||||
@@ -108,11 +113,11 @@ public class TeamManager : MonoBehaviour
|
||||
/// <param name="secondIndex"></param>
|
||||
public void swapTeamElements(int firstIndex, int secondIndex)
|
||||
{
|
||||
List<Character> newCurrentTeam = getCurrentSelectedTeam();
|
||||
Character temp = newCurrentTeam[firstIndex];
|
||||
List<CharacterView> newCurrentTeam = getCurrentSelectedTeam().teamIdList;
|
||||
CharacterView temp = newCurrentTeam[firstIndex];
|
||||
newCurrentTeam[firstIndex] = newCurrentTeam[secondIndex];
|
||||
newCurrentTeam[secondIndex] = temp;
|
||||
currentTeamSettings[currentSelectedTeam] = newCurrentTeam;
|
||||
currentTeamSettings[currentSelectedTeam].teamIdList = newCurrentTeam;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
/// <summary>
|
||||
/// 适用于编队系统数据层,存储单个队伍的信息
|
||||
/// </summary>
|
||||
public class TeamSetting
|
||||
{
|
||||
public TeamSetting(List<CharacterView> teamList, int leaderId)
|
||||
{
|
||||
this.teamIdList = teamIdList;
|
||||
LeaderId = leaderId;
|
||||
}
|
||||
|
||||
|
||||
public List<CharacterView> teamIdList = new List<CharacterView>();
|
||||
|
||||
/// <summary>
|
||||
/// 队长
|
||||
/// </summary>
|
||||
public int LeaderId{get; set;}
|
||||
|
||||
}
|
||||
|
||||
public class CharacterView
|
||||
{
|
||||
public CharacterView(int characterId, string currentBoundaryLevel)
|
||||
{
|
||||
this.characterId = characterId;
|
||||
this.currentBoundaryLevel = currentBoundaryLevel;
|
||||
}
|
||||
|
||||
public int characterId{get; set;}
|
||||
public string currentBoundaryLevel{get; set;}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using UnityEngine.UI;
|
||||
//适用于编队 列表
|
||||
public class teamCharacterView : MonoBehaviour
|
||||
{
|
||||
public int characterID;
|
||||
public GameObject character;
|
||||
public GameObject controlButton;
|
||||
public Image levelIcon;
|
||||
@@ -24,7 +25,9 @@ public class teamCharacterView : MonoBehaviour
|
||||
{
|
||||
character = gameObject;
|
||||
levelIcon.sprite=null;
|
||||
levelIcon.color = new Color(levelIcon.color.r, levelIcon.color.g, levelIcon.color.b, 0);
|
||||
charcterImg.sprite=null;
|
||||
charcterImg.color = new Color(charcterImg.color.r, charcterImg.color.g, charcterImg.color.b, 0);
|
||||
controlButton.SetActive(isSelected);
|
||||
}
|
||||
/// <summary>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using utils;
|
||||
using Transform = UnityEngine.Transform;
|
||||
|
||||
public class teamSettingPanel : MonoBehaviour
|
||||
{
|
||||
@@ -16,6 +18,16 @@ public class teamSettingPanel : MonoBehaviour
|
||||
[SerializeField]
|
||||
public GameObject[] teamElementsObj;
|
||||
/// <summary>
|
||||
/// team用角色数据库总表
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
public TeamCharacterList teamCharacterList;
|
||||
/// <summary>
|
||||
/// 等级贴图表
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
public TeamCharacterLevelData teamCharacterLevelData;
|
||||
/// <summary>
|
||||
/// 左侧角色选择页组件
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
@@ -47,6 +59,9 @@ public class teamSettingPanel : MonoBehaviour
|
||||
{
|
||||
teamManager.OnSelectedCharacterChanged += updateTeamCharacterSelectedStatus;
|
||||
}
|
||||
StartCoroutine(UpdateTeamSettingAfterOneFrame());
|
||||
// updateTeamSettingElements();
|
||||
StartCoroutine(UpdateSelectableCharacterAfterOneFrame());
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
@@ -57,27 +72,102 @@ public class teamSettingPanel : MonoBehaviour
|
||||
}
|
||||
public void openTeamSettingPanel()
|
||||
{
|
||||
updateTeamSettingElements();
|
||||
getSelectableCharacterList();
|
||||
//根据获取的队伍信息处理ui组件
|
||||
//可在此补充ui动画信息
|
||||
StartCoroutine(UpdateTeamSettingAfterOneFrame());
|
||||
// updateTeamSettingElements();
|
||||
StartCoroutine(UpdateSelectableCharacterAfterOneFrame());
|
||||
teamSettingPanelObj.SetActive(true);
|
||||
// getSelectableCharacterList();
|
||||
}
|
||||
private IEnumerator UpdateTeamSettingAfterOneFrame()
|
||||
{
|
||||
yield return null;
|
||||
|
||||
updateTeamSettingElements();
|
||||
foreach (var obj in teamElementsObj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
var t = obj.GetComponent<teamCharacterView>();
|
||||
if (t != null && t.charcterImg != null)
|
||||
{
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(t.charcterImg.rectTransform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private IEnumerator UpdateSelectableCharacterAfterOneFrame()
|
||||
{
|
||||
yield return null;
|
||||
|
||||
updateSelectableCharacterViewList();
|
||||
//获取content下的所有子对象,并重新布局
|
||||
// foreach (Transform child in teamCharacterViewContent.transform)
|
||||
// {
|
||||
// if (child != null)
|
||||
// {
|
||||
// var t = child.GetComponent<CharacterCardView>();
|
||||
// if (t != null && t.characterImage != null)
|
||||
// {
|
||||
// LayoutRebuilder.ForceRebuildLayoutImmediate(t.characterImage.rectTransform);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
RectTransform rt = teamCharacterViewContent.GetComponent<RectTransform>();
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(rt);
|
||||
}
|
||||
|
||||
public void closeTeamSettingPanel()
|
||||
{
|
||||
teamSettingPanelObj.SetActive(false);
|
||||
Transform transform;
|
||||
for (int i = 0; i < teamCharacterViewContent.transform.childCount; i++)
|
||||
}
|
||||
public TeamCharacterDataInfo getCharacterViewInfo(int characterID)
|
||||
{
|
||||
if (teamCharacterList == null)
|
||||
{
|
||||
transform = teamCharacterViewContent.transform.GetChild(i);
|
||||
GameObject.Destroy(transform.gameObject);
|
||||
Debug.LogError("teamCharacterList 缺失");
|
||||
return null;
|
||||
}
|
||||
foreach (TeamCharacterDataInfo tcdi in teamCharacterList.characters)
|
||||
{
|
||||
if(tcdi.CharacterID==characterID)
|
||||
{
|
||||
return tcdi;
|
||||
}
|
||||
}
|
||||
Debug.LogWarning($"未找到{characterID}对应的角色信息");;
|
||||
return null;
|
||||
}
|
||||
|
||||
public Sprite getLevelSprite(string level)
|
||||
{
|
||||
if(level==null)
|
||||
{
|
||||
Debug.LogWarning("level为空,无法获取对应等级贴图");
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (level)
|
||||
{
|
||||
case "S":
|
||||
return teamCharacterLevelData.LevelSSprite;
|
||||
case "A":
|
||||
return teamCharacterLevelData.LevelASprite;
|
||||
case "B":
|
||||
return teamCharacterLevelData.LevelBSprite;
|
||||
case "C":
|
||||
return teamCharacterLevelData.LevelCSprite;
|
||||
default:
|
||||
Debug.LogWarning($"未找到对应等级贴图,当前等级为:{level}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTeamSettingElements()
|
||||
{
|
||||
List<Character> currentTeam = teamManager.getCurrentSelectedTeam();
|
||||
TeamSetting currentSelectedTeam = teamManager.getCurrentSelectedTeam();
|
||||
List<CharacterView> currentTeam = currentSelectedTeam.teamIdList;
|
||||
for (int i = 0; i < teamElementsObj.Length && i < currentTeam.Count; i++)
|
||||
{
|
||||
if(teamElementsObj[i]!=null && currentTeam[i]!=null)
|
||||
@@ -85,13 +175,20 @@ public class teamSettingPanel : MonoBehaviour
|
||||
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);
|
||||
t.characterID= currentTeam[i].characterId;
|
||||
TeamCharacterDataInfo tcdi = getCharacterViewInfo(t.characterID);
|
||||
|
||||
t.charcterImg.sprite = tcdi.CharacterTeamSprite;
|
||||
t.charcterImg.color=new Color(t.charcterImg.color.r,t.charcterImg.color.g,t.charcterImg.color.b,255f);
|
||||
|
||||
t.levelIcon.sprite = getLevelSprite(currentTeam[i].currentBoundaryLevel);
|
||||
t.levelIcon.color=new Color(t.levelIcon.color.r,t.levelIcon.color.g,t.levelIcon.color.b,255f);
|
||||
if(currentSelectedTeam.LeaderId==currentTeam[i].characterId)
|
||||
{
|
||||
t.isLeader.SetActive(true);
|
||||
t.notLeader.SetActive(false);
|
||||
}
|
||||
t.skillName.text = tcdi.CharacterSkillName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,19 +196,25 @@ public class teamSettingPanel : MonoBehaviour
|
||||
/// <summary>
|
||||
/// 获取当前可选入队伍的角色列表,并显示在界面上
|
||||
/// </summary>
|
||||
public void getSelectableCharacterList()
|
||||
public void updateSelectableCharacterViewList()
|
||||
{
|
||||
List<Character> selectAbleCharacters = teamManager.SelectableCharacterList;
|
||||
foreach (Character c in selectAbleCharacters)
|
||||
foreach (Transform child in teamCharacterViewContent.transform)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
List<CharacterView> selectAbleCharacters = teamManager.SelectableCharacterList;
|
||||
foreach (CharacterView c in selectAbleCharacters) //id and level
|
||||
{
|
||||
GameObject characterObj = Instantiate(teamCharacterPrefab, teamCharacterViewContent.transform);
|
||||
CharacterCardView ccv = characterObj.GetComponent<CharacterCardView>();
|
||||
if (ccv != null)
|
||||
TeamCharacterDataInfo tcdi = getCharacterViewInfo(c.characterId);
|
||||
if (ccv != null&& tcdi!=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}");
|
||||
ccv.characterID = tcdi.CharacterID;
|
||||
ccv.characterImage.sprite =tcdi.CharacterCardSprite;
|
||||
ccv.levelIcon.sprite = getLevelSprite(c.currentBoundaryLevel);
|
||||
ccv.occupationIcon.sprite = tcdi.CharacterRoleSprite;
|
||||
Debug.Log($"{ccv.characterID}--{ccv.characterImage.sprite.name}--{ccv.levelIcon.sprite.name}--{ccv.gameObject.name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user