CombatCameraControllder.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.GameObject.transform.TransformPoint(new Vector3(0, 8, -10));
  68. // Vector3 p = combatHeroEntities.dotPos;
  69. // bool isHero = false;
  70. // if (_followHeroId != -1)
  71. // {
  72. // for (int i = 0; i < combatHeroEntities.Length; i++)
  73. // {
  74. // if (combatHeroEntities[i].CurrCombatHeroInfo.modelID == _followHeroId)
  75. // {
  76. // p = combatHeroEntities[i].dotPos;
  77. // isHero = true;
  78. // break;
  79. // }
  80. // }
  81. // }
  82. //
  83. // if (!isHero)
  84. // {
  85. // int c = 0;
  86. // for (int i = 0; i < combatHeroEntities.Length; i++)
  87. // {
  88. // if (!combatHeroEntities[i].isDie)
  89. // {
  90. // c++;
  91. // p += combatHeroEntities[i].dotPos;
  92. // }
  93. // }
  94. //
  95. // if (c <= 0)
  96. // {
  97. // return;
  98. // }
  99. //
  100. // p /= c;
  101. // }
  102. root.rotation = Quaternion.Lerp(root.rotation, combatHeroEntities.GameObject.transform.rotation,
  103. 0.3f);
  104. // Vector3 tp = root.TransformVector(new Vector3(0, 0, -20));
  105. root.position = Vector3.Lerp(root.position, p, 0.3f);
  106. }
  107. }
  108. public void Dispose()
  109. {
  110. EventManager.Instance.RemoveEventListener(CustomEventType.HeroClick, HeroClick);
  111. }
  112. public void Shaking(float qiangDu)
  113. {
  114. if (StressReceiver != null)
  115. {
  116. isStartShake = true;
  117. StressReceiver.InduceStress(qiangDu, ShakeFinish);
  118. }
  119. }
  120. public void Shaking(CameraShakingSerializtion cameraShakingSerializtion)
  121. {
  122. Shaking(cameraShakingSerializtion.qiangDu);
  123. }
  124. }
  125. }