CombatCameraControllder.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using Common.Utility.CombatEvent;
  3. using Fort23.Core;
  4. using UnityEngine;
  5. using Utility.CustomizeTimeLogic.FxLogic.TimeLineEvent;
  6. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  7. namespace GameLogic.Combat.CombatTool
  8. {
  9. public class CombatCameraControllder : IDisposable, ICameraShaking
  10. {
  11. public Transform root;
  12. public Camera Camera;
  13. public CombatController combatController;
  14. public StressReceiver StressReceiver;
  15. private bool isStartShake;
  16. private int _followHeroId=-1;
  17. public void Init(CombatController combatController, Camera camera)
  18. {
  19. this.combatController = combatController;
  20. Camera = camera;
  21. root = Camera.transform.parent;
  22. StressReceiver = camera.transform.GetComponentInParent<StressReceiver>();
  23. TimeLineSingletonEventManager.Instance.AddTimeLineBasic(this);
  24. EventManager.Instance.AddEventListener(CustomEventType.HeroClick, HeroClick);
  25. // EventManager.Instance.AddEventListener(CustomEventType.HeroClick, HeroClick);
  26. }
  27. protected void HeroClick(IEventData eventData)
  28. {
  29. HeroClickEventData heroClickEventData = eventData as HeroClickEventData;
  30. int heroId = heroClickEventData.heroId;
  31. if (_followHeroId == heroId)
  32. {
  33. _followHeroId = -1;
  34. }
  35. else
  36. {
  37. _followHeroId = heroId;
  38. }
  39. }
  40. private void ShakeFinish()
  41. {
  42. isStartShake = false;
  43. }
  44. public void Update(float t)
  45. {
  46. if (!isStartShake)
  47. {
  48. CombatHeroEntity[] combatHeroEntities = combatController.CombatHeroController.GetHero(false);
  49. if (combatHeroEntities == null)
  50. {
  51. return;
  52. }
  53. Vector3 p = Vector3.zero;
  54. if (_followHeroId != -1)
  55. {
  56. for (int i = 0; i < combatHeroEntities.Length; i++)
  57. {
  58. if (combatHeroEntities[i].CurrCombatHeroInfo.modelID == _followHeroId)
  59. {
  60. p = combatHeroEntities[i].dotPos;
  61. break;
  62. }
  63. }
  64. }
  65. else
  66. {
  67. for (int i = 0; i < combatHeroEntities.Length; i++)
  68. {
  69. p += combatHeroEntities[i].dotPos;
  70. }
  71. p /= combatHeroEntities.Length;
  72. }
  73. // Vector3 tp = root.TransformVector(new Vector3(0, 0, -20));
  74. root.position = Vector3.Lerp(root.position, new Vector3(p.x, root.position.y, p.z + 13), 0.1f);
  75. }
  76. }
  77. public void Dispose()
  78. {
  79. EventManager.Instance.RemoveEventListener(CustomEventType.HeroClick, HeroClick);
  80. }
  81. public void Shaking(CameraShakingSerializtion cameraShakingSerializtion)
  82. {
  83. if (StressReceiver != null)
  84. {
  85. isStartShake = true;
  86. StressReceiver.InduceStress(cameraShakingSerializtion.qiangDu, ShakeFinish);
  87. }
  88. }
  89. }
  90. }