CombatCameraControllder.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 bool isStop;
  23. private bool isUpdateCameraToPath;
  24. private float currValue;
  25. private float _cameraSelectValue;
  26. private float targetValue;
  27. private float _currTime;
  28. public void Init(CombatController combatController, Camera camera)
  29. {
  30. CombatEventManager.Instance.AddEventListener(CombatEventType.SencenBesselPathAlter, SencenBesselPathAlter);
  31. this.combatController = combatController;
  32. Camera = camera;
  33. root = Camera.transform.parent;
  34. StressReceiver = camera.transform.GetComponentInParent<StressReceiver>();
  35. TimeLineSingletonEventManager.Instance.AddTimeLineBasic(this);
  36. EventManager.Instance.AddEventListener(CustomEventType.HeroClick, HeroClick);
  37. CameraSelect_onValueChanged(0.7f);
  38. // EventManager.Instance.AddEventListener(CustomEventType.HeroClick, HeroClick);
  39. }
  40. private void SencenBesselPathAlter(IEventData eventData)
  41. {
  42. isUpdateCameraToPath = true;
  43. currValue = _cameraSelectValue;
  44. if (CombatController.currActiveCombat.CombatSenceController.currBesselPath.isCentre)
  45. {
  46. targetValue = 0.5f;
  47. }
  48. else
  49. {
  50. targetValue = 0.7f;
  51. }
  52. _currTime = 0;
  53. }
  54. protected void HeroClick(IEventData eventData)
  55. {
  56. HeroClickEventData heroClickEventData = eventData as HeroClickEventData;
  57. int heroId = heroClickEventData.heroId;
  58. if (_followHeroId == heroId)
  59. {
  60. _followHeroId = -1;
  61. }
  62. else
  63. {
  64. _followHeroId = heroId;
  65. }
  66. }
  67. public void CameraSelect_onValueChanged(float value)
  68. {
  69. _cameraSelectValue = value;
  70. Vector3 pos1 = new Vector3(0, -2, -0.7f);
  71. Vector3 e1 = new Vector3(20, 0, 0);
  72. Vector3 pos2 = new Vector3(9, 0.7f, -1.4f);
  73. Vector3 e2 = new Vector3(17.77f, -28.25f, 1.165f);
  74. Camera.transform.localPosition =
  75. Vector3.Lerp(pos1, pos2, value);
  76. Camera.transform.localEulerAngles =
  77. Vector3.Lerp(e1, e2, value);
  78. }
  79. private void ShakeFinish()
  80. {
  81. isStartShake = false;
  82. }
  83. public void Update(float t)
  84. {
  85. // if (isUpdateCameraToPath)
  86. // {
  87. // _currTime += t;
  88. // CameraSelect_onValueChanged(Mathf.Lerp(currValue, targetValue, _currTime));
  89. // if (_currTime > 1)
  90. // {
  91. // isUpdateCameraToPath = false;
  92. // }
  93. // }
  94. if (!isStartShake && !isStop)
  95. {
  96. CombatHeroEntity combatHeroEntities = combatController.CombatHeroController.playerHeroEntity;
  97. if (combatHeroEntities == null)
  98. {
  99. return;
  100. }
  101. Vector3 p = combatHeroEntities.GameObject.transform.TransformPoint(new Vector3(0, 8, -10));
  102. root.rotation = Quaternion.Lerp(root.rotation, combatHeroEntities.GameObject.transform.rotation,
  103. 1);
  104. root.position = Vector3.Lerp(root.position, p, 1);
  105. }
  106. }
  107. public void SetPos(Transform target)
  108. {
  109. Vector3 p = target.TransformPoint(new Vector3(0, 8, -10));
  110. root.rotation = Quaternion.Lerp(root.rotation, target.rotation,
  111. 1);
  112. root.position = Vector3.Lerp(root.position, p, 1);
  113. }
  114. public void Dispose()
  115. {
  116. EventManager.Instance.RemoveEventListener(CustomEventType.HeroClick, HeroClick);
  117. }
  118. public void Shaking(float qiangDu)
  119. {
  120. if (StressReceiver != null)
  121. {
  122. isStartShake = true;
  123. StressReceiver.InduceStress(qiangDu, ShakeFinish);
  124. }
  125. }
  126. public void Shaking(CameraShakingSerializtion cameraShakingSerializtion)
  127. {
  128. Shaking(cameraShakingSerializtion.qiangDu);
  129. }
  130. }
  131. }