/*--------------------------------------------------------------------
- Author Name: DXL
- Creation Time: 6/11/2019 2:58:08 PM
- File Describe: 挂载在Spine上面的脚本,用于物体跟随Spine移动
- ------------------------------------------------------------------*/
using Spine;
using Spine.Unity;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpineFollow : MonoBehaviour
{
public int boneIndex; //要绑定跟随的骨骼
public GameObject follower; //跟随移动的物体
public bool isStop = false; //是否停止移动
public float offsetX = 0; //相对骨骼的绑点的X坐标偏移量
public float offsetY = 0; //相对骨骼的绑点的Y坐标偏移量
/*************************************************
*这里的Spine使用的是SkeletonAnimator,如果不使用这种Spine,
* 建议使用SkeletonGraphic的形式来绑定物体,更加的方便
*************************************************/
Bone bone; //要绑定的骨骼
SkeletonAnimator sa;
void Start()
{
sa = transform.GetComponent<SkeletonAnimator>();
}
void Update()
{
if (follower && !isStop && follower.activeInHierarchy && sa != null)
{
if (boneIndex < 0 || boneIndex > sa.Skeleton.Bones.Items.Length)
{
return;
}
bone = sa.Skeleton.Bones.Items[boneIndex];
follower.transform.localPosition = new Vector3(bone.WorldX + offsetX, bone.WorldY + offsetY, 0);
}
}
}