using System;
|
using System.Linq;
|
using Cysharp.Threading.Tasks;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using System.Collections.Generic;
|
|
//布阵中的 武将角色
|
public class HeroScenePosCell : MonoBehaviour
|
{
|
[SerializeField] Button heroBtn;
|
[SerializeField] Text jobTip;
|
[SerializeField] Text posTip;
|
[SerializeField] Image countryImg;
|
[SerializeField] Text nameText;
|
[SerializeField] Text lvText;
|
[SerializeField] UIHeroController heroModel;
|
[SerializeField] Image posCircleImg;
|
[SerializeField] UIAlphaTween suggestForm;
|
[SerializeField] DragItem dragObj;
|
[SerializeField] Transform objForfly; //点击飞入的时候的显隐控制
|
|
|
public void Display(string guid, int index, bool isFly = false)
|
{
|
var hero = HeroManager.Instance.GetHero(guid);
|
this.transform.localScale = Vector3.one;
|
|
lvText.text = Language.Get("L1099", hero.heroLevel);
|
var heroConfig = hero.heroConfig;
|
countryImg.SetSprite("herocountry" + heroConfig.Country);
|
heroModel.Create(heroConfig.SkinIDList[hero.SkinIndex]);
|
|
nameText.text = hero.breakLevel == 0 ? heroConfig.Name : Language.Get("herocardbreaklv", heroConfig.Name, hero.breakLevel);
|
posCircleImg.SetSprite("heroposcircle" + heroConfig.Quality);
|
|
//不是推荐位则提示
|
if (heroConfig.AtkDistType == 1 && TeamConst.TeamPos2Array.Contains(index) ||
|
heroConfig.AtkDistType == 2 && TeamConst.TeamPos1Array.Contains(index))
|
{
|
suggestForm.SetActive(true);
|
jobTip.text = RichTextMsgReplaceConfig.GetRichReplace("Class", heroConfig.Class);
|
posTip.text = Language.Get("heroAtkDistType" + heroConfig.AtkDistType);
|
}
|
else
|
{
|
suggestForm.SetActive(false);
|
}
|
|
dragObj.pos = index;
|
dragObj.onEndDragEvent -= SwitchPos;
|
dragObj.onEndDragEvent += SwitchPos;
|
dragObj.canvas.sortingLayerID = dragObj.parentCanvas.sortingLayerID;
|
dragObj.canvas.sortingOrder = dragObj.parentCanvas.sortingOrder + index + 1;
|
|
heroBtn.AddListener(() =>
|
{
|
var team = TeamManager.Instance.GetTeam(HeroUIManager.Instance.selectTeamType);
|
team.RemoveHero(index);
|
//通知刷新(下阵)
|
HeroUIManager.Instance.NotifyOnTeamPosChangeEvent(new List<int>() { index }, -1, Vector3.zero);
|
|
});
|
|
if (isFly)
|
{
|
//点击飞入 延迟显示
|
objForfly.SetActive(false);
|
DelayShow();
|
}
|
else
|
{
|
objForfly.SetActive(true);
|
}
|
}
|
|
void SwitchPos(int pos1, int pos2)
|
{
|
Debug.Log("交换位置:" + pos1 + " " + pos2);
|
var team = TeamManager.Instance.GetTeam(HeroUIManager.Instance.selectTeamType);
|
if (pos2 == -1)
|
{
|
//下阵
|
team.RemoveHero(pos1);
|
HeroUIManager.Instance.NotifyOnTeamPosChangeEvent(new List<int>() { pos1 }, -1, Vector3.zero);
|
}
|
else if (pos1 == pos2)
|
{
|
HeroUIManager.Instance.NotifyOnTeamPosChangeEvent(new List<int>() { pos1 }, -1, Vector3.zero);
|
}
|
else
|
{
|
//通知刷新
|
team.SwapPosition(pos1, pos2);
|
HeroUIManager.Instance.NotifyOnTeamPosChangeEvent(new List<int>() { pos1, pos2 }, -1, Vector3.zero);
|
}
|
}
|
|
async UniTask DelayShow()
|
{
|
//延迟0.5秒显示
|
await UniTask.Delay(TimeSpan.FromSeconds(HeroUIManager.clickFlyPosTime));
|
objForfly.SetActive(true);
|
}
|
}
|