CombatCameraControllder.cs 4.2 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||combatHeroEntities.Length<=0)
  58. {
  59. return;
  60. }
  61. Vector3 p = combatHeroEntities[0].dotPos;
  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. //
  76. // if (!isHero)
  77. // {
  78. // int c = 0;
  79. // for (int i = 0; i < combatHeroEntities.Length; i++)
  80. // {
  81. // if (!combatHeroEntities[i].isDie)
  82. // {
  83. // c++;
  84. // p += combatHeroEntities[i].dotPos;
  85. // }
  86. // }
  87. //
  88. // if (c <= 0)
  89. // {
  90. // return;
  91. // }
  92. //
  93. // p /= c;
  94. // }
  95. MainLight.transform.position = new Vector3(p.x, 5.6f, p.z);
  96. // Vector3 tp = root.TransformVector(new Vector3(0, 0, -20));
  97. root.position = Vector3.Lerp(root.position, new Vector3(p.x, root.position.y, p.z + 13), 0.05f);
  98. }
  99. }
  100. public void Dispose()
  101. {
  102. EventManager.Instance.RemoveEventListener(CustomEventType.HeroClick, HeroClick);
  103. }
  104. public void Shaking(float qiangDu)
  105. {
  106. if (StressReceiver != null)
  107. {
  108. isStartShake = true;
  109. StressReceiver.InduceStress(qiangDu, ShakeFinish);
  110. }
  111. }
  112. public void Shaking(CameraShakingSerializtion cameraShakingSerializtion)
  113. {
  114. Shaking(cameraShakingSerializtion.qiangDu);
  115. }
  116. }
  117. }