CombatCameraControllder.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. private int _followHeroId = -1;
  18. public GameObject MainLight;
  19. public void Init(CombatController combatController, Camera camera)
  20. {
  21. this.combatController = combatController;
  22. Camera = camera;
  23. root = Camera.transform.parent;
  24. StressReceiver = camera.transform.GetComponentInParent<StressReceiver>();
  25. TimeLineSingletonEventManager.Instance.AddTimeLineBasic(this);
  26. EventManager.Instance.AddEventListener(CustomEventType.HeroClick, HeroClick);
  27. MainLight = camera.transform.Find("MainLight").gameObject;
  28. // EventManager.Instance.AddEventListener(CustomEventType.HeroClick, HeroClick);
  29. }
  30. protected void HeroClick(IEventData eventData)
  31. {
  32. HeroClickEventData heroClickEventData = eventData as HeroClickEventData;
  33. int heroId = heroClickEventData.heroId;
  34. if (_followHeroId == heroId)
  35. {
  36. _followHeroId = -1;
  37. }
  38. else
  39. {
  40. _followHeroId = heroId;
  41. }
  42. }
  43. private void ShakeFinish()
  44. {
  45. isStartShake = false;
  46. }
  47. public void Update(float t)
  48. {
  49. if (!isStartShake)
  50. {
  51. CombatHeroEntity[] combatHeroEntities = combatController.CombatHeroController.GetHero(false);
  52. if (combatHeroEntities == null)
  53. {
  54. return;
  55. }
  56. Vector3 p = Vector3.zero;
  57. bool isHero = false;
  58. if (_followHeroId != -1)
  59. {
  60. for (int i = 0; i < combatHeroEntities.Length; i++)
  61. {
  62. if (combatHeroEntities[i].CurrCombatHeroInfo.modelID == _followHeroId)
  63. {
  64. p = combatHeroEntities[i].dotPos;
  65. isHero = true;
  66. break;
  67. }
  68. }
  69. }
  70. if (!isHero)
  71. {
  72. int c = 0;
  73. for (int i = 0; i < combatHeroEntities.Length; i++)
  74. {
  75. if (!combatHeroEntities[i].isDie)
  76. {
  77. c++;
  78. p += combatHeroEntities[i].dotPos;
  79. }
  80. }
  81. if (c <= 0)
  82. {
  83. return;
  84. }
  85. p /= c;
  86. }
  87. MainLight.transform.position = new Vector3(p.x,5.6f,p.z);
  88. // Vector3 tp = root.TransformVector(new Vector3(0, 0, -20));
  89. root.position = Vector3.Lerp(root.position, new Vector3(p.x, root.position.y, p.z + 13), 0.1f);
  90. }
  91. }
  92. public void Dispose()
  93. {
  94. EventManager.Instance.RemoveEventListener(CustomEventType.HeroClick, HeroClick);
  95. }
  96. public void Shaking(float qiangDu)
  97. {
  98. if (StressReceiver != null)
  99. {
  100. isStartShake = true;
  101. StressReceiver.InduceStress(qiangDu, ShakeFinish);
  102. }
  103. }
  104. public void Shaking(CameraShakingSerializtion cameraShakingSerializtion)
  105. {
  106. Shaking(cameraShakingSerializtion.qiangDu);
  107. }
  108. }
  109. }