修改相机移动方式,修改场景1,场景2音频大小,修改键盘提示,去掉QE键

This commit is contained in:
马铖荣 2025-07-02 14:15:36 +08:00
parent 15b49821b6
commit c323f9686d
6 changed files with 40 additions and 78 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 66 KiB

View File

@ -3088,7 +3088,7 @@ AudioSource:
OutputAudioMixerGroup: {fileID: 0} OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: c967447a8f88ed14481d7ada52d149c4, type: 3} m_audioClip: {fileID: 8300000, guid: c967447a8f88ed14481d7ada52d149c4, type: 3}
m_PlayOnAwake: 1 m_PlayOnAwake: 1
m_Volume: 1 m_Volume: 0.5
m_Pitch: 1 m_Pitch: 1
Loop: 1 Loop: 1
Mute: 0 Mute: 0

View File

@ -28405,7 +28405,7 @@ AudioSource:
OutputAudioMixerGroup: {fileID: 0} OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: c967447a8f88ed14481d7ada52d149c4, type: 3} m_audioClip: {fileID: 8300000, guid: c967447a8f88ed14481d7ada52d149c4, type: 3}
m_PlayOnAwake: 1 m_PlayOnAwake: 1
m_Volume: 0.8 m_Volume: 0.5
m_Pitch: 1 m_Pitch: 1
Loop: 1 Loop: 1
Mute: 0 Mute: 0

View File

@ -4,17 +4,13 @@ public class FreeCameraController : MonoBehaviour
{ {
public static FreeCameraController instance; public static FreeCameraController instance;
// 相机移动速度 // 相机移动速度
public float moveSpeed = 5.0f; // 降低了移动速度 public float moveSpeed = 5.0f;
// 相机旋转速度 // 相机旋转速度
public float rotateSpeed = 0.05f; // 降低了旋转速度 public float rotateSpeed = 0.05f;
// X轴旋转的最大范围 // X轴旋转的最大范围
public float xRotationLimit = 80.0f; public float xRotationLimit = 80.0f;
// Y轴旋转的最大范围
//public float yRotationLimit = 180.0f;
//public float minRotationLimitY = -1;
//public float maxRotationLimitY = -1;
// 是否启用碰撞检测 // 是否启用碰撞检测
public bool enableCollision = false; // 默认关闭碰撞检测,根据需要开启 public bool enableCollision = false;
private Vector3 lastMousePosition; private Vector3 lastMousePosition;
private bool isDragging = false; private bool isDragging = false;
@ -23,36 +19,14 @@ public class FreeCameraController : MonoBehaviour
public bool isMov = true; public bool isMov = true;
public bool isRot = true; public bool isRot = true;
CharacterController ctrlor; CharacterController ctrlor;
private void Awake() private void Awake()
{ {
instance = this; instance = this;
DontDestroyOnLoad(this); DontDestroyOnLoad(this);
// Cm = GameObject.Find("Mcam");
ctrlor = GetComponent<CharacterController>(); ctrlor = GetComponent<CharacterController>();
Global.appSetting.MouseMoveSpeed.RegisterWithInitValue(v => rotateSpeed = v); Global.appSetting.MouseMoveSpeed.RegisterWithInitValue(v => rotateSpeed = v);
} }
/// <summary>
/// 添加相机QE上下移动功能
/// </summary>
/// <returns></returns>
Vector3 GetInputTranslationDirection()
{
Vector3 direction = new Vector3();
if (Input.GetKey(KeyCode.Q))
{
direction += Vector3.up;
}
if (Input.GetKey(KeyCode.E))
{
direction += Vector3.down;
}
return direction;
}
void Update() void Update()
{ {
@ -68,48 +42,45 @@ public class FreeCameraController : MonoBehaviour
transform.position += move; transform.position += move;
#else #else
//W键前进 // 获取水平面内的前后左右移动方向
Vector3 moveDirection = Vector3.zero;
//W键前进水平面内
if (Input.GetKey(KeyCode.W)) if (Input.GetKey(KeyCode.W))
{ {
Vector3 forward = transform.TransformDirection(Vector3.forward); Vector3 forward = Vector3.ProjectOnPlane(transform.forward, Vector3.up).normalized;
ctrlor.Move(forward * moveSpeed * Time.deltaTime); moveDirection += forward;
} }
//S键后退
//S键后退水平面内
if (Input.GetKey(KeyCode.S)) if (Input.GetKey(KeyCode.S))
{ {
Vector3 back = transform.TransformDirection(Vector3.back); Vector3 back = -Vector3.ProjectOnPlane(transform.forward, Vector3.up).normalized;
ctrlor.Move(back * moveSpeed * Time.deltaTime); moveDirection += back;
} }
//A键移动
//A键左移水平面内
if (Input.GetKey(KeyCode.A)) if (Input.GetKey(KeyCode.A))
{ {
Vector3 left = transform.TransformDirection(Vector3.left); Vector3 left = -Vector3.ProjectOnPlane(transform.right, Vector3.up).normalized;
ctrlor.Move(left * moveSpeed * Time.deltaTime); moveDirection += left;
} }
//D键后退
if (Input.GetKey(KeyCode.D) && gameObject.transform.position.y > 0) //D键右移水平面内
if (Input.GetKey(KeyCode.D))
{ {
Vector3 right = transform.TransformDirection(Vector3.right); Vector3 right = Vector3.ProjectOnPlane(transform.right, Vector3.up).normalized;
ctrlor.Move(right * moveSpeed * Time.deltaTime); moveDirection += right;
} }
//E键升高
if (Input.GetKey(KeyCode.Q)) // 应用移动
if (moveDirection != Vector3.zero)
{ {
Vector3 upward = transform.TransformDirection(Vector3.up); ctrlor.Move(moveDirection * moveSpeed * Time.deltaTime);
ctrlor.Move(upward * moveSpeed * Time.deltaTime);
} }
//E键升高
if (Input.GetKey(KeyCode.E))
{
Vector3 down = transform.TransformDirection(Vector3.down);
ctrlor.Move(down * moveSpeed * Time.deltaTime);
}
////添加相机QE上下移动功能
//transform.position+= GetInputTranslationDirection()*0.01f;
#endif #endif
} }
if (isRot) if (isRot)
{ {
if (Input.GetMouseButtonDown(1)) if (Input.GetMouseButtonDown(1))
@ -119,32 +90,23 @@ public class FreeCameraController : MonoBehaviour
SyncRotation(); SyncRotation();
} }
if (Input.GetMouseButtonUp(1)) if (Input.GetMouseButtonUp(1))
{ {
isDragging = false; isDragging = false;
} }
if (isDragging) if (isDragging)
{ {
// 相机旋转 // 相机旋转
Vector3 mouseDelta = Input.mousePosition - lastMousePosition;
Vector3 mouseDelta = Input.mousePosition - lastMousePosition; // 反转了鼠标差值
lastMousePosition = Input.mousePosition; lastMousePosition = Input.mousePosition;
xRotation -= mouseDelta.y * rotateSpeed; // 反转了X轴旋转方向 xRotation -= mouseDelta.y * rotateSpeed;
yRotation += mouseDelta.x * rotateSpeed; yRotation += mouseDelta.x * rotateSpeed;
// 限制 X 轴旋转范围 // 限制 X 轴旋转范围
xRotation = Mathf.Clamp(xRotation, -xRotationLimit, xRotationLimit); xRotation = Mathf.Clamp(xRotation, -xRotationLimit, xRotationLimit);
// 限制 Y 轴旋转范围
//if (minRotationLimitY != -1 && maxRotationLimitY != -1)
//{
// yRotation = Mathf.Clamp(yRotation, minRotationLimitY, maxRotationLimitY);
//}
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0); transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
} }
} }
@ -158,9 +120,9 @@ public class FreeCameraController : MonoBehaviour
SyncRotation(); SyncRotation();
} }
public void Rotate(Vector3 eulerAngels) public void Rotate(Vector3 eulerAngles)
{ {
transform.eulerAngles = eulerAngels; transform.eulerAngles = eulerAngles;
SyncRotation(); SyncRotation();
} }

