126 lines
3.7 KiB
C#
126 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.Playables;
|
|
|
|
public class ItemClickSettlementPanel : BasePanel
|
|
{
|
|
|
|
#region UI_ELEMENTS
|
|
|
|
private GameObject fingerObj;
|
|
private EventTrigger eventTrigger;
|
|
private PlayableDirector playableDirector;
|
|
|
|
[SerializeField] private float tipsShowTime = 5f;
|
|
[SerializeField] private float clickPonyGapTime = 0.5f;
|
|
[SerializeField] [Min(1)] private int clickMaxTimes = 5;
|
|
[SerializeField] private List<PlayableAsset> hitTimelines;
|
|
[SerializeField] private PlayableAsset idelTimeline;
|
|
[SerializeField] private PlayableAsset openTimeline;
|
|
[SerializeField] private float time = 0.5f;
|
|
|
|
#endregion UI_ELEMENTS
|
|
|
|
private readonly string guideKey = "ItemClick";
|
|
|
|
private int _clickCount;
|
|
private float _clickGapTime;
|
|
private bool _isClicking;
|
|
private ItemClick _itemClick;
|
|
|
|
private PointerEventData _pointerEventData;
|
|
|
|
private void Awake()
|
|
{
|
|
eventTrigger = gameObject.FindChildGameObject("btn_scene").GetComponent<EventTrigger>();
|
|
|
|
var entry = new EventTrigger.Entry();
|
|
entry.eventID = EventTriggerType.PointerClick;
|
|
entry.callback.AddListener(OnPointerClick);
|
|
eventTrigger.triggers.Add(entry);
|
|
|
|
fingerObj = gameObject.FindChildGameObject("finger").gameObject;
|
|
Observable.Interval(TimeSpan.FromSeconds(clickPonyGapTime)).Subscribe(ResetClickScene).AddTo(this);
|
|
playableDirector = gameObject.FindChildGameObject("spineRoot").GetComponent<PlayableDirector>();
|
|
GContext.OnEvent<RewardPanelClose>().Subscribe(OnEvent_RewardPanelClose).AddTo(disposables);
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
playableDirector.Play(idelTimeline, DirectorWrapMode.Loop);
|
|
}
|
|
|
|
private void OnEvent_RewardPanelClose(RewardPanelClose close)
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.ItemClickSettlementPanel);
|
|
}
|
|
|
|
public void SetData(ItemClick itemClick)
|
|
{
|
|
_itemClick = itemClick;
|
|
}
|
|
|
|
public void OnPointerClick(BaseEventData eventData)
|
|
{
|
|
_pointerEventData = eventData as PointerEventData;
|
|
OnClickScene();
|
|
}
|
|
|
|
private void OnClickScene()
|
|
{
|
|
if (_isClicking) return;
|
|
|
|
_isClicking = true;
|
|
_clickGapTime = 0;
|
|
fingerObj.SetActive(false);
|
|
_clickCount++;
|
|
if (_itemClick != null)
|
|
if (PlayerPrefs.GetInt($"{guideKey}_{_itemClick.ID}") == 0)
|
|
PlayerPrefs.SetInt($"{guideKey}_{_itemClick.ID}", 1);
|
|
if (_clickCount == clickMaxTimes)
|
|
{
|
|
PlayAni(openTimeline, true);
|
|
}
|
|
else
|
|
{
|
|
var index = _clickCount <= hitTimelines.Count ? _clickCount - 1 : hitTimelines.Count - 1;
|
|
var hitTimeline = hitTimelines[index];
|
|
PlayAni(hitTimeline, false);
|
|
}
|
|
}
|
|
|
|
private async void PlayAni(PlayableAsset playableAsset, bool isOpen)
|
|
{
|
|
playableDirector.Play(playableAsset, DirectorWrapMode.None);
|
|
if (isOpen)
|
|
{
|
|
await Awaiters.Seconds(time);
|
|
GContext.container.Resolve<IDeferredRewardStashService>()?.Flush();
|
|
GContext.Publish(new ShowData());
|
|
}
|
|
|
|
playableDirector.stopped += _ =>
|
|
{
|
|
_isClicking = false;
|
|
playableDirector.Play(idelTimeline, DirectorWrapMode.Loop);
|
|
};
|
|
}
|
|
|
|
private void ResetClickScene(long _ = 0)
|
|
{
|
|
_clickGapTime += clickPonyGapTime;
|
|
IsShowTips();
|
|
}
|
|
|
|
private void IsShowTips(long _ = 0)
|
|
{
|
|
if (_clickGapTime >= tipsShowTime) fingerObj.SetActive(_clickCount < clickMaxTimes);
|
|
}
|
|
} |