95 lines
2.8 KiB
C#
95 lines
2.8 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using Pico.Platform.Models;
|
||
using UnityEngine;
|
||
|
||
public class MRCamera : MonoBehaviour
|
||
{
|
||
// ARCameraManager arCameraManager;
|
||
// // 示例代码,获取深度信息
|
||
// void OnEnable()
|
||
// {
|
||
// arCameraManager = GetComponent<ARCameraManager>();
|
||
// arCameraManager.frameReceived += OnFrameReceived;
|
||
// }
|
||
|
||
// void OnDisable()
|
||
// {
|
||
// ARCameraManager arCameraManager = GetComponent<ARCameraManager>();
|
||
// arCameraManager.frameReceived -= OnFrameReceived;
|
||
// }
|
||
|
||
// void OnFrameReceived(ARCameraFrameEventArgs eventArgs)
|
||
// {
|
||
// // ARFrame frame = eventArgs.lightEstimation.mainLightColor;
|
||
// // if (frame.TryGetUpdatedDepth(out XRDepthSubsystem depthSubsystem))
|
||
// // {
|
||
// // 获取深度图
|
||
// // Texture2D depthTexture = frame.GetUpdatedDepthTexture();
|
||
// // 在这里使用深度图进行处理
|
||
// // }
|
||
|
||
// // Debug.Log("frame receive");
|
||
// // if (eventArgs .TryGetLatestFrame(out XRCameraFrame frame))
|
||
// // {
|
||
// // }
|
||
// }
|
||
|
||
private float xRotation;
|
||
private float yRotation;
|
||
public int yRotationMinLimit = -20;
|
||
public int yRotationMaxLimit = 80;
|
||
private float xRotationSpeed = 100;
|
||
private float yRotationSpeed = 100;
|
||
|
||
|
||
void Update()
|
||
{
|
||
CameraRotation();
|
||
CameraMove();
|
||
}
|
||
|
||
float ClampValue(float value, float min, float max)//控制旋转的角度
|
||
{
|
||
if (value < -360)
|
||
value += 360;
|
||
if (value > 360)
|
||
value -= 360;
|
||
return Mathf.Clamp(value, min, max);//限制value的值在min和max之间, 如果value小于min,返回min。 如果value大于max,返回max,否则返回value
|
||
}
|
||
|
||
void CameraRotation()
|
||
{
|
||
float _MouseX = Input.GetAxis("Mouse X");
|
||
float _MouseY = Input.GetAxis("Mouse Y");
|
||
if (Input.GetMouseButton(1))
|
||
{
|
||
xRotation -= _MouseX * xRotationSpeed * 0.02f;
|
||
yRotation += _MouseY * yRotationSpeed * 0.02f;
|
||
yRotation = ClampValue(yRotation, yRotationMinLimit, yRotationMaxLimit);
|
||
Quaternion rotation = Quaternion.Euler(-yRotation, -xRotation, 0);
|
||
transform.rotation = rotation;
|
||
}
|
||
}
|
||
|
||
void CameraMove()
|
||
{
|
||
if (Input.GetKey(KeyCode.W))
|
||
{
|
||
transform.Translate(new Vector3(0, 0, 0.05f));
|
||
}
|
||
if (Input.GetKey(KeyCode.A))
|
||
{
|
||
transform.Translate(new Vector3(-0.05f, 0, 0));
|
||
}
|
||
if (Input.GetKey(KeyCode.S))
|
||
{
|
||
transform.Translate(new Vector3(0, 0, -0.05f));
|
||
}
|
||
if (Input.GetKey(KeyCode.D))
|
||
{
|
||
transform.Translate(new Vector3(0.05f, 0, 0));
|
||
}
|
||
}
|
||
}
|