CombatCameraControllder.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. public void Init(CombatController combatController, Camera camera)
  17. {
  18. this.combatController = combatController;
  19. Camera = camera;
  20. root = Camera.transform.parent;
  21. StressReceiver = camera.transform.GetComponentInParent<StressReceiver>();
  22. TimeLineSingletonEventManager.Instance.AddTimeLineBasic(this);
  23. }
  24. private void ShakeFinish()
  25. {
  26. isStartShake = false;
  27. }
  28. public void Update(float t)
  29. {
  30. if (!isStartShake)
  31. {
  32. CombatHeroEntity[] combatHeroEntities = combatController.CombatHeroController.GetHero(false);
  33. if (combatHeroEntities == null)
  34. {
  35. return;
  36. }
  37. Vector3 p = Vector3.zero;
  38. for (int i = 0; i < combatHeroEntities.Length; i++)
  39. {
  40. p += combatHeroEntities[i].dotPos;
  41. }
  42. p /= combatHeroEntities.Length;
  43. root.position = Vector3.Lerp(root.position, new Vector3(p.x, root.position.y, p.z - 7), 0.3f);
  44. }
  45. }
  46. public void Dispose()
  47. {
  48. }
  49. public void Shaking(CameraShakingSerializtion cameraShakingSerializtion)
  50. {
  51. if (StressReceiver != null)
  52. {
  53. isStartShake = true;
  54. StressReceiver.InduceStress(cameraShakingSerializtion.qiangDu, ShakeFinish);
  55. }
  56. }
  57. }
  58. }