224 lines
6.7 KiB
C#
224 lines
6.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using Cysharp.Threading.Tasks;
|
|
using DG.Tweening;
|
|
using Stary.Evo;
|
|
using Stary.Evo.RKTools;
|
|
using UnityEngine;
|
|
|
|
namespace Main
|
|
{
|
|
public interface IClickSystem : ISystem
|
|
{
|
|
void AddClickIntervalEvent(Action callback);
|
|
void StartTime();
|
|
void EndClick();
|
|
|
|
void BindClickEvent(List<ClickElementChildren> clickElementChildrens, Action<GameObject> callback);
|
|
void ClickBreatheTween(List<ClickElementChildren> tweenList, Transform tweenTarget);
|
|
|
|
bool IsElementChildrenClick();
|
|
}
|
|
|
|
public class ClickSystem : AbstractSystem, IClickSystem
|
|
{
|
|
// public Sequence loopTargetTween;
|
|
|
|
/// <summary>
|
|
/// 点击计时器
|
|
/// </summary>
|
|
public float time;
|
|
|
|
private CancellationTokenSource tokenSource;
|
|
|
|
|
|
private List<ClickElementChildren> clickElementChildrens;
|
|
|
|
|
|
private Action ClickIntervalEvent;
|
|
|
|
protected override void OnInit()
|
|
{
|
|
}
|
|
|
|
public void StartTime()
|
|
{
|
|
time = 0;
|
|
Update();
|
|
}
|
|
|
|
public void BindClickEvent(List<ClickElementChildren> clickElementChildrens, Action<GameObject> callback)
|
|
{
|
|
StartTime();
|
|
this.clickElementChildrens = clickElementChildrens;
|
|
//绑定点击事件
|
|
foreach (var child in clickElementChildrens)
|
|
{
|
|
child.transform.gameObject.ObjectAddTouchEvent(callback);
|
|
}
|
|
}
|
|
public void ClickBreatheTween(List<ClickElementChildren> tweenList, Transform tweenTarget)
|
|
{
|
|
Debug.Log("UnityEvo: 点击呼吸");
|
|
time = 0;
|
|
foreach (var tween in tweenList)
|
|
{
|
|
tween.transform.gameObject.ObjectResumeTouchEvent();
|
|
// if (tween.transform == tweenTarget)
|
|
// {
|
|
// tween.isClick = true;
|
|
// }
|
|
|
|
if (tween.transform == tweenTarget)
|
|
{
|
|
tween.isClick = true;
|
|
tween.transform.GetComponent<Animator>().CrossFade("dianji_idle", 0.2f);
|
|
this.SendEvent<ModeType, ClickElementChildren>(ModeType.PLayAudioOrVideo,tween);
|
|
tweenTarget.gameObject.ObjectPauseTouchEvent();
|
|
// if (loopTargetTween != null)
|
|
// {
|
|
// loopTargetTween.Kill();
|
|
// loopTargetTween = null;
|
|
// }
|
|
//
|
|
// loopTargetTween = DOTween.Sequence();
|
|
// loopTargetTween.Append(tweenTarget.DOScale(tweenTarget.lossyScale * 1.3f, 1f));
|
|
//
|
|
// loopTargetTween.SetLoops(6, LoopType.Yoyo);
|
|
// loopTargetTween.OnKill(() =>
|
|
// {
|
|
// if (tweenTarget != null)
|
|
// tweenTarget.DOScale(Vector3.one, 0.3f);
|
|
// });
|
|
// loopTargetTween.Play();
|
|
|
|
|
|
continue;
|
|
}
|
|
|
|
// tween.transform.DOKill();
|
|
// tween.transform.DOScale(Vector3.one * 0.9f, 0.5f);
|
|
tween.transform.GetComponent<Animator>().CrossFade("dianji_nood", 1f);
|
|
}
|
|
}
|
|
|
|
public void AddClickIntervalEvent(Action callback)
|
|
{
|
|
this.ClickIntervalEvent = callback;
|
|
}
|
|
public bool IsElementChildrenClick()
|
|
{
|
|
//是否全部已经点击
|
|
for (int i = 0; i < clickElementChildrens.Count; i++)
|
|
{
|
|
if (clickElementChildrens[i].isClick == false)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public void EndClick()
|
|
{
|
|
// if (loopTargetTween != null)
|
|
// {
|
|
// loopTargetTween.Kill();
|
|
// loopTargetTween = null;
|
|
// }
|
|
|
|
time = 0;
|
|
if (tokenSource != null)
|
|
{
|
|
tokenSource?.Cancel();
|
|
tokenSource?.Dispose();
|
|
tokenSource = null;
|
|
}
|
|
|
|
foreach (var children in clickElementChildrens)
|
|
{
|
|
children.transform.gameObject.ObjectRemoveTouchEvent();
|
|
children.transform.GetComponent<Animator>().CrossFade("dianji_disappear", 0.2f);
|
|
|
|
}
|
|
}
|
|
|
|
private async void Update()
|
|
{
|
|
//TODO暂时禁用
|
|
// if (tokenSource != null)
|
|
// {
|
|
// tokenSource?.Cancel();
|
|
// }
|
|
//
|
|
// tokenSource = new CancellationTokenSource();
|
|
// try
|
|
// {
|
|
// while (time <= 11 && !tokenSource.IsCancellationRequested)
|
|
// {
|
|
// time += Time.deltaTime;
|
|
//
|
|
// if (time >= 10)
|
|
// {
|
|
// Debug.Log("UnityEvo:执行未点击间隔事件");
|
|
// time = 0;
|
|
// ClickIntervalEvent?.Invoke();
|
|
// }
|
|
//
|
|
// await UniTask.Yield(tokenSource.Token);
|
|
// }
|
|
// }
|
|
// catch (OperationCanceledException e)
|
|
// {
|
|
// Debug.Log("UnityEvo: 取消任务:" + e);
|
|
// }
|
|
}
|
|
|
|
public override void Dispose()
|
|
{
|
|
if (tokenSource != null)
|
|
{
|
|
tokenSource?.Cancel();
|
|
tokenSource?.Dispose();
|
|
tokenSource = null;
|
|
}
|
|
|
|
// if (loopTargetTween != null)
|
|
// {
|
|
// loopTargetTween.Kill();
|
|
// loopTargetTween = null;
|
|
// }
|
|
}
|
|
|
|
|
|
}
|
|
public class ClickElementChildren
|
|
{
|
|
public bool isClick = false;
|
|
public string[] auid;
|
|
public string vid;
|
|
public Transform transform;
|
|
|
|
public Transform targetTransform;
|
|
|
|
public ClickElementChildren(Transform child)
|
|
{
|
|
|
|
this. transform = child;
|
|
}
|
|
public ClickElementChildren(Transform child, string[] auid, string vid)
|
|
{
|
|
this.auid = auid;
|
|
this.vid = vid;
|
|
this. transform = child;
|
|
}
|
|
public ClickElementChildren(Transform child,Transform targetTransform , string[] auid, string vid)
|
|
{
|
|
this.auid = auid;
|
|
this.vid = vid;
|
|
this. transform = child;
|
|
this.targetTransform= targetTransform;
|
|
}
|
|
}
|
|
} |