移除ECM2
This commit is contained in:
@@ -1,224 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace ECM2.Examples
|
||||
{
|
||||
/// <summary>
|
||||
/// Character Input.
|
||||
/// Shows how control a Character using the Input System.
|
||||
/// </summary>
|
||||
|
||||
public class CharacterInput : MonoBehaviour
|
||||
{
|
||||
[Space(15f)]
|
||||
[Tooltip("Collection of input action maps and control schemes available for user controls.")]
|
||||
[SerializeField]
|
||||
private InputActionAsset _inputActionsAsset;
|
||||
|
||||
[Tooltip("The character to be controlled. If left unassigned, this will attempt to locate a Character component within this GameObject.")]
|
||||
[SerializeField]
|
||||
private Character _character;
|
||||
|
||||
/// <summary>
|
||||
/// Our controlled character.
|
||||
/// </summary>
|
||||
|
||||
public Character character => _character;
|
||||
|
||||
/// <summary>
|
||||
/// InputActions assets.
|
||||
/// </summary>
|
||||
|
||||
public InputActionAsset inputActionsAsset
|
||||
{
|
||||
get => _inputActionsAsset;
|
||||
set
|
||||
{
|
||||
DeinitPlayerInput();
|
||||
|
||||
_inputActionsAsset = value;
|
||||
InitPlayerInput();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Movement InputAction.
|
||||
/// </summary>
|
||||
|
||||
public InputAction movementInputAction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Jump InputAction.
|
||||
/// </summary>
|
||||
|
||||
public InputAction jumpInputAction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Crouch InputAction.
|
||||
/// </summary>
|
||||
|
||||
public InputAction crouchInputAction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Polls movement InputAction (if any).
|
||||
/// Return its current value or zero if no valid InputAction found.
|
||||
/// </summary>
|
||||
|
||||
public virtual Vector2 GetMovementInput()
|
||||
{
|
||||
return movementInputAction?.ReadValue<Vector2>() ?? Vector2.zero;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Jump InputAction handler.
|
||||
/// </summary>
|
||||
|
||||
public virtual void OnJump(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.started)
|
||||
_character.Jump();
|
||||
else if (context.canceled)
|
||||
_character.StopJumping();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Crouch InputAction handler.
|
||||
/// </summary>
|
||||
|
||||
public virtual void OnCrouch(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.started)
|
||||
_character.Crouch();
|
||||
else if (context.canceled)
|
||||
_character.UnCrouch();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize player InputActions (if any).
|
||||
/// E.g. Subscribe to input action events and enable input actions here.
|
||||
/// </summary>
|
||||
|
||||
protected virtual void InitPlayerInput()
|
||||
{
|
||||
// Attempts to cache Character InputActions (if any)
|
||||
|
||||
if (inputActionsAsset == null)
|
||||
return;
|
||||
|
||||
// Movement input action (no handler, this is polled, e.g. GetMovementInput())
|
||||
|
||||
movementInputAction = inputActionsAsset.FindAction("Move");
|
||||
movementInputAction?.Enable();
|
||||
|
||||
// Setup Jump input action handlers
|
||||
|
||||
jumpInputAction = inputActionsAsset.FindAction("Jump");
|
||||
if (jumpInputAction != null)
|
||||
{
|
||||
jumpInputAction.started += OnJump;
|
||||
jumpInputAction.canceled += OnJump;
|
||||
|
||||
jumpInputAction.Enable();
|
||||
}
|
||||
|
||||
// Setup Crouch input action handlers
|
||||
|
||||
crouchInputAction = inputActionsAsset.FindAction("Crouch");
|
||||
if (crouchInputAction != null)
|
||||
{
|
||||
crouchInputAction.started += OnCrouch;
|
||||
crouchInputAction.canceled += OnCrouch;
|
||||
|
||||
crouchInputAction.Enable();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unsubscribe from input action events and disable input actions.
|
||||
/// </summary>
|
||||
|
||||
protected virtual void DeinitPlayerInput()
|
||||
{
|
||||
// Unsubscribe from input action events and disable input actions
|
||||
|
||||
if (movementInputAction != null)
|
||||
{
|
||||
movementInputAction.Disable();
|
||||
movementInputAction = null;
|
||||
}
|
||||
|
||||
if (jumpInputAction != null)
|
||||
{
|
||||
jumpInputAction.started -= OnJump;
|
||||
jumpInputAction.canceled -= OnJump;
|
||||
|
||||
jumpInputAction.Disable();
|
||||
jumpInputAction = null;
|
||||
}
|
||||
|
||||
if (crouchInputAction != null)
|
||||
{
|
||||
crouchInputAction.started -= OnCrouch;
|
||||
crouchInputAction.canceled -= OnCrouch;
|
||||
|
||||
crouchInputAction.Disable();
|
||||
crouchInputAction = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void HandleInput()
|
||||
{
|
||||
// Should this character handle input ?
|
||||
|
||||
if (inputActionsAsset == null)
|
||||
return;
|
||||
|
||||
// Poll movement InputAction
|
||||
|
||||
Vector2 movementInput = GetMovementInput();
|
||||
|
||||
Vector3 movementDirection = Vector3.zero;
|
||||
|
||||
movementDirection += Vector3.right * movementInput.x;
|
||||
movementDirection += Vector3.forward * movementInput.y;
|
||||
|
||||
// If character has a camera assigned...
|
||||
|
||||
if (_character.camera)
|
||||
{
|
||||
// Make movement direction relative to its camera view direction
|
||||
|
||||
movementDirection = movementDirection.relativeTo(_character.cameraTransform, _character.GetUpVector());
|
||||
}
|
||||
|
||||
// Set character's movement direction vector
|
||||
|
||||
_character.SetMovementDirection(movementDirection);
|
||||
}
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
// If no character assigned, try to get Character from this GameObject
|
||||
|
||||
if (_character == null)
|
||||
{
|
||||
_character = GetComponent<Character>();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
InitPlayerInput();
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
DeinitPlayerInput();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
HandleInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e33907e14463d146a0fb34c9baaa320
|
||||
@@ -1,27 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace ECM2.Examples
|
||||
{
|
||||
/// <summary>
|
||||
/// Shows how to use the new (introduced in v1.4) Character Pause method to pause / resume a Character.
|
||||
/// When paused, a Character prevents any interaction.
|
||||
/// </summary>
|
||||
|
||||
public class CharacterPause : MonoBehaviour
|
||||
{
|
||||
private Character _character;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_character = GetComponent<Character>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Toggle Character pause
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.P))
|
||||
_character.Pause(!_character.isPaused);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 957641d45695471a971ded93e92de0ba
|
||||
timeCreated: 1700616504
|
||||
@@ -1,68 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace ECM2.Examples
|
||||
{
|
||||
public sealed class SimpleCameraController : MonoBehaviour
|
||||
{
|
||||
#region PUBLIC FIELDS
|
||||
|
||||
[SerializeField]
|
||||
private Transform _target;
|
||||
|
||||
[SerializeField]
|
||||
private float _distanceToTarget = 10.0f;
|
||||
|
||||
[SerializeField]
|
||||
private float _smoothTime = 0.1f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region FIELDS
|
||||
|
||||
private Vector3 _followVelocity;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PROPERTIES
|
||||
|
||||
public Transform target
|
||||
{
|
||||
get => _target;
|
||||
set => _target = value;
|
||||
}
|
||||
|
||||
public float distanceToTarget
|
||||
{
|
||||
get => _distanceToTarget;
|
||||
set => _distanceToTarget = Mathf.Max(0.0f, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MONOBEHAVIOUR
|
||||
|
||||
public void OnValidate()
|
||||
{
|
||||
distanceToTarget = _distanceToTarget;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (_target == null)
|
||||
return;
|
||||
|
||||
transform.position = target.position - transform.forward * distanceToTarget;
|
||||
}
|
||||
|
||||
public void LateUpdate()
|
||||
{
|
||||
if (_target == null)
|
||||
return;
|
||||
|
||||
Vector3 targetPosition = target.position - transform.forward * distanceToTarget;
|
||||
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref _followVelocity, _smoothTime);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: daca56d2826d2b04b97102fbe48616e3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user