I'm trying to adapt the SpineboyTargetController from the "Getting Started" example to use SkeletonMecanim instead of SkeletonAnimation. The original script gets the mouse position and sets a "Shoot target" bone at that position.
However I can't figure out how to get a Bone from a SkeletonMecanim, to then be able to change it's transform, and also get the transform of the animation.
What I tried skeletonMecanim.skeletonDataAsset.GetAnimationStateData().skeletonData.FindBone(boneName); returns a BoneData object, and not a Bone.
Also i can't find the equivalent of skeletonAnimation.transform in a SkeletonMecanim.
Here's the original code:
public class SpineboyTargetController : MonoBehaviour {
   public SkeletonAnimation skeletonAnimation;
   [SpineBone(dataField:"skeletonAnimation")]
   public string boneName;
   public new Camera camera;
   Bone bone;
   void OnValidate () {
      if (skeletonAnimation == null) skeletonAnimation = GetComponent<SkeletonAnimation>();
   }
   void Start () {
      bone = skeletonAnimation.Skeleton.FindBone(boneName);
   }
   void Update () {
      var mousePosition = Input.mousePosition;
      var worldMousePosition = camera.ScreenToWorldPoint(mousePosition);
      var skeletonSpacePoint = skeletonAnimation.transform.InverseTransformPoint(worldMousePosition);
      skeletonSpacePoint.x *= skeletonAnimation.Skeleton.ScaleX;
      skeletonSpacePoint.y *= skeletonAnimation.Skeleton.ScaleY;
      bone.SetLocalPosition(skeletonSpacePoint);
   }
}
Here's my code. I've marked my issues with "ISSUE".
public class SpineBoneTargetController : MonoBehaviour {
   public SkeletonMecanim skeletonMecanim;
   [SpineBone(dataField:"skeletonMecanim")]
   public string boneName;
   public new Camera camera;
   Bone bone;
   void OnValidate () {
      if (skeletonMecanim == null) skeletonMecanim = GetComponent<SkeletonMecanim>();
   }
   void Start () {
      
  // Original code
  //bone = skeletonAnimation.Skeleton.FindBone(boneName);
  
  // ISSUE - I've tried this, but it returns a BoneData object
  bone = skeletonMecanim.skeletonDataAsset.GetAnimationStateData().skeletonData.FindBone(boneName);
   }
   void Update () {
      var mousePosition = Input.mousePosition;
      var worldMousePosition = camera.ScreenToWorldPoint(mousePosition);
      
  // ISSUE - How to get the transform of the current animation? (skeletonAnimation doesn't exist here)
  var skeletonSpacePoint = skeletonAnimation.transform.InverseTransformPoint(worldMousePosition);
  skeletonSpacePoint.x *= skeletonAnimation.Skeleton.ScaleX;
  skeletonSpacePoint.y *= skeletonAnimation.Skeleton.ScaleY;
  bone.SetLocalPosition(skeletonSpacePoint);
   }
}
Thankful for any help! 🙂