移除ECM2
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace ECM2.Examples.FirstPerson
|
||||
{
|
||||
/// <summary>
|
||||
/// This example extends a Character (through inheritance), implementing a First Person control.
|
||||
/// </summary>
|
||||
|
||||
public class FirstPersonCharacter : Character
|
||||
{
|
||||
[Tooltip("The first person camera parent.")]
|
||||
public GameObject cameraParent;
|
||||
|
||||
private float _cameraPitch;
|
||||
|
||||
/// <summary>
|
||||
/// Add input (affecting Yaw).
|
||||
/// This is applied to the Character's rotation.
|
||||
/// </summary>
|
||||
|
||||
public virtual void AddControlYawInput(float value)
|
||||
{
|
||||
if (value != 0.0f)
|
||||
AddYawInput(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add input (affecting Pitch).
|
||||
/// This is applied to the cameraParent's local rotation.
|
||||
/// </summary>
|
||||
|
||||
public virtual void AddControlPitchInput(float value, float minPitch = -80.0f, float maxPitch = 80.0f)
|
||||
{
|
||||
if (value != 0.0f)
|
||||
_cameraPitch = MathLib.ClampAngle(_cameraPitch + value, minPitch, maxPitch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update cameraParent local rotation applying current _cameraPitch value.
|
||||
/// </summary>
|
||||
|
||||
protected virtual void UpdateCameraParentRotation()
|
||||
{
|
||||
cameraParent.transform.localRotation = Quaternion.Euler(_cameraPitch, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If overriden, base method MUST be called.
|
||||
/// </summary>
|
||||
|
||||
protected virtual void LateUpdate()
|
||||
{
|
||||
UpdateCameraParentRotation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If overriden, base method MUST be called.
|
||||
/// </summary>
|
||||
|
||||
protected override void Reset()
|
||||
{
|
||||
// Call base method implementation
|
||||
|
||||
base.Reset();
|
||||
|
||||
// Disable character's rotation,
|
||||
// it is handled by the AddControlYawInput method
|
||||
|
||||
SetRotationMode(RotationMode.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 713b3a549961cf64d88d9131fdc9be1a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,114 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace ECM2.Examples.FirstPerson
|
||||
{
|
||||
/// <summary>
|
||||
/// First person character input.
|
||||
/// Extends the default CharacterInput component adding support for typical first person controls.
|
||||
/// </summary>
|
||||
|
||||
public class FirstPersonInput : CharacterInput
|
||||
{
|
||||
[Space(15.0f)]
|
||||
public bool invertLook = true;
|
||||
[Tooltip("Look sensitivity")]
|
||||
public Vector2 sensitivity = new Vector2(0.05f, 0.05f);
|
||||
|
||||
[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 FirstPersonCharacter.
|
||||
/// </summary>
|
||||
|
||||
public FirstPersonCharacter firstPersonCharacter { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Movement InputAction.
|
||||
/// </summary>
|
||||
|
||||
public InputAction lookInputAction { 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>
|
||||
/// 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();
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
firstPersonCharacter = character as FirstPersonCharacter;
|
||||
}
|
||||
|
||||
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(firstPersonCharacter.cameraTransform, firstPersonCharacter.GetUpVector());
|
||||
|
||||
firstPersonCharacter.SetMovementDirection(movementDirection);
|
||||
|
||||
// Look
|
||||
|
||||
Vector2 lookInput = GetLookInput() * sensitivity;
|
||||
|
||||
firstPersonCharacter.AddControlYawInput(lookInput.x);
|
||||
firstPersonCharacter.AddControlPitchInput(invertLook ? -lookInput.y : lookInput.y, minPitch, maxPitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba598d44e33b26849a4d3d6005e49fd1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user