CombatCameraControllder.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.followTarget;
  57. if (combatHeroEntities == null)
  58. {
  59. return;
  60. }
  61. if (combatHeroEntities.isDie)
  62. {
  63. CombatHeroEntity[] allHero= combatController.CombatHeroController.GetHero(false);
  64. if (allHero != null&& allHero.Length > 0)
  65. {
  66. combatHeroEntities= allHero[0];
  67. }
  68. }
  69. Vector3 p = combatHeroEntities.dotPos;
  70. // bool isHero = false;
  71. // if (_followHeroId != -1)
  72. // {
  73. // for (int i = 0; i < combatHeroEntities.Length; i++)
  74. // {
  75. // if (combatHeroEntities[i].CurrCombatHeroInfo.modelID == _followHeroId)
  76. // {
  77. // p = combatHeroEntities[i].dotPos;
  78. // isHero = true;
  79. // break;
  80. // }
  81. // }
  82. // }
  83. //
  84. // if (!isHero)
  85. // {
  86. // int c = 0;
  87. // for (int i = 0; i < combatHeroEntities.Length; i++)
  88. // {
  89. // if (!combatHeroEntities[i].isDie)
  90. // {
  91. // c++;
  92. // p += combatHeroEntities[i].dotPos;
  93. // }
  94. // }
  95. //
  96. // if (c <= 0)
  97. // {
  98. // return;
  99. // }
  100. //
  101. // p /= c;
  102. // }
  103. MainLight.transform.position = new Vector3(p.x, 5.6f, p.z);
  104. // Vector3 tp = root.TransformVector(new Vector3(0, 0, -20));
  105. root.position = Vector3.Lerp(root.position, new Vector3(p.x, root.position.y, p.z + 13), 0.05f);
  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. }