240 lines
8.2 KiB
C#
240 lines
8.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using asap.core;
|
|
using DG.Tweening;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.UI;
|
|
|
|
public class EventChallengeLevelTips : MonoBehaviour
|
|
{
|
|
//
|
|
public int[] stepLeft;
|
|
|
|
// UI
|
|
private TMP_Text _textTitle;
|
|
private Image _bar;
|
|
private TMP_Text _textNum;
|
|
private Image _icon;
|
|
private Animation _rootAni;
|
|
//reward
|
|
private RewardItemNew _reward;
|
|
|
|
private RewardItemNew _scoreReward;
|
|
//
|
|
private FishingChallengeManager _fishingChallengeManager;
|
|
private TaskCompletionSource<bool> _tcs;
|
|
|
|
// 默认值
|
|
private float _speed = 1.0f;
|
|
private float _wait1 = 0.2f;
|
|
private float _wait2 = 0.5f;
|
|
private float _wait3 = 0.5f;
|
|
|
|
//
|
|
private Transform bg_left;
|
|
private Transform bg_right;
|
|
private Transform bg_lastround_left;
|
|
private Transform bg_lastround_right;
|
|
|
|
//
|
|
private Sound audio_ui_fishingduel_numincrease_sound;
|
|
private AudioClip audio_ui_fishingduel_numincrease;
|
|
|
|
// StopLoopAudio();
|
|
// audio_matchingloop = GContext.container.Resolve<ISoundService>().GetNewUISound(audio_ui_fishingduel_matchingloop);
|
|
// audio_matchingloop.audioSource.Play();
|
|
// audio_matchingloop.audioSource.loop = true;
|
|
private int _curStep;
|
|
// 最高积分,内部更新
|
|
private int _maxScore;
|
|
private void Awake()
|
|
{
|
|
_fishingChallengeManager = GContext.container.Resolve<FishingChallengeManager>();
|
|
_textTitle = transform.Find("tips/root/text_title").GetComponent<TMP_Text>();
|
|
_rootAni = transform.Find("tips/root").GetComponent<Animation>();
|
|
_bar = transform.Find("tips/root/bg_bar/bar").GetComponent<Image>();
|
|
_textNum = transform.Find("tips/root/bg_bar/text_num").GetComponent<TMP_Text>();
|
|
_reward = transform.Find("tips/root/reward").GetComponent<RewardItemNew>();
|
|
_scoreReward = transform.Find("tips/root/reward").GetComponent<RewardItemNew>();
|
|
_icon = transform.Find("tips/root/btn_icon/icon").GetComponent<Image>();
|
|
bg_left = transform.Find("tips/root/bg_left");
|
|
bg_right = transform.Find("tips/root/bg_right");
|
|
bg_lastround_left = transform.Find("tips/root/bg_lastround_left");
|
|
bg_lastround_right = transform.Find("tips/root/bg_lastround_right");
|
|
LoadAudio();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
StopLoopAudio();
|
|
}
|
|
|
|
async void LoadAudio()
|
|
{
|
|
audio_ui_fishingduel_numincrease = await Addressables.LoadAssetAsync<AudioClip>("audio_ui_fishingduel_numincrease").Task;
|
|
}
|
|
|
|
public void SetCurStep(int curStep)
|
|
{
|
|
_curStep = curStep;
|
|
_maxScore = _fishingChallengeManager.GetMaxScoreByStep(curStep);
|
|
var checkValue = _curStep + 1;
|
|
var flag = checkValue == _fishingChallengeManager.GetFullStep();
|
|
//
|
|
if (stepLeft.Contains(checkValue))
|
|
{
|
|
bg_right.gameObject.SetActive(false);
|
|
bg_lastround_right.gameObject.SetActive(false);
|
|
bg_left.gameObject.SetActive(false);
|
|
bg_lastround_left.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
bg_left.gameObject.SetActive(false);
|
|
bg_lastround_left.gameObject.SetActive(false);
|
|
bg_right.gameObject.SetActive(false);
|
|
bg_lastround_right.gameObject.SetActive(true);
|
|
}
|
|
|
|
}
|
|
public void Init(int oldScore)
|
|
{
|
|
var curStep = _fishingChallengeManager.GetStepByScore(oldScore,true);
|
|
var maxScore = _fishingChallengeManager.GetMaxScoreByStep(curStep);
|
|
// _textTitle.SetText($"level {curStep + 1}/{_fishingChallengeManager.GetFullStep()}");
|
|
_textTitle.text = LocalizationMgr.GetFormatTextValue("UI_EventChallengeCrocodilePanel_6", curStep + 1, _fishingChallengeManager.GetFullStep());
|
|
// _textNum.SetText($"{oldScore}/{maxScore}");
|
|
// _bar.fillAmount = (float)oldScore / maxScore;
|
|
var beginScore = _fishingChallengeManager.GetBeginScore(oldScore,true);
|
|
_textNum.SetText($"{oldScore - beginScore}/{maxScore - beginScore}");
|
|
_bar.fillAmount = _fishingChallengeManager.GetFillAmount(oldScore,true);
|
|
var itemData = _fishingChallengeManager.GetStageRewardByStep(curStep);
|
|
if (itemData != null)
|
|
{
|
|
_reward.SetData(itemData);
|
|
}
|
|
else
|
|
{
|
|
_reward.gameObject.SetActive(false);
|
|
}
|
|
SetCurStep(curStep);
|
|
}
|
|
|
|
public float GetSpeed()
|
|
{
|
|
return _speed;
|
|
}
|
|
|
|
public async Task<int> ShowTips(int oldScore, int newScore)
|
|
{
|
|
_tcs = new TaskCompletionSource<bool>();
|
|
Init(oldScore);
|
|
var finalScore = Math.Min(newScore, _maxScore);
|
|
await PlayVisibleAni();
|
|
// await PlayScoreIncrementAni();
|
|
await Awaiters.Seconds(_wait1 * GetSpeed());
|
|
StartCoroutine(PlayScorePre(oldScore,finalScore));
|
|
await _tcs.Task;
|
|
return finalScore;
|
|
}
|
|
|
|
void PlayLoopAudio()
|
|
{
|
|
StopLoopAudio();
|
|
audio_ui_fishingduel_numincrease_sound = GContext.container.Resolve<ISoundService>().GetNewUISound(audio_ui_fishingduel_numincrease);
|
|
audio_ui_fishingduel_numincrease_sound.audioSource.Play();
|
|
audio_ui_fishingduel_numincrease_sound.audioSource.loop = true;
|
|
}
|
|
void StopLoopAudio()
|
|
{
|
|
if (audio_ui_fishingduel_numincrease_sound)
|
|
{
|
|
audio_ui_fishingduel_numincrease_sound.audioSource.Stop();
|
|
audio_ui_fishingduel_numincrease_sound.ReturnPool();
|
|
audio_ui_fishingduel_numincrease_sound = null;
|
|
}
|
|
}
|
|
|
|
|
|
// public async Task ShowStageRewardAdded(int step)
|
|
// {
|
|
// await _reward?.transform.DOScale(1.5f, 0.7f)
|
|
// .SetEase(Ease.InOutSine) // 使用平滑的缓动函数
|
|
// .SetLoops(5, LoopType.Yoyo) // Yoyo模式会在正向和反向动画间切换
|
|
// .AsyncWaitForCompletion()!;
|
|
//
|
|
// }
|
|
private IEnumerator PlayScorePre(int startScore,int endScore)
|
|
{
|
|
Log("PlayScorePre");
|
|
// var duration = 0.5f;
|
|
var duration = _wait2 * GetSpeed();
|
|
// _bar.fillAmount = (float)startScore / _maxScore;
|
|
_bar.fillAmount = _fishingChallengeManager.GetFillAmount(startScore,true);
|
|
var endValue = _fishingChallengeManager.GetFillAmount(endScore,false);
|
|
// _bar.DOFillAmount((float)endScore / _maxScore, duration);
|
|
_bar.DOFillAmount(endValue, duration).OnStart(PlayLoopAudio).OnComplete(() =>
|
|
{
|
|
StopLoopAudio();
|
|
_rootAni.Play("bar_finished");
|
|
});
|
|
|
|
|
|
var curScore = startScore - _fishingChallengeManager.GetBeginScore(startScore,true);
|
|
endScore -= _fishingChallengeManager.GetBeginScore(startScore,true);
|
|
var maxValue= _maxScore - _fishingChallengeManager.GetBeginScore(startScore,true);
|
|
DOTween.To(() => curScore, x =>
|
|
{
|
|
curScore = x;
|
|
}, endScore,duration).OnUpdate(() =>
|
|
{
|
|
_textNum.text = $"{curScore}/{maxValue}";
|
|
});
|
|
yield return new WaitForSeconds(duration + _wait3 * GetSpeed());
|
|
// PlayInVisibleAni();
|
|
_tcs.SetResult(true);
|
|
}
|
|
public async Task PlayVisibleAni()
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
private async Task PlayScoreIncrementAni()
|
|
{
|
|
var itemDataNew = new ItemData
|
|
{
|
|
id = _fishingChallengeManager.EventItemId,
|
|
count = 100,
|
|
};
|
|
|
|
var fly = Instantiate(_scoreReward, transform).GetComponent<RewardItemNew>();
|
|
fly.SetRewardPopupData(itemDataNew);
|
|
fly.gameObject.SetActive(true);
|
|
fly.transform.position = _scoreReward.transform.position ;
|
|
await fly.ParticleAttractor();
|
|
}
|
|
public async Task PlayInVisibleAni()
|
|
{
|
|
Log("PlayInVisibleAni()");
|
|
gameObject.SetActive(false);
|
|
}
|
|
private static void Log(object message)
|
|
{
|
|
Debug.Log($"<color=orange>EventChallengeLevelTips => {message} </color>");
|
|
}
|
|
public void SetSpeed(float speed)
|
|
{
|
|
_speed = speed;
|
|
}
|
|
public void UpdateControllerTime(float f, float f1, float f3)
|
|
{
|
|
_wait1 = f;
|
|
_wait2 = f1;
|
|
_wait3 = f3;
|
|
}
|
|
} |