54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
![]() |
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Threading;
|
||
|
using Animancer;
|
||
|
using Cysharp.Threading.Tasks;
|
||
|
using Project.B.CharacterController;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace Net.Project.B.Emoji
|
||
|
{
|
||
|
public class PlayerAnimancerEmoji
|
||
|
{
|
||
|
private readonly IEmojiService<AnimationClip> _emojiService;
|
||
|
private readonly ICharacterController _characterController;
|
||
|
private readonly AnimancerComponent _animancerComponent;
|
||
|
|
||
|
public PlayerAnimancerEmoji(IEmojiService<AnimationClip> emojiService, ICharacterController characterController, AnimancerComponent animancerComponent)
|
||
|
{
|
||
|
_emojiService = emojiService;
|
||
|
_characterController = characterController;
|
||
|
_animancerComponent = animancerComponent;
|
||
|
|
||
|
_emojiService.OnPlayAsync+= OnPlayAsync;
|
||
|
}
|
||
|
|
||
|
private async UniTask OnPlayAsync(IEmojiData<AnimationClip> arg1, CancellationToken arg2)
|
||
|
{
|
||
|
var currentState = _characterController.CurrentState;
|
||
|
|
||
|
_characterController.TransitionState<ICharacterStateAnimation>();
|
||
|
|
||
|
var layer = _animancerComponent.Layers[_animancerComponent.Layers.Count+1];
|
||
|
|
||
|
var task = layer.Play(arg1.Clip);
|
||
|
|
||
|
try
|
||
|
{
|
||
|
await task.WithCancellation(arg2);
|
||
|
}
|
||
|
catch (OperationCanceledException)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
layer.Stop();
|
||
|
layer.Weight = 0;
|
||
|
layer.DestroyStates();
|
||
|
|
||
|
_characterController.TransitionState(currentState);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|