You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Plugins/Animancer/Examples/09 Animator Controllers/02 3D Game Kit/States/RespawnState.cs

60 lines
2.3 KiB
C#

3 months ago
// Animancer // Copyright 2020 Kybernetik //
#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
using UnityEngine;
using UnityEngine.Events;
namespace Animancer.Examples.AnimatorControllers.GameKit
{
/// <summary>
/// A <see cref="CreatureState"/> which teleports back to the starting position, plays an animation then returns
/// to the <see cref="Creature.Idle"/> state.
/// </summary>
[AddComponentMenu(Strings.MenuPrefix + "Examples/Game Kit - Respawn State")]
[HelpURL(Strings.APIDocumentationURL + ".Examples.AnimatorControllers.GameKit/RespawnState")]
public sealed class RespawnState : CreatureState
{
/************************************************************************************************************************/
[SerializeField] private ClipState.Transition _Animation;
[SerializeField] private UnityEvent _OnEnterState;// See the Read Me.
[SerializeField] private UnityEvent _OnExitState;// See the Read Me.
private Vector3 _StartingPosition;
/************************************************************************************************************************/
private void Awake()
{
_Animation.Events.Sequence.OnEnd = Creature.ForceEnterIdleState;
_StartingPosition = transform.position;
}
/************************************************************************************************************************/
private void OnEnable()
{
Creature.Animancer.Play(_Animation);
Creature.transform.position = _StartingPosition;
_OnEnterState.Invoke();
}
/************************************************************************************************************************/
private void OnDisable()
{
_OnExitState.Invoke();
}
/************************************************************************************************************************/
public override bool CanExitState(CreatureState nextState)
{
return false;
}
/************************************************************************************************************************/
}
}