lcy
6 天以前 fa401262d2ca2891aa9c88b9667f66aa1175736c
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
 
public class TimeRushTaskCell : MonoBehaviour
{
    [SerializeField] ButtonEx clickButton;
    [SerializeField] TextEx titleText;
    [SerializeField] ImageEx sliderImage;
    [SerializeField] ImageEx maskImage;
    [SerializeField] TextEx sliderText;
    [SerializeField] ItemCell[] itemCells;
    [SerializeField] ImageEx[] grays;
 
    [SerializeField] RectTransform[] tweenTargets;
    
    [SerializeField, Tooltip("单边摆动的基础耗时(秒)")] 
    float timeMultiplier = 0.5f;
    
    [SerializeField, Tooltip("一轮摆动结束后的停顿秒数")] 
    float pauseDuration = 0.2f; 
    
    [SerializeField, Tooltip("左右摇摆的最大旋转角度")] 
    float shakeAngle = 15f; 
 
    [SerializeField] UIEffectPlayer uiEffectPlayer;
 
    int awardIndex;
    int roundType;
    int tabType;
    TimeRushManager manager { get { return TimeRushManager.Instance; } }
 
    public void Display(int index, CellView cell, List<HAA88_tagMCActLunhuidianInfo.tagMCActLunhuidianAward> taskList)
    {
        roundType = cell.info.Value.infoInt1;
        tabType = cell.info.Value.infoInt2;
        if (taskList.IsNullOrEmpty() || index < 0 || index >= taskList.Count)
            return;
 
        var task = taskList[index];
        awardIndex = task.AwardIndex;
 
        if (!manager.TryGetOperationInfo(out var act))
            return;
        if (!act.TryGetRound(roundType, out var round))
            return;
        if (!manager.TryGetPlayerInfo(roundType, out var playerInfo))
            return;
        RefreshAnimations();
 
        int state = manager.GetAwardState(roundType, awardIndex);
        maskImage.SetActive(state == 2);
        uiEffectPlayer.SetActive(state == 1);
        titleText.text = Language.Get($"TimeRushTaskTitle_{round.AwardType}_{round.AwardTypeValue}", task.NeedValue);
        sliderImage.fillAmount = playerInfo.CurValue / (float)task.NeedValue;
        sliderText.text = Language.Get("BoneField09", playerInfo.CurValue, task.NeedValue);
 
        for (int i = 0; i < itemCells.Length; i++)
        {
            var itemBaisc = itemCells[i];
            if (i < task.AwardItemList.Length)
            {
                var itemInfo = task.AwardItemList[i];
                itemBaisc.SetActive(true);
                grays[i].SetActive(state == 2);
                ItemCellModel cellModel = new ItemCellModel((int)itemInfo.ItemID, false, itemInfo.ItemCount);
                itemBaisc.Init(cellModel);
                itemBaisc.button.AddListener(() =>
                {
                    if (state == 1)
                    {
                        manager.HaveAllMissionAward(roundType);
                    }
                    else
                    {
                        ItemTipUtility.Show((int)itemInfo.ItemID);
                    }
                });
            }
            else
            {
                itemBaisc.SetActive(false);
                grays[i].SetActive(false);
            }
        }
 
        clickButton.SetListener(() =>
        {
            if (state == 1)
            {
                manager.HaveAllMissionAward(roundType);
            }
        });
    }
 
    private void OnEnable()
    {
        manager.PlayAnimationSync += OnPlaySyncAnimation;
        RefreshAnimations();
    }
 
    private void OnDisable()
    {
        manager.PlayAnimationSync -= OnPlaySyncAnimation;
        StopAllTweens();
    }
 
    private void OnPlaySyncAnimation()
    {
        if (tabType != 1) return;
        RefreshAnimations();
    }
 
    // 统一处理动画的刷新和启动
    private void RefreshAnimations()
    {
        StopAllTweens();
 
        if (!manager.TryGetOperationInfo(out var act)) return;
        if (!act.TryGetRoundInfoByIndex(roundType, awardIndex, out var awardInfo, out int listIndex) || awardInfo.AwardItemList == null) return;
 
        int state = manager.GetAwardState(roundType, awardIndex);
 
        for (int i = 0; i < tweenTargets.Length; i++)
        {
            if (i < awardInfo.AwardItemList.Length && tweenTargets[i].gameObject.activeInHierarchy && state == 1)
            {
                PlayShakeAnimation(tweenTargets[i]);
            }
        }
    }
 
    // 安全停止所有动画并重置状态
    private void StopAllTweens()
    {
        // 彻底清理 DOTween 状态并回正
        for (int i = 0; i < tweenTargets.Length; i++)
        {
            if (tweenTargets[i] != null)
            {
                tweenTargets[i].DOKill();
                tweenTargets[i].localEulerAngles = Vector3.zero;
            }
        }
    }
 
    private void PlayShakeAnimation(RectTransform target)
    {
        Sequence shakeSequence = DOTween.Sequence();
 
        shakeSequence.Append(target.DOLocalRotate(new Vector3(0, 0, -shakeAngle), timeMultiplier * 1).SetEase(Ease.Linear))
                     .Append(target.DOLocalRotate(new Vector3(0, 0, shakeAngle), timeMultiplier * 2).SetEase(Ease.Linear))
                     .Append(target.DOLocalRotate(new Vector3(0, 0, -shakeAngle), timeMultiplier * 2).SetEase(Ease.Linear))
                     .Append(target.DOLocalRotate(Vector3.zero, timeMultiplier * 1).SetEase(Ease.Linear))
                     .AppendInterval(pauseDuration);  // 添加停顿
        shakeSequence.SetLoops(-1);
        shakeSequence.SetTarget(target);
    }
}