View File

@ -213,9 +213,9 @@
<Action type="Parallel"> <Action type="Parallel">
<Action type="Move" value="FlyCamera" to="-5.530235,1.408061,5.152232" time="0"></Action> <Action type="Move" value="FlyCamera" to="-3.514123,0.7293322,0.5859525" time="0"></Action>
<Action type="Rotate" value="FlyCamera" to="6.030264,129.4993,-2.146311E-07" time="0"></Action> <Action type="Rotate" value="FlyCamera" to="9.980267,90.39926,0" time="0"></Action>
</Action> </Action>
<Action type="UIShow" value="UITextWindow" isShow="false"></Action> <Action type="UIShow" value="UITextWindow" isShow="false"></Action>
<Action type="UIShow" value="UIHint" isShow="false"></Action> <Action type="UIShow" value="UIHint" isShow="false"></Action>

View File

@ -288,8 +288,8 @@
<Action type="Parallel"> <Action type="Parallel">
<Action type="Move" value="FlyCamera" to="-5.530235,1.408061,5.152232" time="0"></Action> <Action type="Move" value="FlyCamera" to="-3.514123,0.7293322,0.5859525" time="0"></Action>
<Action type="Rotate" value="FlyCamera" to="6.030264,129.4993,-2.146311E-07" time="0"></Action> <Action type="Rotate" value="FlyCamera" to="9.980267,90.39926,0" time="0"></Action>
</Action> </Action>
<Action type="UIShow" value="UITextWindow" isShow="false"></Action> <Action type="UIShow" value="UITextWindow" isShow="false"></Action>
<Action type="UIShow" value="UIHint" isShow="false"></Action> <Action type="UIShow" value="UIHint" isShow="false"></Action>