PartnerEntityView.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using FL.Battle;
  2. using FL.Battle.Components;
  3. using Spine.Unity;
  4. using UnityEngine;
  5. using XGame.Framework.Map;
  6. using XGame.Framework.ObjectCollection;
  7. namespace FL.Map
  8. {
  9. public class PartnerEntityView : BattleEntityView<PartnerEntityVM>, ISkillContext, IAnimatorContext, IVfxContext, IStatesContext, IEpigraphicsContext
  10. {
  11. /// <summary>
  12. /// 随从没有血条等UI资源
  13. /// </summary>
  14. public override Transform UIPoint => null;
  15. protected override EEntityType DefaultTargetType => EEntityType.Monster;
  16. //public void FindTarget(int skillId)
  17. //{
  18. // Selector.FindAsync(this, EEntityType.Monster, (target) =>
  19. // {
  20. // SelectTarget(target, skillId);
  21. // });
  22. //}
  23. public IAnimator Animator => GetComponent<AnimatorComponent>();
  24. #region ISkillContext
  25. Transform ISkillContext.ActionRoot => VM.ActionRoot;
  26. #endregion
  27. //#region ISpineContext
  28. //SkeletonAnimation ISpineContext.Skeleton => VM.Skeleton;
  29. //#endregion
  30. #region IAnimatorContext
  31. Animator IAnimatorContext.Animator => VM.Animator;
  32. #endregion
  33. #region IVfxContext
  34. Transform IVfxContext.WorldTr => null;
  35. Transform IVfxContext.CenterTr => VM.Tr;
  36. Transform IVfxContext.CastTr => VM.VfxRoot;
  37. #endregion
  38. int IEpigraphicsContext.EpigraphId => (Entity as PartnerEntity).EpigraphId;
  39. public override EpigraphicsComponent Epigraphics => GetComponent<EpigraphicsComponent>();
  40. /// <summary>
  41. /// 随从的身体镜像,所有武器默认向左,玩家左边的武器镜像翻转朝右
  42. /// </summary>
  43. public void BodyMirror()
  44. {
  45. //var scale = Vector3.one * PartnerTableRepo.Get(Entity.TableId).Size;
  46. //scale.z = 1;
  47. //if (LocalPosition.x < 0)
  48. //{
  49. // scale.x *= -1;
  50. //}
  51. //VM.Skeleton.transform.localScale = scale;
  52. }
  53. }
  54. public class PartnerEntityVM : EntityViewModel
  55. {
  56. public Transform ActionRoot { get; private set; }
  57. public SkeletonAnimation Skeleton { get; private set; }
  58. public Transform VfxRoot { get; private set; }
  59. public Animator Animator { get; private set; }
  60. protected override void OnInit(IObjectCollector collector)
  61. {
  62. ActionRoot = collector.GetGameObject("ActionRoot").transform;
  63. Skeleton = collector.GetComponent<SkeletonAnimation>("Skeleton");
  64. VfxRoot = collector.GetGameObject("VfxRoot").transform;
  65. Animator = collector.GetComponent<Animator>("Animator");
  66. }
  67. }
  68. }