| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace UnityCommon
- {
- public class MotionlessState : CameraState
- {
- private Vector3 position;
- private Quaternion rotation;
- public MotionlessState(Camera camera, Vector3 p, Quaternion r) : base(camera)
- {
- position = p;
- rotation = r;
- }
- private float clipNearOld = 0.1f;
- public override void Enter()
- {
- base.Enter();
- m_camera.transform.SetParent(null);//保持父节点为空,解决相机漂移问题
- clipNearOld = m_camera.nearClipPlane;
- m_camera.nearClipPlane = 0.1f;
- SetCameraPosition(position, rotation, () =>
- {
- });
- }
- public override void Exit()
- {
- base.Exit();
- m_camera.nearClipPlane = clipNearOld;
- }
- private const float speedZoom = 0.5f;
- public override void OnZoom(float zoom)
- {
- base.OnZoom(zoom);
- m_camera.transform.Translate(0, 0, zoom * speedZoom);
- }
- }
- }
|