新输入系统
This commit is contained in:
@@ -1,122 +1,133 @@
|
||||
using System;
|
||||
using NBF;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityStandardAssets.Characters.FirstPerson
|
||||
{
|
||||
[Serializable]
|
||||
public class MouseLook
|
||||
{
|
||||
public float XSensitivity = 2f;
|
||||
[Serializable]
|
||||
public class MouseLook
|
||||
{
|
||||
public float XSensitivity = 2f;
|
||||
|
||||
public float YSensitivity = 2f;
|
||||
public float YSensitivity = 2f;
|
||||
|
||||
public bool clampVerticalRotation = true;
|
||||
public bool clampVerticalRotation = true;
|
||||
|
||||
public float MinimumX = -90f;
|
||||
public float MinimumX = -90f;
|
||||
|
||||
public float MaximumX = 90f;
|
||||
public float MaximumX = 90f;
|
||||
|
||||
public bool smooth;
|
||||
public bool smooth;
|
||||
|
||||
public float smoothTime = 5f;
|
||||
public float smoothTime = 5f;
|
||||
|
||||
public bool lockCursor = true;
|
||||
public bool lockCursor = true;
|
||||
|
||||
public float RotYvalue;
|
||||
public float RotYvalue;
|
||||
|
||||
public bool invertMouseY;
|
||||
public bool invertMouseY;
|
||||
|
||||
public bool invertMouseX;
|
||||
public bool invertMouseX;
|
||||
|
||||
public int ControllerHandMode;
|
||||
public int ControllerHandMode;
|
||||
|
||||
private Quaternion m_CharacterTargetRot;
|
||||
private Quaternion m_CharacterTargetRot;
|
||||
|
||||
private Quaternion m_CameraTargetRot;
|
||||
private Quaternion m_CameraTargetRot;
|
||||
|
||||
private bool m_cursorIsLocked = true;
|
||||
private bool m_cursorIsLocked = true;
|
||||
|
||||
// private Player player;
|
||||
// private Player player;
|
||||
|
||||
public void Init(Transform character, Transform camera)
|
||||
{
|
||||
m_CharacterTargetRot = character.localRotation;
|
||||
m_CameraTargetRot = camera.localRotation;
|
||||
// player = ReInput.players.GetPlayer(0);
|
||||
}
|
||||
public void Init(Transform character, Transform camera)
|
||||
{
|
||||
m_CharacterTargetRot = character.localRotation;
|
||||
m_CameraTargetRot = camera.localRotation;
|
||||
// player = ReInput.players.GetPlayer(0);
|
||||
}
|
||||
|
||||
public void LookRotation(Transform character, Transform camera)
|
||||
{
|
||||
// if (!SRDebug.Instance.IsDebugPanelVisible && !SRDebug.Instance.IsDebugPanelVisible)
|
||||
// {
|
||||
// float num = Mathf.Clamp(player.GetAxis("cameraVerticalGamepad") * YSensitivity * 50f * Time.deltaTime + player.GetAxis("cameraVertical") * YSensitivity * 5f * Time.deltaTime, -10f, 10f);
|
||||
// float num2 = Mathf.Clamp(player.GetAxis("cameraHorizontalGamepad") * XSensitivity * 50f * Time.deltaTime + player.GetAxis("cameraHorizontal") * XSensitivity * 5f * Time.deltaTime, -10f, 10f);
|
||||
// if (invertMouseY)
|
||||
// {
|
||||
// num *= -1f;
|
||||
// }
|
||||
// if (invertMouseX)
|
||||
// {
|
||||
// num2 *= -1f;
|
||||
// }
|
||||
// RotYvalue = num2;
|
||||
// m_CharacterTargetRot *= Quaternion.Euler(0f, num2, 0f);
|
||||
// m_CameraTargetRot *= Quaternion.Euler(0f - num, 0f, 0f);
|
||||
// if (clampVerticalRotation)
|
||||
// {
|
||||
// m_CameraTargetRot = ClampRotationAroundXAxis(m_CameraTargetRot);
|
||||
// }
|
||||
// if (smooth)
|
||||
// {
|
||||
// character.localRotation = Quaternion.Slerp(character.localRotation, m_CharacterTargetRot, smoothTime * Time.deltaTime);
|
||||
// camera.localRotation = Quaternion.Slerp(camera.localRotation, m_CameraTargetRot, smoothTime * Time.deltaTime);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// character.localRotation = m_CharacterTargetRot;
|
||||
// camera.localRotation = m_CameraTargetRot;
|
||||
// }
|
||||
// UpdateCursorLock();
|
||||
// }
|
||||
}
|
||||
public void LookRotation(Transform character, Transform camera)
|
||||
{
|
||||
// if (!SRDebug.Instance.IsDebugPanelVisible && !SRDebug.Instance.IsDebugPanelVisible)
|
||||
{
|
||||
var lookInput = InputManager.GetLookInput();
|
||||
|
||||
public void SetCursorLock(bool value)
|
||||
{
|
||||
lockCursor = value;
|
||||
if (!lockCursor)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
}
|
||||
float num = Mathf.Clamp(lookInput.y * YSensitivity * 5f * Time.deltaTime, -10f, 10f);
|
||||
float num2 =
|
||||
Mathf.Clamp(lookInput.x * XSensitivity * 5f * Time.deltaTime, -10f, 10f);
|
||||
|
||||
public void UpdateCursorLock()
|
||||
{
|
||||
if (lockCursor)
|
||||
{
|
||||
InternalLockUpdate();
|
||||
}
|
||||
}
|
||||
if (invertMouseY)
|
||||
{
|
||||
num *= -1f;
|
||||
}
|
||||
|
||||
private void InternalLockUpdate()
|
||||
{
|
||||
}
|
||||
if (invertMouseX)
|
||||
{
|
||||
num2 *= -1f;
|
||||
}
|
||||
|
||||
private Quaternion ClampRotationAroundXAxis(Quaternion q)
|
||||
{
|
||||
q.x /= q.w;
|
||||
q.y /= q.w;
|
||||
q.z /= q.w;
|
||||
q.w = 1f;
|
||||
float value = 114.59156f * Mathf.Atan(q.x);
|
||||
value = Mathf.Clamp(value, MinimumX, MaximumX);
|
||||
q.x = Mathf.Tan((float)Math.PI / 360f * value);
|
||||
return q;
|
||||
}
|
||||
}
|
||||
}
|
||||
RotYvalue = num2;
|
||||
m_CharacterTargetRot *= Quaternion.Euler(0f, num2, 0f);
|
||||
m_CameraTargetRot *= Quaternion.Euler(0f - num, 0f, 0f);
|
||||
if (clampVerticalRotation)
|
||||
{
|
||||
m_CameraTargetRot = ClampRotationAroundXAxis(m_CameraTargetRot);
|
||||
}
|
||||
|
||||
if (smooth)
|
||||
{
|
||||
character.localRotation = Quaternion.Slerp(character.localRotation, m_CharacterTargetRot,
|
||||
smoothTime * Time.deltaTime);
|
||||
camera.localRotation = Quaternion.Slerp(camera.localRotation, m_CameraTargetRot,
|
||||
smoothTime * Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
character.localRotation = m_CharacterTargetRot;
|
||||
camera.localRotation = m_CameraTargetRot;
|
||||
}
|
||||
|
||||
UpdateCursorLock();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCursorLock(bool value)
|
||||
{
|
||||
lockCursor = value;
|
||||
if (!lockCursor)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateCursorLock()
|
||||
{
|
||||
if (lockCursor)
|
||||
{
|
||||
InternalLockUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void InternalLockUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
private Quaternion ClampRotationAroundXAxis(Quaternion q)
|
||||
{
|
||||
q.x /= q.w;
|
||||
q.y /= q.w;
|
||||
q.z /= q.w;
|
||||
q.w = 1f;
|
||||
float value = 114.59156f * Mathf.Atan(q.x);
|
||||
value = Mathf.Clamp(value, MinimumX, MaximumX);
|
||||
q.x = Mathf.Tan((float)Math.PI / 360f * value);
|
||||
return q;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user