移除ECM2
This commit is contained in:
@@ -1,109 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace ECM2.Walkthrough.Ex42
|
||||
{
|
||||
/// <summary>
|
||||
/// This example shows how to extend a Character (through composition) to perform a sprint ability.
|
||||
/// This one use the new simulation OnBeforeSimulationUpdate event (introduced in v1.4),
|
||||
/// to easily modify the character's state within Character's simulation loop.
|
||||
/// </summary>
|
||||
|
||||
public class SprintAbility : MonoBehaviour
|
||||
{
|
||||
[Space(15.0f)]
|
||||
public float maxSprintSpeed = 10.0f;
|
||||
|
||||
private Character _character;
|
||||
|
||||
private bool _isSprinting;
|
||||
private bool _sprintInputPressed;
|
||||
|
||||
private float _cachedMaxWalkSpeed;
|
||||
|
||||
/// <summary>
|
||||
/// Request the character to start to sprint.
|
||||
/// </summary>
|
||||
|
||||
public void Sprint()
|
||||
{
|
||||
_sprintInputPressed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request the character to stop sprinting.
|
||||
/// </summary>
|
||||
|
||||
public void StopSprinting()
|
||||
{
|
||||
_sprintInputPressed = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return true if the character is sprinting, false otherwise.
|
||||
/// </summary>
|
||||
|
||||
public bool IsSprinting()
|
||||
{
|
||||
return _isSprinting;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the character, is able to sprint in its current state.
|
||||
/// </summary>
|
||||
|
||||
private bool CanSprint()
|
||||
{
|
||||
return _character.IsWalking() && !_character.IsCrouched();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles sprint input and adjusts character speed accordingly.
|
||||
/// </summary>
|
||||
|
||||
private void CheckSprintInput()
|
||||
{
|
||||
if (!_isSprinting && _sprintInputPressed && CanSprint())
|
||||
{
|
||||
_isSprinting = true;
|
||||
|
||||
_cachedMaxWalkSpeed = _character.maxWalkSpeed;
|
||||
_character.maxWalkSpeed = maxSprintSpeed;
|
||||
|
||||
}
|
||||
else if (_isSprinting && (!_sprintInputPressed || !CanSprint()))
|
||||
{
|
||||
_isSprinting = false;
|
||||
|
||||
_character.maxWalkSpeed = _cachedMaxWalkSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBeforeSimulationUpdated(float deltaTime)
|
||||
{
|
||||
// Handle sprinting
|
||||
|
||||
CheckSprintInput();
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Cache character
|
||||
|
||||
_character = GetComponent<Character>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
// Subscribe to Character BeforeSimulationUpdated event
|
||||
|
||||
_character.BeforeSimulationUpdated += OnBeforeSimulationUpdated;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
// Un-Subscribe from Character BeforeSimulationUpdated event
|
||||
|
||||
_character.BeforeSimulationUpdated -= OnBeforeSimulationUpdated;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea4bc13934a49484bb0606e7a1ff4f76
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,76 +0,0 @@
|
||||
using ECM2.Examples;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace ECM2.Walkthrough.Ex42
|
||||
{
|
||||
/// <summary>
|
||||
/// Extends CharacterInput adding support to handle the Sprint Ability.
|
||||
/// </summary>
|
||||
|
||||
public class SprintAbilityInput : CharacterInput
|
||||
{
|
||||
// The Sprint Ability
|
||||
|
||||
private SprintAbility _sprintAbility;
|
||||
|
||||
/// <summary>
|
||||
/// Sprint InputAction.
|
||||
/// </summary>
|
||||
|
||||
public InputAction sprintInputAction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sprint InputAction handler.
|
||||
/// </summary>
|
||||
|
||||
public virtual void OnSprint(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.started)
|
||||
_sprintAbility.Sprint();
|
||||
else if (context.canceled)
|
||||
_sprintAbility.StopSprinting();
|
||||
}
|
||||
|
||||
protected override void InitPlayerInput()
|
||||
{
|
||||
base.InitPlayerInput();
|
||||
|
||||
// Setup Sprint input action handlers
|
||||
|
||||
sprintInputAction = inputActionsAsset.FindAction("Sprint");
|
||||
if (sprintInputAction != null)
|
||||
{
|
||||
sprintInputAction.started += OnSprint;
|
||||
sprintInputAction.canceled += OnSprint;
|
||||
|
||||
sprintInputAction.Enable();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DeinitPlayerInput()
|
||||
{
|
||||
base.DeinitPlayerInput();
|
||||
|
||||
if (sprintInputAction != null)
|
||||
{
|
||||
sprintInputAction.started -= OnSprint;
|
||||
sprintInputAction.canceled -= OnSprint;
|
||||
|
||||
sprintInputAction.Disable();
|
||||
sprintInputAction = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
// Call base method implementation (a MUST)
|
||||
|
||||
base.Awake();
|
||||
|
||||
// Cache character sprint ability component
|
||||
|
||||
_sprintAbility = GetComponent<SprintAbility>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4213399d96084b888c737cbc95143458
|
||||
timeCreated: 1700116698
|
||||
Reference in New Issue
Block a user