131 lines
4.5 KiB
C#
131 lines
4.5 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using asap.core;
|
|
using DG.Tweening;
|
|
using DG.Tweening.Core.Easing;
|
|
using GameCore;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace EventMowForTreasure
|
|
{
|
|
public class EventMowForTreasureGuidePanel:BasePanel
|
|
{
|
|
private GameObject _guide01;
|
|
private GameObject _guide02;
|
|
private GameObject _guide03;
|
|
private Button _btnClick;
|
|
[SerializeField] private float clickTimes=1f;
|
|
[SerializeField] private Vector2Int targetCoordinate=Vector2Int.one;
|
|
[SerializeField] private Vector2 targetPosOffset=Vector2.one;
|
|
[SerializeField] private Vector3 targetScale=Vector3.one;
|
|
[SerializeField] private float delayTime=0.5f;
|
|
[SerializeField] private float aniTime;
|
|
[SerializeField] private Ease easeCurve;
|
|
private float _time;
|
|
private void Awake()
|
|
{
|
|
_guide01 = gameObject.FindChildGameObject("guide01");
|
|
_guide02 = gameObject.FindChildGameObject("guide02");
|
|
_guide03 = gameObject.FindChildGameObject("guide03");
|
|
_btnClick = gameObject.FindChildGameObject("btn_click").GetComponent<Button>();
|
|
_btnClick.onClick.AddListener(OnClick);
|
|
Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(disposables);
|
|
}
|
|
protected override void OnDestroy()
|
|
{
|
|
_btnClick.onClick.RemoveListener(OnClick);
|
|
base.OnDestroy();
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
ShowGuide();
|
|
}
|
|
private void ShowGuide()
|
|
{
|
|
var manager=GContext.container.Resolve<EventMowForTreasureManager>();
|
|
var step = manager.Data.GuideStep;
|
|
var act=(EventMowForTreasureAct)GContext.container.ResolveAct(manager.GetCurrentStageAct());
|
|
var position= act.GetObstacleCellPositionByCoordinate(targetCoordinate);
|
|
position= new Vector2(position.x+targetPosOffset.x,position.y+targetPosOffset.y);
|
|
_guide01.SetActive(step==2);
|
|
_guide02.SetActive(step==3);
|
|
_guide03.SetActive(step==4);
|
|
switch (step)
|
|
{
|
|
case 2:
|
|
_guide01.FindChildGameObject("finger").transform.position = position;
|
|
break;
|
|
case 3:
|
|
GuideAni(_guide02.FindChildGameObject("finger").transform,position);
|
|
break;
|
|
case 4:
|
|
GuideAni(_guide03.FindChildGameObject("finger").transform,position);
|
|
break;
|
|
}
|
|
}
|
|
private Tween moveTween;
|
|
private Tween scaleTween;
|
|
private void GuideAni(Transform finger,Vector2 targetPos)
|
|
{
|
|
moveTween?.Kill();
|
|
scaleTween?.Kill();
|
|
StartGuideAnimationLoop(finger, targetPos);
|
|
}
|
|
|
|
private void StartGuideAnimationLoop(Transform finger, Vector2 targetPos)
|
|
{
|
|
// 记录初始状态
|
|
Vector3 originalPos = finger.position;
|
|
Vector3 originalScale = finger.localScale;
|
|
|
|
moveTween = finger.DOMove(targetPos, aniTime)
|
|
.SetEase(easeCurve)
|
|
.OnComplete(() => OnAnimationComplete(finger, targetPos, originalPos, originalScale));
|
|
|
|
scaleTween = finger.DOScale(targetScale, aniTime)
|
|
.SetEase(easeCurve);
|
|
}
|
|
|
|
private async void OnAnimationComplete(Transform finger, Vector2 targetPos, Vector3 originalPos, Vector3 originalScale)
|
|
{
|
|
try
|
|
{
|
|
await Awaiters.Seconds(delayTime);
|
|
|
|
// 重置到初始状态
|
|
if(!finger) return;
|
|
finger.position = originalPos;
|
|
finger.localScale = originalScale;
|
|
|
|
StartGuideAnimationLoop(finger, targetPos);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
private void OnClick()
|
|
{
|
|
if(_time<clickTimes) return;
|
|
_time = 0;
|
|
var manager=GContext.container.Resolve<EventMowForTreasureManager>();
|
|
manager.AddGuideStep();
|
|
if (manager.Data.GuideStep > 4)
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.EventMowForTreasureGuidePopup);
|
|
manager.TryShowGuide();
|
|
}
|
|
else
|
|
ShowGuide();
|
|
}
|
|
private void UpdateTimer(long time)
|
|
{
|
|
_time++;
|
|
}
|
|
}
|
|
} |