2025-01-02 12:15:45 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using KinematicCharacterController;
|
|
|
|
|
|
using KinematicCharacterController.Examples;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace KinematicCharacterController.Walkthrough.NoClipState
|
|
|
|
|
|
{
|
|
|
|
|
|
public class MyPlayer : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
public ExampleCharacterCamera OrbitCamera;
|
|
|
|
|
|
public Transform CameraFollowPoint;
|
|
|
|
|
|
public MyCharacterController Character;
|
|
|
|
|
|
|
|
|
|
|
|
private const string MouseXInput = "Mouse X";
|
|
|
|
|
|
private const string MouseYInput = "Mouse Y";
|
|
|
|
|
|
private const string MouseScrollInput = "Mouse ScrollWheel";
|
|
|
|
|
|
private const string HorizontalInput = "Horizontal";
|
|
|
|
|
|
private const string VerticalInput = "Vertical";
|
|
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Cursor.lockState = CursorLockMode.Locked;
|
|
|
|
|
|
|
|
|
|
|
|
// Tell camera to follow transform
|
|
|
|
|
|
OrbitCamera.SetFollowTransform(CameraFollowPoint);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ignore the character's collider(s) for camera obstruction checks
|
|
|
|
|
|
OrbitCamera.IgnoredColliders.Clear();
|
|
|
|
|
|
OrbitCamera.IgnoredColliders.AddRange(Character.GetComponentsInChildren<Collider>());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerCharacterInputs.NoClipDown = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
PlayerCharacterInputs playerCharacterInputs = new PlayerCharacterInputs();
|
|
|
|
|
|
private void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
//if (Input.GetMouseButton(0))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Cursor.lockState =CursorLockMode.None;
|
|
|
|
|
|
//}
|
|
|
|
|
|
Cursor.visible = true;
|
2025-01-04 19:56:41 +08:00
|
|
|
|
|
2025-01-02 12:15:45 +08:00
|
|
|
|
HandleCharacterInput();
|
|
|
|
|
|
}
|
|
|
|
|
|
private int maxView = 80;
|
|
|
|
|
|
private int minView = 10;
|
|
|
|
|
|
private float slideSpeed = 20;
|
|
|
|
|
|
private void LateUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>ⰴ<EFBFBD><E2B0B4>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|
|
|
|
|
//float mouseCenter = Input.GetAxis("Mouse ScrollWheel");
|
|
|
|
|
|
//if (mouseCenter < 0)
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
|
|
// if (OrbitCamera.transform.GetComponent<Camera>().fieldOfView <= maxView) {
|
|
|
|
|
|
|
|
|
|
|
|
// OrbitCamera.transform.GetComponent<Camera>().fieldOfView += 10 * slideSpeed * Time.deltaTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
// //mouseCenter >0 = <20><><EFBFBD><EFBFBD> <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>,<2C>Ŵ<EFBFBD><C5B4><EFBFBD>ͷ
|
|
|
|
|
|
//}
|
|
|
|
|
|
//else if (mouseCenter > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
// if (OrbitCamera.transform.GetComponent<Camera>().fieldOfView >= minView)
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// OrbitCamera.transform.GetComponent<Camera>().fieldOfView -= 10 * slideSpeed * Time.deltaTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
|
|
|
|
|
|
HandleCameraInput();
|
|
|
|
|
|
}
|
|
|
|
|
|
private float _zoomSpeed = 1.6f;// 80.0f;
|
|
|
|
|
|
public float _ZoomSpeed { get => _zoomSpeed /** ZXK.GYJQR.GameManager.Instance._CurMouseFlexible*/; }
|
|
|
|
|
|
private float _minZoom = 5.0f;
|
|
|
|
|
|
private float _maxZoom = 100f;
|
|
|
|
|
|
private void HandleCameraInput()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Create the look input vector for the camera
|
|
|
|
|
|
//float mouseLookAxisUp = Input.GetAxisRaw(MouseYInput);
|
|
|
|
|
|
//float mouseLookAxisRight = Input.GetAxisRaw(MouseXInput);
|
2025-01-04 19:56:41 +08:00
|
|
|
|
float mouseLookAxisUp = 0;
|
|
|
|
|
|
float mouseLookAxisRight = 0;
|
|
|
|
|
|
if (CG.UTility.PopUpMng._TriAble)
|
|
|
|
|
|
{
|
|
|
|
|
|
mouseLookAxisUp = Input.GetAxis(MouseYInput);
|
|
|
|
|
|
mouseLookAxisRight = Input.GetAxis(MouseXInput);
|
|
|
|
|
|
}
|
2025-01-02 12:15:45 +08:00
|
|
|
|
if (Input.GetKey(KeyCode.Mouse1))
|
|
|
|
|
|
{
|
|
|
|
|
|
Vector3 lookInputVector = new Vector3(mouseLookAxisRight, mouseLookAxisUp, 0f);
|
|
|
|
|
|
float scrollInput = 0;
|
|
|
|
|
|
OrbitCamera.UpdateWithInput(Time.deltaTime, scrollInput, lookInputVector);
|
|
|
|
|
|
OrbitCamera.TargetDistance = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Prevent moving the camera while the cursor isn't locked
|
|
|
|
|
|
//if (Cursor.lockState != CursorLockMode.Locked)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// lookInputVector = Vector3.zero;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
// Input for zooming the camera (disabled in WebGL because it can cause problems)
|
|
|
|
|
|
// float scrollInput = -Input.GetAxis(MouseScrollInput);
|
|
|
|
|
|
// float scrollInput = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// float scrollInput = 0;
|
|
|
|
|
|
//#if UNITY_WEBGL
|
|
|
|
|
|
// scrollInput = 0f;
|
|
|
|
|
|
//#endif
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>0
|
|
|
|
|
|
// WDebug.Log("scrollInput!!!!!" + scrollInput);
|
|
|
|
|
|
|
|
|
|
|
|
// Apply inputs to the camera
|
|
|
|
|
|
// OrbitCamera.UpdateWithInput(Time.deltaTime, scrollInput, lookInputVector);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle toggling zoom level
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ҽ<EFBFBD><D2BC><EFBFBD><EFBFBD><EFBFBD>ֵ 0-6
|
|
|
|
|
|
//if (Input.GetMouseButtonDown(1))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// WDebug.Log("?????");
|
|
|
|
|
|
// OrbitCamera.TargetDistance = (OrbitCamera.TargetDistance == 0f) ? OrbitCamera.DefaultDistance : 0f;
|
|
|
|
|
|
|
|
|
|
|
|
// WDebug.Log(OrbitCamera.TargetDistance+"????????????????????");
|
|
|
|
|
|
//}
|
|
|
|
|
|
//<2F><>Զ<EFBFBD><D4B6>0
|
|
|
|
|
|
// OrbitCamera.TargetDistance = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void HandleCharacterInput()
|
|
|
|
|
|
{
|
|
|
|
|
|
PlayerCharacterInputs characterInputs = new PlayerCharacterInputs();
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>ⰴ<EFBFBD><E2B0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
2025-01-04 19:56:41 +08:00
|
|
|
|
|
|
|
|
|
|
characterInputs.MoveAxisForward = Input.GetAxisRaw(VerticalInput);
|
|
|
|
|
|
characterInputs.MoveAxisRight = Input.GetAxisRaw(HorizontalInput);
|
|
|
|
|
|
characterInputs.JumpHeld = Input.GetKey(KeyCode.Q);
|
|
|
|
|
|
characterInputs.CrouchHeld = Input.GetKey(KeyCode.E);
|
2025-01-02 12:15:45 +08:00
|
|
|
|
characterInputs.CameraRotation = OrbitCamera.Transform.rotation;
|
|
|
|
|
|
|
|
|
|
|
|
// characterInputs.JumpDown = Input.GetKeyDown(KeyCode.Space);
|
2025-01-04 19:56:41 +08:00
|
|
|
|
|
2025-01-02 12:15:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// characterInputs.CrouchDown = Input.GetKeyDown(KeyCode.C);
|
|
|
|
|
|
// characterInputs.CrouchUp = Input.GetKeyUp(KeyCode.C);
|
2025-01-04 19:56:41 +08:00
|
|
|
|
|
2025-01-02 12:15:45 +08:00
|
|
|
|
|
|
|
|
|
|
// characterInputs.NoClipDown = Input.GetKeyUp(KeyCode.Q);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Apply inputs to character
|
|
|
|
|
|
Character.SetInputs(ref characterInputs);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|