2024-06-19 04:29:32 -07:00
|
|
|
using System;
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
using DG.Tweening;
|
|
|
|
using GadGame.Event.Type;
|
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
2024-06-19 20:25:06 -07:00
|
|
|
using UnityEngine.Serialization;
|
2024-06-19 04:29:32 -07:00
|
|
|
using UnityEngine.UI;
|
2024-06-25 01:40:52 -07:00
|
|
|
using GadGame.Network;
|
2024-06-19 04:29:32 -07:00
|
|
|
|
|
|
|
namespace GadGame.Scripts.Coffee
|
|
|
|
{
|
|
|
|
public class CoffeeController : MonoBehaviour
|
|
|
|
{
|
2024-06-19 20:25:06 -07:00
|
|
|
[SerializeField] private VoidEvent _engageReadyEvent;
|
2024-06-21 01:20:01 -07:00
|
|
|
[SerializeField] private StringEvent _generateImageSuccessEvent;
|
2024-06-19 04:29:32 -07:00
|
|
|
[SerializeField] private BoolEvent _playPassByAnimEvent;
|
|
|
|
[SerializeField] private BoolEvent _playVideoEvent;
|
|
|
|
[SerializeField] private FloatEvent _readyCountDownEvent;
|
2024-06-19 20:25:06 -07:00
|
|
|
[SerializeField] private StringEvent _encodeImageEvent;
|
2024-06-19 04:29:32 -07:00
|
|
|
[SerializeField] private CanvasGroup _idleBg;
|
2024-06-19 20:25:06 -07:00
|
|
|
[SerializeField] private LoadImageEncoded _userImager;
|
2024-06-19 04:29:32 -07:00
|
|
|
[SerializeField] private Image _process;
|
|
|
|
[SerializeField] private TextMeshProUGUI _hintText;
|
2024-06-24 01:57:54 -07:00
|
|
|
[SerializeField] private GameObject _notify;
|
|
|
|
[SerializeField] private GameObject _hint;
|
2024-06-19 04:29:32 -07:00
|
|
|
[SerializeField] private Image _loading;
|
2024-06-19 20:30:19 -07:00
|
|
|
[SerializeField] private float _loadingSpeed = 100;
|
2024-06-19 04:29:32 -07:00
|
|
|
[SerializeField] private string[] _texts;
|
|
|
|
[SerializeField] private string[] _loadingTexts;
|
|
|
|
|
|
|
|
private int _indexText;
|
|
|
|
private bool _isLoading;
|
|
|
|
private float _timer;
|
|
|
|
|
2024-06-25 01:40:52 -07:00
|
|
|
private async void Awake()
|
2024-06-19 04:29:32 -07:00
|
|
|
{
|
2024-06-25 01:40:52 -07:00
|
|
|
await P4PGraphqlManager.Instance.JoinPromotion();
|
|
|
|
await P4PGraphqlManager.Instance.SubmitGameSession(0);
|
2024-06-19 04:29:32 -07:00
|
|
|
_idleBg.alpha = 1;
|
2024-06-20 04:00:53 -07:00
|
|
|
_loading.transform.DOLocalRotate(new Vector3(0, 0, 360), 10 / _loadingSpeed, RotateMode.FastBeyond360)
|
|
|
|
.SetLoops(-1)
|
|
|
|
.SetRelative(true)
|
|
|
|
.SetEase(Ease.Linear);
|
2024-06-24 01:57:54 -07:00
|
|
|
|
|
|
|
_notify.SetActive(false);
|
|
|
|
_hint.SetActive(false);
|
2024-06-19 04:29:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
{
|
2024-06-19 20:25:06 -07:00
|
|
|
_engageReadyEvent.Register(OnEngageReady);
|
|
|
|
_generateImageSuccessEvent.Register(OnGenerateImageSuccess);
|
2024-06-19 04:29:32 -07:00
|
|
|
_playPassByAnimEvent.Register(Play);
|
|
|
|
_playVideoEvent.Register(SetPlayVideo);
|
|
|
|
_readyCountDownEvent.Register(SetReadyCountDown);
|
2024-06-19 20:25:06 -07:00
|
|
|
_encodeImageEvent.Register(OnGetEncodeImage);
|
2024-06-19 04:29:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
2024-06-19 20:25:06 -07:00
|
|
|
_engageReadyEvent.Unregister(OnEngageReady);
|
|
|
|
_generateImageSuccessEvent.Unregister(OnGenerateImageSuccess);
|
2024-06-19 04:29:32 -07:00
|
|
|
_playPassByAnimEvent.Unregister(Play);
|
|
|
|
_playVideoEvent.Unregister(SetPlayVideo);
|
|
|
|
_readyCountDownEvent.Unregister(SetReadyCountDown);
|
2024-06-19 20:25:06 -07:00
|
|
|
_encodeImageEvent.Unregister(OnGetEncodeImage);
|
2024-06-19 04:29:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if(!_isLoading) return;
|
|
|
|
_timer += Time.deltaTime;
|
|
|
|
if (_timer >= 3)
|
|
|
|
{
|
|
|
|
_timer = 0;
|
|
|
|
_indexText++;
|
|
|
|
if (_indexText > _loadingTexts.Length - 1)
|
|
|
|
{
|
|
|
|
_indexText = 0;
|
|
|
|
}
|
2024-06-24 01:57:54 -07:00
|
|
|
// _hintText.text = _loadingTexts[_indexText];
|
2024-06-19 04:29:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Play(bool engage) {
|
|
|
|
// videoPlayer.gameObject.SetActive(!passBy);
|
|
|
|
// _transform.DOAnchorPosX(engage ? -1000 : 0, 1);
|
2024-06-24 01:57:54 -07:00
|
|
|
// _hintText.text = _texts[0];
|
2024-06-19 04:29:32 -07:00
|
|
|
}
|
|
|
|
|
2024-06-21 01:20:01 -07:00
|
|
|
private void OnGenerateImageSuccess(string desc)
|
2024-06-19 04:29:32 -07:00
|
|
|
{
|
2024-06-21 01:20:01 -07:00
|
|
|
_isLoading = false;
|
2024-06-20 04:00:53 -07:00
|
|
|
_loading.DOFade(0.255f, 0.5f);
|
2024-06-24 01:57:54 -07:00
|
|
|
// _hintText.text = desc;
|
|
|
|
_notify.SetActive(false);
|
|
|
|
_hint.SetActive(false);
|
2024-06-19 04:29:32 -07:00
|
|
|
}
|
|
|
|
|
2024-06-21 01:20:01 -07:00
|
|
|
private void OnGetEncodeImage(string filePath)
|
2024-06-19 20:25:06 -07:00
|
|
|
{
|
2024-06-21 01:20:01 -07:00
|
|
|
_userImager.LoadImage(filePath);
|
2024-06-24 01:57:54 -07:00
|
|
|
_notify.SetActive(true);
|
2024-06-19 20:25:06 -07:00
|
|
|
}
|
|
|
|
|
2024-06-19 04:29:32 -07:00
|
|
|
private void OnEngageReady()
|
|
|
|
{
|
|
|
|
_process.fillAmount = 0;
|
|
|
|
_isLoading = true;
|
2024-06-24 01:57:54 -07:00
|
|
|
// _hintText.text = _loadingTexts[_indexText];
|
2024-06-19 04:29:32 -07:00
|
|
|
_loading.DOFade(1, 1f);
|
2024-06-24 01:57:54 -07:00
|
|
|
_hint.SetActive(true);
|
2024-06-19 04:29:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private async void SetPlayVideo(bool value){
|
|
|
|
if(value) {
|
|
|
|
while (_idleBg.alpha < 1)
|
|
|
|
{
|
|
|
|
_idleBg.alpha += Time.deltaTime * 3;
|
|
|
|
await UniTask.Yield();
|
|
|
|
}
|
|
|
|
_idleBg.alpha = 1;
|
|
|
|
} else {
|
|
|
|
while (_idleBg.alpha > 0)
|
|
|
|
{
|
|
|
|
_idleBg.alpha -= Time.deltaTime * 3;
|
|
|
|
await UniTask.Yield();
|
|
|
|
}
|
|
|
|
_idleBg.alpha = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetReadyCountDown(float progress){
|
2024-06-24 01:57:54 -07:00
|
|
|
// _hintText.text = _texts[1];
|
2024-06-25 01:40:52 -07:00
|
|
|
_process.fillAmount = 1 - progress ;
|
2024-06-19 04:29:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|