102 lines
2.8 KiB
C#
102 lines
2.8 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2021-09-28
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "PetSpineAnimation" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using Spine.Unity;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 宠物spine动画
|
|||
|
/// </summary>
|
|||
|
public class PetSpineAnimation : MonoBehaviour
|
|||
|
{
|
|||
|
#region Field
|
|||
|
|
|||
|
public int mode = 0;
|
|||
|
|
|||
|
SkeletonGraphic _skeleton;
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
private void Play(string name)
|
|||
|
{
|
|||
|
if (!_skeleton)
|
|||
|
return;
|
|||
|
|
|||
|
_skeleton.AnimationState.Complete += OnAnimComp;
|
|||
|
_skeleton.AnimationState.SetAnimation(0, name, false);
|
|||
|
}
|
|||
|
|
|||
|
private void OnAnimComp(Spine.TrackEntry trackEntry)
|
|||
|
{
|
|||
|
var animationName = trackEntry.Animation.Name;
|
|||
|
if (animationName == "show" || animationName == "skill")
|
|||
|
{
|
|||
|
_skeleton.AnimationState.Complete -= OnAnimComp;
|
|||
|
_skeleton.AnimationState.SetAnimation(0, "idle", true);
|
|||
|
StartCoroutine(DoSkill());
|
|||
|
}
|
|||
|
else if (animationName == "course")
|
|||
|
{
|
|||
|
_skeleton.AnimationState.SetAnimation(0, "skill_idle", false);
|
|||
|
}
|
|||
|
else if (animationName == "skill_idle")
|
|||
|
{
|
|||
|
if (Random.value < 0.3f)
|
|||
|
_skeleton.AnimationState.SetAnimation(0, "skill_idle", false);
|
|||
|
else
|
|||
|
_skeleton.AnimationState.SetAnimation(0, "skill", false);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
IEnumerator DoSkill()
|
|||
|
{
|
|||
|
var rndSeconds = Random.Range(5f, 20f);
|
|||
|
yield return new WaitForSeconds(rndSeconds);
|
|||
|
if (mode == 1)
|
|||
|
Play("skill");
|
|||
|
else
|
|||
|
Play("course");
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Unity
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
_skeleton = GetComponent<SkeletonGraphic>();
|
|||
|
var pos = this.transform.position;
|
|||
|
pos.z = -10000f;
|
|||
|
this.transform.position = pos;
|
|||
|
}
|
|||
|
private IEnumerator Start()
|
|||
|
{
|
|||
|
yield return null;
|
|||
|
var pos = this.transform.position;
|
|||
|
pos.z = 0;
|
|||
|
this.transform.position = pos;
|
|||
|
}
|
|||
|
// Use this for initialization
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
Play("show");
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|