235 lines
7.7 KiB
C#
235 lines
7.7 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using DG.Tweening;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UniRx;
|
|
|
|
public class EventChallengeMatchingLoadingPanel : MonoBehaviour
|
|
{
|
|
private FishingChallengeManager _fishingChallengeManager;
|
|
//
|
|
private Animation _panelAnimation;
|
|
|
|
private Button _btnMask;
|
|
|
|
private TMP_Text text_title;
|
|
//
|
|
private TMP_Text text_info;
|
|
//
|
|
private TMP_Text text_num;
|
|
|
|
private TMP_Text _prizeTextNum;
|
|
private Image _iconPrize;
|
|
|
|
private GameObject rootGo;
|
|
|
|
private GameObject text_match_success;
|
|
private GameObject text_match;
|
|
private GameObject text_continue;
|
|
private Animation player;
|
|
private RectTransform region;
|
|
|
|
private IDisposable _disposable;
|
|
|
|
private List<EventChallengeHead> headList = new();
|
|
|
|
//
|
|
private int _uiType = 0;
|
|
|
|
private void Awake()
|
|
{
|
|
Log("Awake");
|
|
|
|
_uiType = FishingChallengeAct.CloudType;
|
|
|
|
_fishingChallengeManager = GContext.container.Resolve<FishingChallengeManager>();
|
|
_disposable = GContext.OnEvent<EndTransition>().Subscribe(EndTransition);
|
|
_panelAnimation = transform.GetComponent<Animation>();
|
|
_btnMask = transform.Find("top").GetComponent<Button>();
|
|
_iconPrize = transform.Find("bg/total_prize/icon_prize").GetComponent<Image>();
|
|
_prizeTextNum = transform.Find("bg/total_prize/reward/text_num").GetComponent<TMP_Text>();
|
|
|
|
//
|
|
rootGo = transform.Find("root").gameObject;
|
|
text_title = transform.Find("root/text_title").GetComponent<TMP_Text>();
|
|
text_num = transform.Find("root/challenger/text_num").GetComponent<TMP_Text>();
|
|
text_match_success = transform.Find("root/text_match_success").gameObject;
|
|
text_match = transform.Find("root/text_match").gameObject;
|
|
text_continue = transform.Find("root/text_continue").gameObject;
|
|
player = transform.Find("root/player").GetComponent<Animation>();
|
|
player.gameObject.SetActive(false);
|
|
|
|
}
|
|
private async void Start()
|
|
{
|
|
Log("Start");
|
|
var itemData = _fishingChallengeManager.GetFinalReward().FirstOrDefault();
|
|
if (itemData?.count > 0)
|
|
{
|
|
_prizeTextNum.text = "x" + ConvertTools.GetNumberString(itemData.count);
|
|
}
|
|
|
|
if (_uiType == 1)
|
|
{
|
|
rootGo.SetActive(true);
|
|
PlayAni();
|
|
_btnMask.onClick.AddListener(OnEnter);
|
|
// var listItemData = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(_fishingChallengeManager.eventChallengeMain.WinnerReward);
|
|
// if (listItemData is { Count: > 0 })
|
|
// {
|
|
// //var count = listItemData.Sum(itemData => itemData.count);
|
|
// // _prizeTextNum.GetComponent<TMP_Text>().text = "x" + ConvertTools.GetNumberString(count);
|
|
// }
|
|
_btnMask.enabled = false;
|
|
text_continue.SetActive(false);
|
|
text_match_success.SetActive(false);
|
|
text_match.SetActive(true);
|
|
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("EventChallengeMatchingPopupPanel");
|
|
}
|
|
else
|
|
{
|
|
rootGo.SetActive(false);
|
|
await PlayBgAni();
|
|
}
|
|
|
|
}
|
|
|
|
private async Task PlayBgAni()
|
|
{
|
|
// 等待开始动画播完
|
|
await Awaiters.Seconds(0.68f);
|
|
_panelAnimation.Play("loading_loop");
|
|
await Awaiters.Seconds(0.1f);
|
|
}
|
|
|
|
private async void PlayAni()
|
|
{
|
|
Log("PlayAni");
|
|
text_num.text = "1";
|
|
await PlayBgAni();
|
|
_fishingChallengeManager.MatchComplete();
|
|
ShowPlay();
|
|
await Awaiters.Seconds(1);
|
|
SetPlay();
|
|
int curPlay = 1;
|
|
int allPlay = _fishingChallengeManager.eventChallengeMain.RobotNumber + 1;
|
|
float len = player.clip.length;
|
|
DOTween.To(() => curPlay, x => curPlay = x, allPlay, len).OnUpdate(() => text_num.text = curPlay.ToString()).SetEase(Ease.InCubic);
|
|
await Awaiters.Seconds(len);
|
|
text_num.text = allPlay.ToString();
|
|
text_match_success.SetActive(true);
|
|
text_match.SetActive(false);
|
|
text_continue.SetActive(true);
|
|
_btnMask.enabled = true;
|
|
}
|
|
void SetPlay()
|
|
{
|
|
player.gameObject.SetActive(true);
|
|
// await Awaiters.Seconds(0.5f);
|
|
}
|
|
void ShowPlay()
|
|
{
|
|
Log("ShowPlay");
|
|
|
|
var robotAccountList = _fishingChallengeManager.fishingChallengeData.robotAccountList;
|
|
Dictionary<int, cfg.Robot> robots = GContext.container.Resolve<cfg.Tables>().TbRobot.DataMap;
|
|
IUIService uiService = GContext.container.Resolve<IUIService>();
|
|
Transform player = transform.Find("root/player");
|
|
|
|
EventChallengeHead myHead = player.Find("myself/EventChallengeHead").GetComponent<EventChallengeHead>();
|
|
uiService.SetHeadImage(myHead.icon_head, GContext.container.Resolve<IUserService>().AvatarUrl);
|
|
myHead.bg_head_myself.SetActive(true);
|
|
int residual = player.childCount;
|
|
for (int i = 1; i < residual; i++)
|
|
{
|
|
var head = player.Find($"{i}/EventChallengeHead").GetComponent<EventChallengeHead>();
|
|
if (robots.TryGetValue(robotAccountList[i], out cfg.Robot robot))
|
|
{
|
|
uiService.SetHeadImage(head.icon_head, robot.Avatar);
|
|
}
|
|
headList.Add(head);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 随机位置
|
|
/// </summary>
|
|
/// <param name="region">区域</param>
|
|
/// <param name="residual">剩余人数</param>
|
|
/// <returns>vector2+scale</returns>
|
|
List<Vector3> GetRandomPos(RectTransform region, int residual)
|
|
{
|
|
var rect = region.rect;
|
|
float width = rect.width / 2;
|
|
float height = rect.height / 2;
|
|
List<Vector3> vector2s = new List<Vector3>();
|
|
for (int i = 0; i < residual; i++)
|
|
{
|
|
//在园内随机位置
|
|
Vector3 randomPosition = UnityEngine.Random.insideUnitCircle;
|
|
randomPosition.x *= width;
|
|
randomPosition.y = -Math.Abs(randomPosition.y) * 2 * height + height;
|
|
randomPosition.z = Mathf.Lerp(1, 0.7f, (randomPosition.y + height) / rect.height);
|
|
vector2s.Add(randomPosition);
|
|
}
|
|
vector2s.Sort((a, b) => b.y.CompareTo(a.y));
|
|
return vector2s;
|
|
}
|
|
async void OnEnter()
|
|
{
|
|
// _panelAnimation.Play("loading_end");
|
|
// await Awaiters.Seconds(0.7f);
|
|
StartCoroutine(End());
|
|
}
|
|
private void EndLoad()
|
|
{
|
|
// load?.Dispose();
|
|
// load = null;
|
|
// btn_close.onClick.RemoveAllListeners();
|
|
// btn_close.gameObject.SetActive(false);
|
|
// bg_bar.SetActive(false);
|
|
}
|
|
public void EndTransition(EndTransition endTransition)
|
|
{
|
|
if(_uiType == 0)
|
|
{
|
|
// EndLoad();
|
|
StartCoroutine(End());
|
|
}
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
Dispose();
|
|
}
|
|
IEnumerator End()
|
|
{
|
|
_panelAnimation.Play("loading_end");
|
|
Dispose();
|
|
yield return new WaitForSeconds(0.6f);
|
|
if (FishingChallengeAct.CloudType == 1)
|
|
{
|
|
GContext.Publish(new EventNotifyMatchComplete());
|
|
yield return new WaitForSeconds(0.3f);
|
|
}
|
|
UIManager.Instance.DestroyUI(gameObject.name);
|
|
FishingChallengeAct.CloudType = 0;
|
|
}
|
|
private void Dispose()
|
|
{
|
|
_disposable?.Dispose();
|
|
_disposable = null;
|
|
}
|
|
private void Log(object message)
|
|
{
|
|
Debug.Log($"<color=#00ffff> EventChallengeMatchingPopupPanel -> {message} </color>");
|
|
}
|
|
}
|