CombatCameraControllder.cs 4.1 KB

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