-
Notifications
You must be signed in to change notification settings - Fork 2
Common.Spine
DucNV_2000 edited this page Jul 10, 2024
·
1 revision
-
Duration
Get duration animation
float Duration(this SkeletonAnimation skeletonAnimation, string animationName) // Get duration animation by animation name for skeleton animation
float Duration(this SkeletonAnimation skeletonAnimation, int track = 0) // Get duration animation by track index for skeleton animation
float Duration(this SkeletonGraphic skeletonGraphic, string animationName) // Get duration animation by animation name for skeleton graphic
float Duration(this SkeletonGraphic skeletonGraphic, int track = 0) // Get duration animation by track index for skeleton graphic
Example Duration
:
public SkeletonAnimation skeletonAnimation;
public string animAttack;
public int trackIndex;
public float GetDurationByAnimationNameAttack()
{
return skeletonAnimation.Duration(animAttack);
}
public float GetDurationByTrackIndexAttack()
{
return skeletonAnimation.Duration(trackIndex);
}
-
Play
Clear state, play and initialize skeleton
SkeletonAnimation Play(this SkeletonAnimation skeletonAnimation, string animationName, bool loop = false, int trackIndex = 0) //for skeleton animation
SkeletonGraphic Play(this SkeletonGraphic skeletonGraphic, string animationName, bool loop = false, int trackIndex = 0) //for skeleton graphic
Example Play
:
public SkeletonAnimation skeletonAnimation;
public string animAttack;
public void PlayAttack()
{
skeletonAnimation.Play(animAttack);
}
-
PlayOnly
Play only skeleton not clear state and not initialize skeleton
SkeletonAnimation PlayOnly(this SkeletonAnimation skeletonAnimation, string animationName, bool loop = false, int trackIndex = 0) //for skeleton animation
SkeletonGraphic PlayOnly(this SkeletonGraphic skeletonGraphic, string animationName, bool loop = false, int trackIndex = 0) //for skeleton graphic
Example PlayOnly
:
public SkeletonAnimation skeletonAnimation;
public string animAttack;
public void PlayOnlyAttack()
{
skeletonAnimation.PlayOnly(animAttack);
}
-
OnComplete
Completion event plays an animation
SkeletonAnimation OnComplete(this SkeletonAnimation skeletonAnimation, Action onComplete, int trackIndex = 0, MonoBehaviour target = null) // For skeleton animation
SkeletonGraphic OnComplete(this SkeletonGraphic skeletonGraphic, Action onComplete, int trackIndex = 0, MonoBehaviour target = null) // For skeleton graphic
Example OnComplete
:
public SkeletonAnimation skeletonAnimation;
public string animAttack;
public void PlayAttack()
{
skeletonAnimation.PlayOnly(animAttack).OnComplete(() =>
{
// handle completed anim attack
});
}
-
OnUpdate
Update during play animation
SkeletonAnimation OnUpdate(this SkeletonAnimation skeletonAnimation, Action<float> onUpdate, int trackIndex = 0, MonoBehaviour target = null) // For skeleton animation
SkeletonGraphic OnUpdate(this SkeletonGraphic skeletonGraphic, Action<float> onUpdate, int trackIndex = 0, MonoBehaviour target = null) // For skeleton graphic
Example
[SerializeField] private SkeletonGraphic skeletonGraphic;
[SerializeField] private string animShoot;
private void PlayShoot()
{
skeletonGraphic.PlayOnly(animShoot, false).OnUpdate(f => { Debug.Log("update"); }).OnComplete(() =>
{
Debug.Log("completed");
});
}
-
AddAnimation
Add animation
SkeletonAnimation AddAnimation(this SkeletonAnimation skeletonAnimation, int trackIndex, string animationName, bool loop, float timeDelay = 0f, float mixDuration = 0f) // Add animation for skeleton animation
SkeletonGraphic AddAnimation(this SkeletonGraphic skeletonGraphic, int trackIndex, string animationName, bool loop, float timeDelay = 0f, float mixDuration = 0f) // Add animation for skeleton graphic
Example AddAnimation
: both run and attack
public SkeletonAnimation skeletonAnimation;
public string animRun;
public string animAttack;
public void PlayRun()
{
skeletonAnimation.PlayOnly(animRun, true);
}
public void AddAttack()
{
skeletonAnimation.AddAnimation(1, animAttack, false);
}
-
SetSkin
Set new skin for skeleton
SkeletonAnimation SetSkin(this SkeletonAnimation skeletonAnimation, string skinName) //for skeleton animation
SkeletonAnimation SetSkin(this SkeletonAnimation skeletonAnimation, List<string> skinNames) //for skeleton animation
SkeletonGraphic SetSkin(this SkeletonGraphic skeletonGraphic, string skinName) //for skeleton graphic
SkeletonGraphic SetSkin(this SkeletonGraphic skeletonGraphic, List<string> skinNames) //for skeleton graphic
Example SetSkin
:
public SkeletonAnimation skeletonAnimation;
public string skin1;
public List<string> listSkin;
public void SetSkin1()
{
skeletonAnimation.SetSkin(skin1);
}
public void SetListSkin()
{
skeletonAnimation.SetSkin(listSkin);
}
ChangeAttachment
SkeletonAnimation ChangeAttachment(this SkeletonAnimation skeletonAnimation, string slotName, string attachmentName) //for skeleton animation
SkeletonAnimation ChangeAttachment(this SkeletonAnimation skeletonAnimation, string slotName, List<string> attachmentNames) //for skeleton animation
SkeletonGraphic ChangeAttachment(this SkeletonGraphic skeletonGraphic, string slotName, string attachmentName) //for skeleton graphic
SkeletonGraphic ChangeAttachment(this SkeletonGraphic skeletonGraphic, string slotName, List<string> attachmentNames) //for skeleton graphic
Example ChangeAttachment
:
public SkeletonAnimation skeletonAnimation;
public string slotName;
public string attachmentName;
public List<string> listAttachmentName;
public void ChangeAttachment()
{
skeletonAnimation.ChangeAttachment(slotName, attachmentName);
}
public void ChangeListAttachment()
{
skeletonAnimation.ChangeAttachment(slotName, listAttachmentName);
}
MixSkin
SkeletonAnimation MixSkin(this SkeletonAnimation skeletonAnimation, string mixSkinName) //for skeleton animation
SkeletonAnimation MixSkin(this SkeletonAnimation skeletonAnimation, List<string> mixSkinNames) //for skeleton animation
SkeletonGraphic MixSkin(this SkeletonGraphic skeletonGraphic, string mixSkinName) //for skeleton graphic
SkeletonGraphic MixSkin(this SkeletonGraphic skeletonGraphic, List<string> mixSkinNames) //for skeleton graphic
Example MixSkin
:
public SkeletonAnimation skeletonAnimation;
public string mixSkin;
public List<string> listMixSkin;
public void MixSkin()
{
skeletonAnimation.MixSkin(mixSkin);
}
public void MixListSkin()
{
skeletonAnimation.MixSkin(listMixSkin);
}