MonsterEntityView.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 MonsterEntityView : BattleEntityView<MonsterEntityVM>, ISkillContext, ISpineContext, IVfxContext, IStatesContext
  10. {
  11. public override Transform UIPoint => VM.UIPoint;
  12. protected override EEntityType DefaultTargetType => EEntityType.Player;
  13. //public void FindTarget(int skillId)
  14. //{
  15. // Selector.FindAsync(this, EEntityType.Player, (target) =>
  16. // {
  17. // SelectTarget(target, skillId);
  18. // });
  19. //}
  20. public IAnimator Animator => GetComponent<SpineComponent>();
  21. #region ISkillContext
  22. Transform ISkillContext.ActionRoot => VM.ActionRoot;
  23. void ISkillContext.OnSkillStart(int skillId)
  24. {
  25. if (States.IsState(EEntityState.MoveAI))
  26. {
  27. Move.Pause();
  28. }
  29. }
  30. void ISkillContext.OnSkillStop(int skillId)
  31. {
  32. //TOTO 临时代码
  33. if ((Entity as MonsterEntity).IsBoss)
  34. return;
  35. //TOTO 临时代码
  36. if (States.IsState(EEntityState.MoveAI))
  37. {
  38. Move.Resume();
  39. }
  40. else
  41. {
  42. var target = (Entity as MonsterEntity).BirthPosition;
  43. target.y -= 8;
  44. target.x += Random.Range(-2.5f, 2.5f);
  45. target.y += Random.Range(-4f, 4f);
  46. var moveArgs = new MoveArgs()
  47. {
  48. target = VM.Tr.parent.TransformPoint(target),
  49. speed = Entity.Attr.MoveSpeed * 0.5f,
  50. timeScale = Entity.Attr.MoveSpeedScale,
  51. };
  52. moveArgs.onComplete += () =>
  53. {
  54. States.RemoveState(EEntityState.MoveAI);
  55. };
  56. States.AddState(EEntityState.MoveAI);
  57. Move.MoveTo(moveArgs);
  58. }
  59. }
  60. #endregion
  61. #region ISpineContext
  62. SkeletonAnimation ISpineContext.Skeleton => VM.Skeleton;
  63. #endregion
  64. #region IVfxContext
  65. Transform IVfxContext.WorldTr => null;
  66. Transform IVfxContext.CenterTr => VM.Tr;
  67. Transform IVfxContext.CastTr => VM.Tr;
  68. #endregion
  69. public override EpigraphicsComponent Epigraphics => null;
  70. }
  71. public class MonsterEntityVM : EntityViewModel
  72. {
  73. public Transform ActionRoot { get; private set; }
  74. public Transform UIPoint { get; private set; }
  75. public SkeletonAnimation Skeleton { get; private set; }
  76. protected override void OnInit(IObjectCollector collector)
  77. {
  78. ActionRoot = collector.GetGameObject("ActionRoot").transform;
  79. UIPoint = collector.GetGameObject("UIPoint").transform;
  80. Skeleton = collector.GetComponent<SkeletonAnimation>("Skeleton");
  81. }
  82. }
  83. }