Super Knight : Enter the Dungeon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.3 KiB

using Spine;
using Spine.Unity;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Serialization;
public class ProjectileSpine : MonoBehaviour
{
[System.Serializable]
public class Control
{
[Space(10)]
public int layer;
[SpineAnimation]
public string name;
public bool loop;
[Space]
public float timeScale = 1f;
[Space]
public bool useMixDuration;
public float mixDuration;
}
public SkeletonAnimation skeletonAnimation;
Spine.AnimationState spineState;
private void OnEnable()
{
if (spineState == null)
spineState = skeletonAnimation.state;
Play_Idle();
}
[Space(10)]
public Control idle;
[System.Serializable]
public class IdleEndEvent : UnityEvent<bool> { }
[FormerlySerializedAs("onIdleEnd")]
[SerializeField]
[Space(10)]
private IdleEndEvent onIdleEnd = new IdleEndEvent();
public void Play_Idle()
{
Play(idle, () =>
{
onIdleEnd.Invoke(true);
});
}
public Control hit;
[System.Serializable]
public class EndEvent : UnityEvent<bool> { }
[FormerlySerializedAs("onEnd")]
[SerializeField]
[Space(10)]
private EndEvent onEnd = new EndEvent();
public void Play_Hit()
{
Play(hit, () =>
{
onEnd.Invoke(true);
}, null);
}
public void Play(Control control, System.Action OnEnd = null, System.Action<Spine.Event> OnEvent = null)
{
TrackEntry track = spineState.SetAnimation(control.layer, control.name, control.loop);
if (track != null)
{
if (control != null)
{
track.MixDuration = control.useMixDuration ? control.mixDuration : 0;
track.TimeScale = control.timeScale;
}
if (OnEnd != null)
{
track.Complete += delegate (TrackEntry entry)
{
OnEnd();
};
}
if (OnEvent != null)
{
track.Event += delegate (TrackEntry trackEntry, Spine.Event e)
{
OnEvent(e);
};
}
}
}
}