85 lines
2.9 KiB
C#
85 lines
2.9 KiB
C#
using BigSpace.Logic;
|
|
using BigSpace.XRCore.Event;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CameraMove : MonoBehaviour
|
|
{
|
|
public GameObject picoHandMove;
|
|
|
|
private Transform cameraPos;
|
|
[Tooltip("移动速度")]
|
|
[SerializeField] private float moveSpeed = 5f;
|
|
[Tooltip("视角转动速度")]
|
|
[SerializeField] private float rotationSpeed = -20.0f;
|
|
private Vector2 mouseDownPosition;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
cameraPos = GameObject.Find("XROriginHands").transform; //GameObject.Find("XROriginHands/Camera Offset/Main Camera").transform;
|
|
GlobalEventMgr.Listen<int>(GameEvent.EventSetHandMove, GameDataManage_EventSetHandMove);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
// 根据ASWD键控制物体移动
|
|
if (Input.GetKey(KeyCode.A))
|
|
{
|
|
cameraPos.Translate(Vector3.left * moveSpeed * Time.deltaTime);
|
|
/*OriginInfoManager.Instance.OrginState = isStandUp ? EnPlayerState.Walk : EnPlayerState.KAway;*/
|
|
}
|
|
else if (Input.GetKey(KeyCode.D))
|
|
{
|
|
cameraPos.Translate(Vector3.right * moveSpeed * Time.deltaTime);
|
|
|
|
}
|
|
|
|
if (Input.GetKey(KeyCode.S))
|
|
{
|
|
cameraPos.Translate(Vector3.back * moveSpeed * Time.deltaTime);
|
|
cameraPos.localPosition = new Vector3(cameraPos.localPosition.x, 0, cameraPos.localPosition.z);
|
|
}
|
|
else if (Input.GetKey(KeyCode.W))
|
|
{
|
|
cameraPos.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
|
|
cameraPos.localPosition = new Vector3(cameraPos.localPosition.x, 0, cameraPos.localPosition.z);
|
|
}
|
|
// 按住鼠标邮件拖动game试图旋转相机
|
|
if (Input.GetMouseButtonDown(1))
|
|
{
|
|
mouseDownPosition = Input.mousePosition;
|
|
}
|
|
if (Input.GetMouseButton(1))
|
|
{
|
|
Vector2 mouseDelta = (Vector2)Input.mousePosition - mouseDownPosition;
|
|
|
|
cameraPos.Rotate(Vector3.up, (mouseDelta.x / -rotationSpeed * 5), Space.Self);
|
|
|
|
cameraPos.Rotate(Vector3.right, (mouseDelta.y / rotationSpeed * 5), Space.Self);
|
|
//cameraPos.rotation = Quaternion.Slerp(transform.rotation, origiRota, LookSpeep * Time.deltaTime);
|
|
cameraPos.rotation = Quaternion.Euler(cameraPos.rotation.eulerAngles.x, cameraPos.rotation.eulerAngles.y, 0);
|
|
mouseDownPosition = (Vector2)Input.mousePosition;
|
|
}
|
|
if (Input.GetMouseButtonUp(1))
|
|
{
|
|
mouseDownPosition = Vector2.zero;
|
|
}
|
|
}
|
|
|
|
void GameDataManage_EventSetHandMove(int index)
|
|
{
|
|
//Debug.Log("是否显示啊:" + index);
|
|
if (index == 2)
|
|
{
|
|
picoHandMove.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
picoHandMove.SetActive(false);
|
|
}
|
|
}
|
|
}
|