CombatCameraControllder.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using Common.Utility.CombatEvent;
  3. using Fort23.Core;
  4. using UnityEngine;
  5. using Utility;
  6. using Utility.CustomizeTimeLogic.FxLogic.TimeLineEvent;
  7. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  8. namespace GameLogic.Combat.CombatTool
  9. {
  10. public class CombatCameraControllder : IDisposable, ICameraShaking
  11. {
  12. public Transform root;
  13. public Camera Camera;
  14. public CombatController combatController;
  15. public StressReceiver StressReceiver;
  16. private bool isStartShake;
  17. public int FollowHeroId
  18. {
  19. get { return _followHeroId; }
  20. }
  21. private int _followHeroId = -1;
  22. public bool isStop;
  23. public void Init(CombatController combatController, Camera camera)
  24. {
  25. this.combatController = combatController;
  26. Camera = camera;
  27. root = Camera.transform.parent;
  28. StressReceiver = camera.transform.GetComponentInParent<StressReceiver>();
  29. TimeLineSingletonEventManager.Instance.AddTimeLineBasic(this);
  30. EventManager.Instance.AddEventListener(CustomEventType.HeroClick, HeroClick);
  31. // EventManager.Instance.AddEventListener(CustomEventType.HeroClick, HeroClick);
  32. }
  33. protected void HeroClick(IEventData eventData)
  34. {
  35. HeroClickEventData heroClickEventData = eventData as HeroClickEventData;
  36. int heroId = heroClickEventData.heroId;
  37. if (_followHeroId == heroId)
  38. {
  39. _followHeroId = -1;
  40. }
  41. else
  42. {
  43. _followHeroId = heroId;
  44. }
  45. }
  46. private void ShakeFinish()
  47. {
  48. isStartShake = false;
  49. }
  50. public void Update(float t)
  51. {
  52. if (!isStartShake && !isStop)
  53. {
  54. CombatHeroEntity combatHeroEntities = combatController.CombatHeroController.followTarget;
  55. if (combatHeroEntities == null)
  56. {
  57. return;
  58. }
  59. if (combatHeroEntities.isDie)
  60. {
  61. CombatHeroEntity[] allHero= combatController.CombatHeroController.GetHero(false);
  62. if (allHero != null&& allHero.Length > 0)
  63. {
  64. combatHeroEntities= allHero[0];
  65. }
  66. }
  67. Vector3 p = combatHeroEntities.dotPos;
  68. // bool isHero = false;
  69. // if (_followHeroId != -1)
  70. // {
  71. // for (int i = 0; i < combatHeroEntities.Length; i++)
  72. // {
  73. // if (combatHeroEntities[i].CurrCombatHeroInfo.modelID == _followHeroId)
  74. // {
  75. // p = combatHeroEntities[i].dotPos;
  76. // isHero = true;
  77. // break;
  78. // }
  79. // }
  80. // }
  81. //
  82. // if (!isHero)
  83. // {
  84. // int c = 0;
  85. // for (int i = 0; i < combatHeroEntities.Length; i++)
  86. // {
  87. // if (!combatHeroEntities[i].isDie)
  88. // {
  89. // c++;
  90. // p += combatHeroEntities[i].dotPos;
  91. // }
  92. // }
  93. //
  94. // if (c <= 0)
  95. // {
  96. // return;
  97. // }
  98. //
  99. // p /= c;
  100. // }
  101. // Vector3 tp = root.TransformVector(new Vector3(0, 0, -20));
  102. root.position = Vector3.Lerp(root.position, p, 0.05f);
  103. }
  104. }
  105. public void Dispose()
  106. {
  107. EventManager.Instance.RemoveEventListener(CustomEventType.HeroClick, HeroClick);
  108. }
  109. public void Shaking(float qiangDu)
  110. {
  111. if (StressReceiver != null)
  112. {
  113. isStartShake = true;
  114. StressReceiver.InduceStress(qiangDu, ShakeFinish);
  115. }
  116. }
  117. public void Shaking(CameraShakingSerializtion cameraShakingSerializtion)
  118. {
  119. Shaking(cameraShakingSerializtion.qiangDu);
  120. }
  121. }
  122. }