CombatCameraControllder.cs 3.5 KB

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