123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using DG.Tweening;
- using ET.EventType;
- using UnityEngine;
- namespace ET.Client
- {
- [FriendOfAttribute(typeof(ET.Client.GlobalViewComponent))]
- public static class CameraMgr
- {
- public static void Init()
- {
- var camera = GlobalViewComponent.Instance.BattleCamera;
- camera.transform.position = new Vector3(30, 45, -60);
- camera.fieldOfView = 70;
- }
- //相机跟随主角
- public static void FollowMe(Vector3 pos)
- {
- /*var camera = Camera.main;
- pos.x += 7;
- pos.y = 15;
- pos.z -= 25;
- camera.transform.position = pos;*/
- }
- private static bool bShaking = false;
- public static void ShakeMe(float shakeTime, Vector3 shakeStength)
- {
- if (bShaking) return;
- bShaking = true;
- Transform trans = GlobalViewComponent.Instance.BattleCamera.transform;
- Tweener tweener = trans.DOShakePosition(shakeTime, shakeStength);
- tweener.OnComplete<Tweener>(() =>
- {
- trans.localPosition = Vector3.zero;
- bShaking = false;
- });
- }
- public static Vector3 CarmeraPos()
- {
- return Camera.main.transform.position;
- }
- public static void DragMe(Vector3 start, Vector3 end, float duration, System.Action endcb)
- {
- Transform trans = GlobalViewComponent.Instance.BattleCamera.transform;
- trans.position = start;
- var tweener = trans.DOMove(end, duration);
- tweener.OnComplete<Tweener>(() =>
- {
- endcb ?.Invoke();
- });
- }
- }
- [Event(SceneType.None)]
- [FriendOfAttribute(typeof(ET.Client.GlobalViewComponent))]
- public class CameraEventHandler : BEvent<EventType.CameraEvent>
- {
- public override void OnEvent(CameraEvent args)
- {
- var endpos = new Vector3(args.X, args.Y, args.Z);
- float time = (float)args.TimeMS / 1000;
- Transform trans = GlobalViewComponent.Instance.BattleCamera.transform;
- if (args.MoveSpeedSec > 0.0001 && time < 0.01)
- {
- var dis = Vector3.Distance(trans.position, endpos);
- time = dis / args.MoveSpeedSec;
- }
- trans.DOMove(endpos, time);
- }
- }
- }
|