CombatCameraControllder.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. public void Init(CombatController combatController, Camera camera)
  24. {
  25. this.combatController = combatController;
  26. Camera = camera;
  27. root = Camera.transform.parent;
  28. StressReceiver = camera.transform.GetComponentInParent<StressReceiver>();
  29. TimeLineSingletonEventManager.Instance.AddTimeLineBasic(this);
  30. EventManager.Instance.AddEventListener(CustomEventType.HeroClick, HeroClick);
  31. // EventManager.Instance.AddEventListener(CustomEventType.HeroClick, HeroClick);
  32. }
  33. protected void HeroClick(IEventData eventData)
  34. {
  35. HeroClickEventData heroClickEventData = eventData as HeroClickEventData;
  36. int heroId = heroClickEventData.heroId;
  37. if (_followHeroId == heroId)
  38. {
  39. _followHeroId = -1;
  40. }
  41. else
  42. {
  43. _followHeroId = heroId;
  44. }
  45. }
  46. private void ShakeFinish()
  47. {
  48. isStartShake = false;
  49. }
  50. public void Update(float t)
  51. {
  52. if (!isStartShake && !isStop)
  53. {
  54. CombatHeroEntity combatHeroEntities = combatController.CombatHeroController.playerHeroEntity;
  55. if (combatHeroEntities == null)
  56. {
  57. return;
  58. }
  59. Vector3 p = combatHeroEntities.GameObject.transform.TransformPoint(new Vector3(0, 8, -10));
  60. root.rotation = Quaternion.Lerp(root.rotation, combatHeroEntities.GameObject.transform.rotation,
  61. 1);
  62. root.position = Vector3.Lerp(root.position, p, 1);
  63. }
  64. }
  65. public void SetPos(Transform target)
  66. {
  67. Vector3 p = target.TransformPoint(new Vector3(0, 8, -10));
  68. root.rotation = Quaternion.Lerp(root.rotation, target.rotation,
  69. 1);
  70. root.position = Vector3.Lerp(root.position, p, 1);
  71. }
  72. public void Dispose()
  73. {
  74. EventManager.Instance.RemoveEventListener(CustomEventType.HeroClick, HeroClick);
  75. }
  76. public void Shaking(float qiangDu)
  77. {
  78. if (StressReceiver != null)
  79. {
  80. isStartShake = true;
  81. StressReceiver.InduceStress(qiangDu, ShakeFinish);
  82. }
  83. }
  84. public void Shaking(CameraShakingSerializtion cameraShakingSerializtion)
  85. {
  86. Shaking(cameraShakingSerializtion.qiangDu);
  87. }
  88. }
  89. }