CombatCameraControllder.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // Vector3 tp = root.TransformVector(new Vector3(0, 0, -20));
  44. root.position = Vector3.Lerp(root.position, new Vector3(p.x, root.position.y, p.z+13), 0.1f);
  45. }
  46. }
  47. public void Dispose()
  48. {
  49. }
  50. public void Shaking(CameraShakingSerializtion cameraShakingSerializtion)
  51. {
  52. if (StressReceiver != null)
  53. {
  54. isStartShake = true;
  55. StressReceiver.InduceStress(cameraShakingSerializtion.qiangDu, ShakeFinish);
  56. }
  57. }
  58. }
  59. }