Files
ft/Client/Assets/Scripts/UI/OfferStoryChain/OfferStoryChainSpineCtrl.cs
2026-06-29 21:18:33 +08:00

85 lines
2.9 KiB
C#

using System.Linq;
using Spine.Unity;
using UnityEngine;
using System.Threading.Tasks;
using System;
using asap.core;
public class OfferStoryChainSpineCtrl : OfferStoryChainAnimationCtrl
{
[SerializeField] private SkeletonGraphic skeletonGraphic;
// private readonly string[] _idleAnimNames = Enumerable.Range(1, 6).Select(i => "npc_offerchainwinter_idle_s" + i).ToArray();
// private readonly string[] _aniNames = {
// "npc_offerchainwinter_equip_hat",
// "npc_offerchainwinter_equip_gloves",
// "npc_offerchainwinter_equip_scarf",
// "npc_offerchainwinter_equip_pipe", // But, this is a vest instead of a pipe
// "npc_offerchainwinter_equip_rod"
// };
// private readonly string[] _audioNames =
// {
// "audio_ui_offerchainwinter_equip_hat",
// "audio_ui_offerchainwinter_equip_gloves",
// "audio_ui_offerchainwinter_equip_scarf",
// "audio_ui_offerchainwinter_equip_vest",
// "audio_ui_offerchainwinter_equip_rod"
// };
private string[] _idleAnimNames;
private string[] _aniNames;
private string[] _audioNames;
public override void Init(string baseName)
{
// _idleAnimNames = Enumerable.Range(1, 6).Select(i => baseName + "_idle_" + i).ToArray();
// _aniNames = Enumerable.Range(1, 5).Select(i => baseName + "_action_" + i).ToArray();
_idleAnimNames = Enumerable.Range(1, 6).Select(i => "idle_" + i).ToArray();
_aniNames = Enumerable.Range(1, 5).Select(i => "action_" + i).ToArray();
_audioNames = Enumerable.Range(1, 5).Select(i => "audio_" + baseName + "_action_" + i).ToArray();
}
public override void PlayIdleAnimation(int progress)
{
try
{
skeletonGraphic.AnimationState.SetAnimation(0, _idleAnimNames[progress], true);
}
catch (Exception e)
{
Debug.LogError(e);
}
}
public override async Task PlayUpdateAnimation(int progress)
{
try
{
GContext.Publish(new Game.EventUISound(_audioNames[progress - 1]));
skeletonGraphic.AnimationState.SetAnimation(0, _aniNames[progress - 1], false);
var duration = skeletonGraphic.AnimationState.GetCurrent(0).Animation.Duration;
skeletonGraphic.AnimationState.AddAnimation(0, _idleAnimNames[progress], true, 0f);
await Task.Delay(TimeSpan.FromSeconds(duration));
}
catch (Exception e)
{
Debug.LogError(e);
}
}
// #if UNITY_EDITOR
// [Header("Test")]
// [SerializeField] private int progress;
// private void Update()
// {
// if (Input.GetKeyDown(KeyCode.I))
// {
// PlayIdleAnimation(progress);
// }
// if (Input.GetKeyDown(KeyCode.U))
// {
// PlayUpdateAnimation(progress);
// }
// }
// #endif
}