CameraMgr.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using DG.Tweening;
  2. using ET.EventType;
  3. using UnityEngine;
  4. namespace ET.Client
  5. {
  6. [FriendOfAttribute(typeof(ET.Client.GlobalViewComponent))]
  7. public static class CameraMgr
  8. {
  9. public static void Init()
  10. {
  11. var camera = GlobalViewComponent.Instance.BattleCamera;
  12. camera.transform.position = new Vector3(30, 45, -60);
  13. camera.fieldOfView = 70;
  14. }
  15. //相机跟随主角
  16. public static void FollowMe(Vector3 pos)
  17. {
  18. /*var camera = Camera.main;
  19. pos.x += 7;
  20. pos.y = 15;
  21. pos.z -= 25;
  22. camera.transform.position = pos;*/
  23. }
  24. private static bool bShaking = false;
  25. public static void ShakeMe(float shakeTime, Vector3 shakeStength)
  26. {
  27. if (bShaking) return;
  28. bShaking = true;
  29. Transform trans = GlobalViewComponent.Instance.BattleCamera.transform;
  30. Tweener tweener = trans.DOShakePosition(shakeTime, shakeStength);
  31. tweener.OnComplete<Tweener>(() =>
  32. {
  33. trans.localPosition = Vector3.zero;
  34. bShaking = false;
  35. });
  36. }
  37. public static Vector3 CarmeraPos()
  38. {
  39. return Camera.main.transform.position;
  40. }
  41. public static void DragMe(Vector3 start, Vector3 end, float duration, System.Action endcb)
  42. {
  43. Transform trans = GlobalViewComponent.Instance.BattleCamera.transform;
  44. trans.position = start;
  45. var tweener = trans.DOMove(end, duration);
  46. tweener.OnComplete<Tweener>(() =>
  47. {
  48. endcb ?.Invoke();
  49. });
  50. }
  51. }
  52. [Event(SceneType.None)]
  53. [FriendOfAttribute(typeof(ET.Client.GlobalViewComponent))]
  54. public class CameraEventHandler : BEvent<EventType.CameraEvent>
  55. {
  56. public override void OnEvent(CameraEvent args)
  57. {
  58. var endpos = new Vector3(args.X, args.Y, args.Z);
  59. float time = (float)args.TimeMS / 1000;
  60. Transform trans = GlobalViewComponent.Instance.BattleCamera.transform;
  61. if (args.MoveSpeedSec > 0.0001 && time < 0.01)
  62. {
  63. var dis = Vector3.Distance(trans.position, endpos);
  64. time = dis / args.MoveSpeedSec;
  65. }
  66. trans.DOMove(endpos, time);
  67. }
  68. }
  69. }