移除ECM2
This commit is contained in:
@@ -1,110 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace ECM2.Examples.ThirdPerson
|
||||
{
|
||||
/// <summary>
|
||||
/// This example extends a Character (through inheritance), implementing a typical Third Person control.
|
||||
/// </summary>
|
||||
|
||||
public class ThirdPersonCharacter : Character
|
||||
{
|
||||
[Space(15.0f)]
|
||||
public GameObject followTarget;
|
||||
|
||||
[Tooltip("The default distance behind the Follow target.")]
|
||||
[SerializeField]
|
||||
public float followDistance = 5.0f;
|
||||
|
||||
[Tooltip("The minimum distance to Follow target.")]
|
||||
[SerializeField]
|
||||
public float followMinDistance;
|
||||
|
||||
[Tooltip("The maximum distance to Follow target.")]
|
||||
[SerializeField]
|
||||
public float followMaxDistance = 10.0f;
|
||||
|
||||
protected float _cameraYaw;
|
||||
protected float _cameraPitch;
|
||||
|
||||
protected float _currentFollowDistance;
|
||||
protected float _followDistanceSmoothVelocity;
|
||||
|
||||
/// <summary>
|
||||
/// Add input (affecting Yaw).
|
||||
/// This is applied to the camera's rotation.
|
||||
/// </summary>
|
||||
|
||||
public virtual void AddControlYawInput(float value)
|
||||
{
|
||||
_cameraYaw = MathLib.ClampAngle(_cameraYaw + value, -180.0f, 180.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add input (affecting Pitch).
|
||||
/// This is applied to the camera's rotation.
|
||||
/// </summary>
|
||||
|
||||
public virtual void AddControlPitchInput(float value, float minValue = -80.0f, float maxValue = 80.0f)
|
||||
{
|
||||
_cameraPitch = MathLib.ClampAngle(_cameraPitch + value, minValue, maxValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds input (affecting follow distance).
|
||||
/// </summary>
|
||||
|
||||
public virtual void AddControlZoomInput(float value)
|
||||
{
|
||||
followDistance = Mathf.Clamp(followDistance - value, followMinDistance, followMaxDistance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update camera's rotation applying current _cameraPitch and _cameraYaw values.
|
||||
/// </summary>
|
||||
|
||||
protected virtual void UpdateCameraRotation()
|
||||
{
|
||||
cameraTransform.rotation = Quaternion.Euler(_cameraPitch, _cameraYaw, 0.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update camera's position maintaining _currentFollowDistance from target.
|
||||
/// </summary>
|
||||
|
||||
protected virtual void UpdateCameraPosition()
|
||||
{
|
||||
_currentFollowDistance =
|
||||
Mathf.SmoothDamp(_currentFollowDistance, followDistance, ref _followDistanceSmoothVelocity, 0.2f);
|
||||
|
||||
cameraTransform.position =
|
||||
followTarget.transform.position - cameraTransform.forward * _currentFollowDistance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update camera's position and rotation.
|
||||
/// </summary>
|
||||
|
||||
protected virtual void UpdateCamera()
|
||||
{
|
||||
UpdateCameraRotation();
|
||||
UpdateCameraPosition();
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
Vector3 eulerAngles = cameraTransform.eulerAngles;
|
||||
|
||||
_cameraPitch = eulerAngles.x;
|
||||
_cameraYaw = eulerAngles.y;
|
||||
|
||||
_currentFollowDistance = followDistance;
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
UpdateCamera();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 798a5e46fa4539c498a5bc5625f3712b
|
||||
@@ -1,149 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace ECM2.Examples.ThirdPerson
|
||||
{
|
||||
/// <summary>
|
||||
/// Third person character input.
|
||||
/// Extends the default CharacterInput component adding support for typical third person controls.
|
||||
/// </summary>
|
||||
|
||||
public class ThirdPersonInput : CharacterInput
|
||||
{
|
||||
[Space(15.0f)]
|
||||
public bool invertLook = true;
|
||||
|
||||
[Tooltip("Look Sensitivity")]
|
||||
public Vector2 lookSensitivity = new Vector2(0.05f, 0.05f);
|
||||
|
||||
[Tooltip("Zoom Sensitivity")]
|
||||
public float zoomSensitivity = 1.0f;
|
||||
|
||||
[Space(15.0f)]
|
||||
[Tooltip("How far in degrees can you move the camera down.")]
|
||||
public float minPitch = -80.0f;
|
||||
|
||||
[Tooltip("How far in degrees can you move the camera up.")]
|
||||
public float maxPitch = 80.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Cached ThirdPersonCharacter.
|
||||
/// </summary>
|
||||
|
||||
public ThirdPersonCharacter thirdPersonCharacter { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Movement InputAction.
|
||||
/// </summary>
|
||||
|
||||
public InputAction lookInputAction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Zoom InputAction.
|
||||
/// </summary>
|
||||
|
||||
public InputAction zoomInputAction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Polls look InputAction (if any).
|
||||
/// Return its current value or zero if no valid InputAction found.
|
||||
/// </summary>
|
||||
|
||||
public Vector2 GetLookInput()
|
||||
{
|
||||
return lookInputAction?.ReadValue<Vector2>() ?? Vector2.zero;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Polls zoom InputAction (if any).
|
||||
/// Return its current value or zero if no valid InputAction found.
|
||||
/// </summary>
|
||||
|
||||
public Vector2 GetZoomInput()
|
||||
{
|
||||
return zoomInputAction?.ReadValue<Vector2>() ?? Vector2.zero;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize player InputActions (if any).
|
||||
/// E.g. Subscribe to input action events and enable input actions here.
|
||||
/// </summary>
|
||||
|
||||
protected override void InitPlayerInput()
|
||||
{
|
||||
base.InitPlayerInput();
|
||||
|
||||
// Look input action (no handler, this is polled, e.g. GetLookInput())
|
||||
|
||||
lookInputAction = inputActionsAsset.FindAction("Look");
|
||||
lookInputAction?.Enable();
|
||||
|
||||
// Zoom input action (no handler, this is polled, e.g. GetLookInput())
|
||||
|
||||
zoomInputAction = inputActionsAsset.FindAction("Zoom");
|
||||
zoomInputAction?.Enable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unsubscribe from input action events and disable input actions.
|
||||
/// </summary>
|
||||
|
||||
protected override void DeinitPlayerInput()
|
||||
{
|
||||
base.DeinitPlayerInput();
|
||||
|
||||
// Unsubscribe from input action events and disable input actions
|
||||
|
||||
if (lookInputAction != null)
|
||||
{
|
||||
lookInputAction.Disable();
|
||||
lookInputAction = null;
|
||||
}
|
||||
|
||||
if (zoomInputAction != null)
|
||||
{
|
||||
zoomInputAction.Disable();
|
||||
zoomInputAction = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
thirdPersonCharacter = character as ThirdPersonCharacter;
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
protected override void HandleInput()
|
||||
{
|
||||
// Move
|
||||
|
||||
Vector2 movementInput = GetMovementInput();
|
||||
|
||||
Vector3 movementDirection = Vector3.zero;
|
||||
movementDirection += Vector3.forward * movementInput.y;
|
||||
movementDirection += Vector3.right * movementInput.x;
|
||||
|
||||
movementDirection = movementDirection.relativeTo(thirdPersonCharacter.cameraTransform, thirdPersonCharacter.GetUpVector());
|
||||
|
||||
thirdPersonCharacter.SetMovementDirection(movementDirection);
|
||||
|
||||
// Look
|
||||
|
||||
Vector2 lookInput = GetLookInput() * lookSensitivity;
|
||||
|
||||
thirdPersonCharacter.AddControlYawInput(lookInput.x);
|
||||
thirdPersonCharacter.AddControlPitchInput(invertLook ? -lookInput.y : lookInput.y, minPitch, maxPitch);
|
||||
|
||||
// Zoom
|
||||
|
||||
Vector2 zoomInput = GetZoomInput() * zoomSensitivity;
|
||||
thirdPersonCharacter.AddControlZoomInput(zoomInput.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0f254751279cd34487e0e6ed6bea863
|
||||
Reference in New Issue
Block a user