96 lines
3.1 KiB
C#
96 lines
3.1 KiB
C#
using DG.Tweening;
|
|
using Spine.Unity;
|
|
using UnityEngine;
|
|
using System.Threading.Tasks;
|
|
using System;
|
|
using GameCore;
|
|
using asap.core;
|
|
using Game;
|
|
|
|
public class EventBreakBoxingGlove : EventBreakDrillDisplay
|
|
{
|
|
public override float Y
|
|
{
|
|
get
|
|
{
|
|
aniSpring.Skeleton.UpdateWorldTransform();
|
|
var bones = aniSpring.Skeleton.Bones;
|
|
var bone = bones.Items[59];
|
|
// var worldPos = bone.GetWorldPosition(aniSpring.transform, 100);
|
|
var worldPos = bone.GetWorldPosition(aniSpring.transform, UIManager.Instance.CanvasScaler.referencePixelsPerUnit);
|
|
return worldPos.y;
|
|
}
|
|
}
|
|
private Vector3 _originalPos;
|
|
[SerializeField] private SkeletonGraphic aniSpring;
|
|
private const string Idle = "boxing_idle", Push = "boxing_start", Pull = "boxing_return";
|
|
private readonly string[] _launchAudios =
|
|
new string[] { "audio_ui_eventbreak_boxing_start_01",
|
|
"audio_ui_eventbreak_boxing_start_02",
|
|
"audio_ui_eventbreak_boxing_start_03" };
|
|
private int _tunnelIdx;
|
|
|
|
public override Tween GetDrillTween(Vector3 endPos, float duration = 0.5f)
|
|
{
|
|
// transform.position = _originalPos;
|
|
// var push = transform.DOMove(endPos, duration).SetEase(Ease.InSine);
|
|
// var pull = transform.DOMove(_originalPos, duration).SetEase(Ease.InSine);
|
|
// return DOTween.Sequence().Append(push).Append(pull);
|
|
float t = 0;
|
|
return DOTween.To(() => t, x => t = x, 1f, duration);
|
|
}
|
|
|
|
public override void Init(int tunnelIndex)
|
|
{
|
|
_originalPos = transform.position;
|
|
PlayAnimation(Idle);
|
|
_tunnelIdx = tunnelIndex;
|
|
}
|
|
|
|
public override async void PlayDrill(float readyDuration = 0)
|
|
{
|
|
try
|
|
{
|
|
Debug.Log("[EventBreak] Play Drill.");
|
|
GContext.Publish(new EventUISound(_launchAudios[_tunnelIdx]));
|
|
await PlayAnimationAsync(Push);
|
|
await PlayAnimationAsync(Pull);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log($"[EventBreak] Play Drill Error");
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
public override void PlayEnter(Vector3 startPos)
|
|
{
|
|
// Debug.Log("[EventBreak] Play Enter in boxing.");
|
|
}
|
|
|
|
private async Task PlayAnimationAsync(string animationName, double duration = 0)
|
|
{
|
|
if (aniSpring == null)
|
|
return;
|
|
var animationEntry = aniSpring.AnimationState.SetAnimation(0, animationName, false);
|
|
if (duration == 0)
|
|
duration = animationEntry.Animation.Duration;
|
|
await Task.Delay(TimeSpan.FromSeconds(duration));
|
|
// var bl = aniSpring.Skeleton.Bones.ToList();
|
|
// for (int i = 0; i < bl.Count; i++)
|
|
// {
|
|
// Debug.Log($"[EventBreak] {i}: {bl[i].Data.Name} at height {bl[i].WorldY}");
|
|
// }
|
|
}
|
|
|
|
private void PlayAnimation(string animationName)
|
|
{
|
|
aniSpring.AnimationState.SetAnimation(0, animationName, false);
|
|
}
|
|
|
|
private void Reset()
|
|
{
|
|
aniSpring = transform.Find("spine").GetComponent<SkeletonGraphic>();
|
|
}
|
|
}
|