hch
2025-11-24 f0c41c38ec5c651dedc645687597d227dccac981
Main/System/Horse/HorseController.cs
@@ -52,7 +52,16 @@
         instanceGO.transform.localRotation = Quaternion.identity;
      }
      skeletonGraphic = instanceGO.GetComponentInChildren<SkeletonGraphic>(true);
      // skeletonGraphic = instanceGO.GetComponentInChildren<SkeletonGraphic>(true);
      skeletonGraphic = instanceGO.transform.Find("Horse").GetComponent<SkeletonGraphic>();
      if (string.IsNullOrEmpty(skinConfig.Spine))
      {
         //卸下坐骑的情况
         skeletonGraphic.enabled = false;
         spineAnimationState = null;
         CreateHero(_heroSkinID);
         return;
        }
      skeletonGraphic.skeletonDataAsset = ResManager.Instance.LoadAsset<SkeletonDataAsset>("UIEffect/Spine/Horse", skinConfig.Spine);
      if (skeletonGraphic.skeletonDataAsset == null)
@@ -66,6 +75,7 @@
         Debug.LogError("未配置spine");
         return;
      }
      skeletonGraphic.enabled = true;
      skeletonGraphic.Initialize(true);
      skeletonGraphic.transform.localPosition = new Vector3(skinConfig.Poses[0], skinConfig.Poses[1], 0);
@@ -83,9 +93,17 @@
   public void CreateHero(int heroSkinID)
   {
      if (instanceGO == null)
        {
      {
         return;
        }
      }
      if (heroSkinID == 0)
      {
         if (hero != null && hero.gameObject.activeSelf)
            {
                hero.SetActive(false);
            }
         return;
      }
      hero = instanceGO.GetComponentInChildren<UIHeroController>(true);
      if (hero == null)
      {
@@ -98,8 +116,25 @@
      }
      hero.SetActive(true);
      hero.Create(heroSkinID);
      //约定骑乘点骨骼名
      hero.GetComponent<BoneFollowerGraphic>().boneName = "mountPoint";
      // 确保 BoneFollowerGraphic 引用到正确的坐骑 SkeletonGraphic
      var boneFollower = hero.GetComponent<BoneFollowerGraphic>();
      if (boneFollower != null && skeletonGraphic != null && skeletonGraphic.enabled)
      {
         boneFollower.enabled = true;
         // 设置 SkeletonGraphic 引用
         boneFollower.SkeletonGraphic = skeletonGraphic;
         // 约定骑乘点骨骼名
         boneFollower.boneName = "mountPoint";
         // 强制重新初始化 BoneFollowerGraphic 以应用新的设置
         boneFollower.Initialize();
      }
      else
      {
         boneFollower.enabled = false;
         hero.transform.localPosition = new Vector3(0, -50, 0);
      }
      if (isHeroShowBefore)
      {
         hero.transform.SetAsLastSibling();
@@ -112,6 +147,8 @@
   public void HeroPlay(string motionName, bool loop = false, bool replay=true)
   {
      if (hero == null)
         return;
      hero.PlayAnimation(motionName, loop, replay);
   }
@@ -143,6 +180,8 @@
      // 直接使用 ToString() 而不是调用 GetAnimationName
      spineAnimationState.SetAnimation(0, motionName.ToString(), loop);
      HeroPlay(motionName, loop, replay);
   }
   // 播放第一个动画(作为默认动画)