yyl
2025-08-04 464c36a0811d5a2ef317ebf1adc1711baab52856
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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);
    }
}