CombatCameraControllder.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. if (_followHeroId != -1)
  56. {
  57. for (int i = 0; i < combatHeroEntities.Length; i++)
  58. {
  59. if (combatHeroEntities[i].CurrCombatHeroInfo.modelID == _followHeroId)
  60. {
  61. p = combatHeroEntities[i].dotPos;
  62. break;
  63. }
  64. }
  65. }
  66. else
  67. {
  68. for (int i = 0; i < combatHeroEntities.Length; i++)
  69. {
  70. p += combatHeroEntities[i].dotPos;
  71. }
  72. p /= combatHeroEntities.Length;
  73. }
  74. // Vector3 tp = root.TransformVector(new Vector3(0, 0, -20));
  75. root.position = Vector3.Lerp(root.position, new Vector3(p.x, root.position.y, p.z + 13), 0.1f);
  76. }
  77. }
  78. public void Dispose()
  79. {
  80. EventManager.Instance.RemoveEventListener(CustomEventType.HeroClick, HeroClick);
  81. }
  82. public void Shaking(float qiangDu)
  83. {
  84. if (StressReceiver != null)
  85. {
  86. isStartShake = true;
  87. StressReceiver.InduceStress(qiangDu, ShakeFinish);
  88. }
  89. }
  90. public void Shaking(CameraShakingSerializtion cameraShakingSerializtion)
  91. {
  92. Shaking(cameraShakingSerializtion.qiangDu);
  93. }
  94. }
  95. }