Import assets from store
This commit is contained in:
1 parent
a05f2e47a2
commit
376e52e323
875 files changed
+128037
No files matched your search
@@ -0,0 +1,17 @@
|
||||
namespace CharacterMovement
|
||||
{
|
||||
public enum CharacterAnimationState
|
||||
{
|
||||
None = 0,
|
||||
Idle = 1,
|
||||
Moving = 2,
|
||||
Jumping = 3,
|
||||
Falling = 4,
|
||||
Crouching = 5,
|
||||
Prone = 6,
|
||||
Sliding = 7,
|
||||
Dashing = 8,
|
||||
Vaulting = 9,
|
||||
Parkour = 10
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30e61f43d67947beb1e1d757f9e9ad19
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 367142
|
||||
packageName: "MotionCore \u2013 Physics Character Controller"
|
||||
packageVersion: 1.2
|
||||
assetPath: Assets/Character Controller/Core/Scripts/Animation/CharacterAnimationState.cs
|
||||
uploadId: 997018
|
||||
@@ -0,0 +1,280 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace CharacterMovement
|
||||
{
|
||||
[AddComponentMenu("Character Controller/Core/Character Animator Bridge")]
|
||||
public class CharacterAnimatorBridge : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public class StanceChangedEvent : UnityEvent<PlayerStance, PlayerStance>
|
||||
{
|
||||
}
|
||||
|
||||
[Header("References")]
|
||||
[Tooltip("Controller to read state from. Found on this GameObject if left empty.")]
|
||||
[SerializeField] private PlayerController playerController;
|
||||
[Tooltip("Animator to drive. Searched for in children if left empty.")]
|
||||
[SerializeField] private Animator animator;
|
||||
[Tooltip("Asset mapping controller state to your Animator's parameter names.")]
|
||||
[SerializeField] private CharacterAnimatorParameters parameters;
|
||||
|
||||
[Header("Tuning")]
|
||||
[Tooltip("Smoothing applied to float parameters, in seconds. 0 writes raw values.")]
|
||||
[SerializeField, Min(0f)] private float floatDampTime = 0.08f;
|
||||
[Header("Events")]
|
||||
[Tooltip("Raised when a jump launches.")]
|
||||
[SerializeField] private UnityEvent jumpStarted;
|
||||
[Tooltip("Raised on touchdown.")]
|
||||
[SerializeField] private UnityEvent landed;
|
||||
[Tooltip("Raised when a slide begins.")]
|
||||
[SerializeField] private UnityEvent slideStarted;
|
||||
[Tooltip("Raised when a slide ends.")]
|
||||
[SerializeField] private UnityEvent slideEnded;
|
||||
[Tooltip("Raised when a vault begins.")]
|
||||
[SerializeField] private UnityEvent vaultStarted;
|
||||
[Tooltip("Raised when a vault ends.")]
|
||||
[SerializeField] private UnityEvent vaultEnded;
|
||||
[Tooltip("Raised when an add-on module reports a mantle starting.")]
|
||||
[SerializeField] private UnityEvent mantleStarted;
|
||||
[Tooltip("Raised when an add-on module reports a mantle ending.")]
|
||||
[SerializeField] private UnityEvent mantleEnded;
|
||||
[Tooltip("Raised when the stance changes, with the previous and new stance.")]
|
||||
[SerializeField] private StanceChangedEvent stanceChanged;
|
||||
|
||||
private readonly Dictionary<int, AnimatorControllerParameterType> _availableParameters =
|
||||
new Dictionary<int, AnimatorControllerParameterType>();
|
||||
|
||||
public PlayerController PlayerController => playerController;
|
||||
public Animator Animator => animator;
|
||||
public CharacterAnimatorParameters Parameters => parameters;
|
||||
public UnityEvent JumpStarted => jumpStarted;
|
||||
public UnityEvent Landed => landed;
|
||||
public UnityEvent SlideStarted => slideStarted;
|
||||
public UnityEvent SlideEnded => slideEnded;
|
||||
public UnityEvent VaultStarted => vaultStarted;
|
||||
public UnityEvent VaultEnded => vaultEnded;
|
||||
public UnityEvent MantleStarted => mantleStarted;
|
||||
public UnityEvent MantleEnded => mantleEnded;
|
||||
public StanceChangedEvent StanceChanged => stanceChanged;
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
ResolveReferences();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ResolveReferences();
|
||||
CacheAnimatorParameters();
|
||||
Subscribe();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
Unsubscribe();
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
floatDampTime = Mathf.Max(0f, floatDampTime);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!playerController || !animator || !parameters)
|
||||
return;
|
||||
|
||||
float deltaTime = Time.deltaTime;
|
||||
Vector3 velocity = playerController.RigidBody ? playerController.RigidBody.linearVelocity : Vector3.zero;
|
||||
Vector3 planarVelocity = Vector3.ProjectOnPlane(velocity, Vector3.up);
|
||||
Vector2 moveInput = playerController.InputSource.MoveDirection;
|
||||
LocomotionState movementState = playerController.MovementState;
|
||||
|
||||
TrySetFloat(parameters.Speed, velocity.magnitude, deltaTime);
|
||||
float planarSpeed = planarVelocity.magnitude;
|
||||
TrySetFloat(parameters.PlanarSpeed, planarSpeed, deltaTime);
|
||||
TrySetFloat(parameters.NormalizedSpeed, ResolveNormalizedSpeed(planarSpeed), deltaTime);
|
||||
TrySetFloat(parameters.Forward, moveInput.y, deltaTime);
|
||||
TrySetFloat(parameters.Strafe, moveInput.x, deltaTime);
|
||||
TrySetBool(parameters.IsGrounded, playerController.IsGrounded());
|
||||
TrySetBool(parameters.IsFalling, movementState == LocomotionState.Falling);
|
||||
TrySetBool(parameters.IsJumping, movementState == LocomotionState.Jumping);
|
||||
TrySetBool(parameters.IsSprinting, playerController.IsSprintRequested);
|
||||
TrySetBool(parameters.IsCrouching, playerController.CurrentStance == PlayerStance.Crouching);
|
||||
TrySetBool(parameters.IsProne, playerController.CurrentStance == PlayerStance.Prone);
|
||||
TrySetBool(parameters.IsSliding, movementState == LocomotionState.Sliding);
|
||||
TrySetInt(parameters.Stance, (int)playerController.CurrentStance);
|
||||
TrySetInt(parameters.MovementState, (int)PlayerController.ToAnimationState(movementState));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Planar speed as a 0-1 fraction of the character's top speed, for blend trees.
|
||||
/// </summary>
|
||||
private float ResolveNormalizedSpeed(float planarSpeed)
|
||||
{
|
||||
float topSpeed = Mathf.Max(playerController.SprintSpeed, playerController.Speed);
|
||||
return topSpeed > 0.0001f ? Mathf.Clamp01(planarSpeed / topSpeed) : 0f;
|
||||
}
|
||||
|
||||
public void RefreshAnimatorParameterCache()
|
||||
{
|
||||
CacheAnimatorParameters();
|
||||
}
|
||||
|
||||
private void ResolveReferences()
|
||||
{
|
||||
if (!playerController)
|
||||
playerController = GetComponent<PlayerController>();
|
||||
|
||||
if (!animator)
|
||||
{
|
||||
if (playerController && playerController.PlayerAnimator)
|
||||
animator = playerController.PlayerAnimator;
|
||||
else
|
||||
animator = GetComponentInChildren<Animator>();
|
||||
}
|
||||
}
|
||||
|
||||
private void Subscribe()
|
||||
{
|
||||
if (!playerController)
|
||||
return;
|
||||
|
||||
playerController.JumpStarted += OnJumpStarted;
|
||||
playerController.Landed += OnLanded;
|
||||
playerController.SlideStarted += OnSlideStarted;
|
||||
playerController.SlideEnded += OnSlideEnded;
|
||||
playerController.VaultStarted += OnVaultStarted;
|
||||
playerController.VaultEnded += OnVaultEnded;
|
||||
playerController.MantleStarted += OnMantleStarted;
|
||||
playerController.MantleEnded += OnMantleEnded;
|
||||
playerController.StanceChanged += OnStanceChanged;
|
||||
}
|
||||
|
||||
private void Unsubscribe()
|
||||
{
|
||||
if (!playerController)
|
||||
return;
|
||||
|
||||
playerController.JumpStarted -= OnJumpStarted;
|
||||
playerController.Landed -= OnLanded;
|
||||
playerController.SlideStarted -= OnSlideStarted;
|
||||
playerController.SlideEnded -= OnSlideEnded;
|
||||
playerController.VaultStarted -= OnVaultStarted;
|
||||
playerController.VaultEnded -= OnVaultEnded;
|
||||
playerController.MantleStarted -= OnMantleStarted;
|
||||
playerController.MantleEnded -= OnMantleEnded;
|
||||
playerController.StanceChanged -= OnStanceChanged;
|
||||
}
|
||||
|
||||
private void CacheAnimatorParameters()
|
||||
{
|
||||
_availableParameters.Clear();
|
||||
if (!animator)
|
||||
return;
|
||||
|
||||
AnimatorControllerParameter[] animatorParameters = animator.parameters;
|
||||
for (int i = 0; i < animatorParameters.Length; i++)
|
||||
{
|
||||
AnimatorControllerParameter parameter = animatorParameters[i];
|
||||
_availableParameters[parameter.nameHash] = parameter.type;
|
||||
}
|
||||
}
|
||||
|
||||
private void TrySetFloat(string parameterName, float value, float deltaTime)
|
||||
{
|
||||
if (!TryGetParameter(parameterName, AnimatorControllerParameterType.Float, out int hash))
|
||||
return;
|
||||
|
||||
if (floatDampTime > 0f)
|
||||
animator.SetFloat(hash, value, floatDampTime, deltaTime);
|
||||
else
|
||||
animator.SetFloat(hash, value);
|
||||
}
|
||||
|
||||
private void TrySetBool(string parameterName, bool value)
|
||||
{
|
||||
if (TryGetParameter(parameterName, AnimatorControllerParameterType.Bool, out int hash))
|
||||
animator.SetBool(hash, value);
|
||||
}
|
||||
|
||||
private void TrySetInt(string parameterName, int value)
|
||||
{
|
||||
if (TryGetParameter(parameterName, AnimatorControllerParameterType.Int, out int hash))
|
||||
animator.SetInteger(hash, value);
|
||||
}
|
||||
|
||||
private void TrySetTrigger(string parameterName)
|
||||
{
|
||||
if (TryGetParameter(parameterName, AnimatorControllerParameterType.Trigger, out int hash))
|
||||
animator.SetTrigger(hash);
|
||||
}
|
||||
|
||||
private bool TryGetParameter(string parameterName, AnimatorControllerParameterType expectedType, out int hash)
|
||||
{
|
||||
hash = 0;
|
||||
if (string.IsNullOrWhiteSpace(parameterName) || !animator)
|
||||
return false;
|
||||
|
||||
hash = Animator.StringToHash(parameterName);
|
||||
return _availableParameters.TryGetValue(hash, out AnimatorControllerParameterType actualType)
|
||||
&& actualType == expectedType;
|
||||
}
|
||||
|
||||
private void OnJumpStarted()
|
||||
{
|
||||
TrySetTrigger(parameters ? parameters.JumpStarted : null);
|
||||
jumpStarted?.Invoke();
|
||||
}
|
||||
|
||||
private void OnLanded()
|
||||
{
|
||||
TrySetTrigger(parameters ? parameters.Landed : null);
|
||||
landed?.Invoke();
|
||||
}
|
||||
|
||||
private void OnSlideStarted()
|
||||
{
|
||||
TrySetTrigger(parameters ? parameters.SlideStarted : null);
|
||||
slideStarted?.Invoke();
|
||||
}
|
||||
|
||||
private void OnSlideEnded()
|
||||
{
|
||||
TrySetTrigger(parameters ? parameters.SlideEnded : null);
|
||||
slideEnded?.Invoke();
|
||||
}
|
||||
|
||||
private void OnVaultStarted()
|
||||
{
|
||||
TrySetTrigger(parameters ? parameters.VaultStarted : null);
|
||||
vaultStarted?.Invoke();
|
||||
}
|
||||
|
||||
private void OnVaultEnded()
|
||||
{
|
||||
TrySetTrigger(parameters ? parameters.VaultEnded : null);
|
||||
vaultEnded?.Invoke();
|
||||
}
|
||||
|
||||
private void OnMantleStarted()
|
||||
{
|
||||
TrySetTrigger(parameters ? parameters.MantleStarted : null);
|
||||
mantleStarted?.Invoke();
|
||||
}
|
||||
|
||||
private void OnMantleEnded()
|
||||
{
|
||||
TrySetTrigger(parameters ? parameters.MantleEnded : null);
|
||||
mantleEnded?.Invoke();
|
||||
}
|
||||
|
||||
private void OnStanceChanged(PlayerStance previousStance, PlayerStance nextStance)
|
||||
{
|
||||
stanceChanged?.Invoke(previousStance, nextStance);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2afa0f6808a4a2a86b4ef67fb9e913b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 367142
|
||||
packageName: "MotionCore \u2013 Physics Character Controller"
|
||||
packageVersion: 1.2
|
||||
assetPath: Assets/Character Controller/Core/Scripts/Animation/CharacterAnimatorBridge.cs
|
||||
uploadId: 997018
|
||||
@@ -0,0 +1,82 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace CharacterMovement
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Character Controller/Core/Animator Parameters", fileName = "CharacterAnimatorParameters")]
|
||||
public class CharacterAnimatorParameters : ScriptableObject
|
||||
{
|
||||
[Header("Float Parameters")]
|
||||
[SerializeField] private string speed = "Speed";
|
||||
[SerializeField] private string planarSpeed = "PlanarSpeed";
|
||||
[SerializeField]
|
||||
[Tooltip("Planar speed as 0-1 of the character's top speed. Convenient as the blend "
|
||||
+ "parameter of an idle/walk/run/sprint blend tree.")]
|
||||
private string normalizedSpeed = "NormalizedSpeed";
|
||||
[SerializeField] private string forward = "Forward";
|
||||
[Tooltip("Float parameter receiving sideways move input, -1 to 1.")]
|
||||
[SerializeField] private string strafe = "Strafe";
|
||||
|
||||
[Header("Bool Parameters")]
|
||||
[Tooltip("Bool parameter set while the character is on the ground.")]
|
||||
[SerializeField] private string isGrounded = "IsGrounded";
|
||||
[Tooltip("Bool parameter set while the character is falling.")]
|
||||
[SerializeField] private string isFalling = "IsFalling";
|
||||
[Tooltip("Bool parameter set while the character is rising from a jump.")]
|
||||
[SerializeField] private string isJumping = "IsJumping";
|
||||
[Tooltip("Bool parameter set while sprinting.")]
|
||||
[SerializeField] private string isSprinting = "IsSprinting";
|
||||
[Tooltip("Bool parameter set while in the crouch stance.")]
|
||||
[SerializeField] private string isCrouching = "IsCrouching";
|
||||
[Tooltip("Bool parameter set while in the prone stance.")]
|
||||
[SerializeField] private string isProne = "IsProne";
|
||||
[Tooltip("Bool parameter set while sliding.")]
|
||||
[SerializeField] private string isSliding = "IsSliding";
|
||||
|
||||
[Header("Int Parameters")]
|
||||
[Tooltip("Int parameter receiving the PlayerStance value (0 standing, 1 crouching, 2 prone).")]
|
||||
[SerializeField] private string stance = "Stance";
|
||||
[Tooltip("Int parameter receiving the CharacterAnimationState value.")]
|
||||
[SerializeField] private string movementState = "MovementState";
|
||||
|
||||
[Header("Trigger Parameters")]
|
||||
[Tooltip("Trigger fired when a jump launches.")]
|
||||
[SerializeField] private string jumpStarted = "JumpStarted";
|
||||
[Tooltip("Trigger fired on touchdown.")]
|
||||
[SerializeField] private string landed = "Landed";
|
||||
[Tooltip("Trigger fired when a slide begins.")]
|
||||
[SerializeField] private string slideStarted = "SlideStarted";
|
||||
[Tooltip("Trigger fired when a slide ends.")]
|
||||
[SerializeField] private string slideEnded = "SlideEnded";
|
||||
[Tooltip("Trigger fired when a vault begins.")]
|
||||
[SerializeField] private string vaultStarted = "VaultStarted";
|
||||
[Tooltip("Trigger fired when a vault ends.")]
|
||||
[SerializeField] private string vaultEnded = "VaultEnded";
|
||||
[Tooltip("Trigger fired when an add-on module reports a mantle starting.")]
|
||||
[SerializeField] private string mantleStarted = "MantleStarted";
|
||||
[Tooltip("Trigger fired when an add-on module reports a mantle ending.")]
|
||||
[SerializeField] private string mantleEnded = "MantleEnded";
|
||||
|
||||
public string Speed => speed;
|
||||
public string PlanarSpeed => planarSpeed;
|
||||
public string NormalizedSpeed => normalizedSpeed;
|
||||
public string Forward => forward;
|
||||
public string Strafe => strafe;
|
||||
public string IsGrounded => isGrounded;
|
||||
public string IsFalling => isFalling;
|
||||
public string IsJumping => isJumping;
|
||||
public string IsSprinting => isSprinting;
|
||||
public string IsCrouching => isCrouching;
|
||||
public string IsProne => isProne;
|
||||
public string IsSliding => isSliding;
|
||||
public string Stance => stance;
|
||||
public string MovementState => movementState;
|
||||
public string JumpStarted => jumpStarted;
|
||||
public string Landed => landed;
|
||||
public string SlideStarted => slideStarted;
|
||||
public string SlideEnded => slideEnded;
|
||||
public string VaultStarted => vaultStarted;
|
||||
public string VaultEnded => vaultEnded;
|
||||
public string MantleStarted => mantleStarted;
|
||||
public string MantleEnded => mantleEnded;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48eb654a49d14d5998664661cf5b635e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 367142
|
||||
packageName: "MotionCore \u2013 Physics Character Controller"
|
||||
packageVersion: 1.2
|
||||
assetPath: Assets/Character Controller/Core/Scripts/Animation/CharacterAnimatorParameters.cs
|
||||
uploadId: 997018
|
||||
Reference in new issue
Block a user