Added Feel plugin
This commit is contained in:
57
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMAnimationModifier.cs
vendored
Normal file
57
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMAnimationModifier.cs
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Add this script to an animation in Mecanim and you'll be able to control its start position and speed
|
||||
/// </summary>
|
||||
[AddComponentMenu("More Mountains/Tools/Animation/MM Animation Modifier")]
|
||||
public class MMAnimationModifier : StateMachineBehaviour
|
||||
{
|
||||
[MMVectorAttribute("Min", "Max")]
|
||||
/// the min and max values for the start position of the animation (between 0 and 1)
|
||||
public Vector2 StartPosition = new Vector2(0, 0);
|
||||
|
||||
[MMVectorAttribute("Min", "Max")]
|
||||
/// the min and max values for the animation speed (1 is normal)
|
||||
public Vector2 AnimationSpeed = new Vector2(1, 1);
|
||||
|
||||
protected bool _enteredState = false;
|
||||
protected float _initialSpeed;
|
||||
|
||||
/// <summary>
|
||||
/// On state enter, we modify our speed and start position
|
||||
/// </summary>
|
||||
/// <param name="animator"></param>
|
||||
/// <param name="stateInfo"></param>
|
||||
/// <param name="layerIndex"></param>
|
||||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
base.OnStateEnter(animator, stateInfo, layerIndex);
|
||||
|
||||
// handle speed
|
||||
_initialSpeed = animator.speed;
|
||||
animator.speed = Random.Range(AnimationSpeed.x, AnimationSpeed.y);
|
||||
|
||||
// handle start position
|
||||
if (!_enteredState)
|
||||
{
|
||||
animator.Play(stateInfo.fullPathHash, layerIndex, Random.Range(StartPosition.x, StartPosition.y));
|
||||
}
|
||||
_enteredState = !_enteredState;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On state exit, we restore our speed
|
||||
/// </summary>
|
||||
/// <param name="animator"></param>
|
||||
/// <param name="stateInfo"></param>
|
||||
/// <param name="layerIndex"></param>
|
||||
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
base.OnStateExit(animator, stateInfo, layerIndex);
|
||||
animator.speed = _initialSpeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMAnimationModifier.cs.meta
vendored
Normal file
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMAnimationModifier.cs.meta
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ba4bd496d6656d4da1541ce7071ed10
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 183370
|
||||
packageName: Feel
|
||||
packageVersion: 5.9.1
|
||||
assetPath: Assets/Feel/MMTools/Foundation/MMAnimation/MMAnimationModifier.cs
|
||||
uploadId: 830868
|
||||
68
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMAnimationParameter.cs
vendored
Normal file
68
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMAnimationParameter.cs
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper class that will hash a animation parameter and update it on demand
|
||||
/// </summary>
|
||||
[AddComponentMenu("More Mountains/Tools/Animation/MM Animation Parameter")]
|
||||
public class MMAnimationParameter : MonoBehaviour
|
||||
{
|
||||
/// the name of the animation parameter to hash
|
||||
public string ParameterName;
|
||||
/// the animator to update
|
||||
public Animator TargetAnimator;
|
||||
|
||||
protected int _parameter;
|
||||
|
||||
/// <summary>
|
||||
/// On awake we initialize our class
|
||||
/// </summary>
|
||||
protected virtual void Awake()
|
||||
{
|
||||
Initialization();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hashes the parameter name into an int
|
||||
/// </summary>
|
||||
protected virtual void Initialization()
|
||||
{
|
||||
_parameter = Animator.StringToHash(ParameterName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the trigger of the specified name
|
||||
/// </summary>
|
||||
public virtual void SetTrigger()
|
||||
{
|
||||
TargetAnimator.SetTrigger(_parameter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the int of the specified name to the specified value
|
||||
/// </summary>
|
||||
public virtual void SetInt(int value)
|
||||
{
|
||||
TargetAnimator.SetInteger(_parameter, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the float of the specified name to the specified value
|
||||
/// </summary>
|
||||
public virtual void SetFloat(float value)
|
||||
{
|
||||
TargetAnimator.SetFloat(_parameter, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the bool of the specified name to the specified value
|
||||
/// </summary>
|
||||
public virtual void SetBool(bool value)
|
||||
{
|
||||
TargetAnimator.SetBool(_parameter, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMAnimationParameter.cs.meta
vendored
Normal file
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMAnimationParameter.cs.meta
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5451e999c8f9dfb41aa3b2894ffc3d60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 183370
|
||||
packageName: Feel
|
||||
packageVersion: 5.9.1
|
||||
assetPath: Assets/Feel/MMTools/Foundation/MMAnimation/MMAnimationParameter.cs
|
||||
uploadId: 830868
|
||||
133
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMAnimatorMirror.cs
vendored
Normal file
133
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMAnimatorMirror.cs
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// This class will let you mirror the behaviour of an Animator's parameters on a Source Animator onto the ones of a Target Animator.
|
||||
/// Target will mirror Source.
|
||||
/// Only the parameters existing on both Target and Source will be considered, you'll need to have the same on both before entering runtime.
|
||||
/// </summary>
|
||||
public class MMAnimatorMirror : MonoBehaviour
|
||||
{
|
||||
/// a struct used to store bindings
|
||||
public struct MMAnimatorMirrorBind
|
||||
{
|
||||
public int ParameterHash;
|
||||
public AnimatorControllerParameterType ParameterType;
|
||||
}
|
||||
|
||||
[Header("Bindings")]
|
||||
/// the animator to mirror
|
||||
public Animator SourceAnimator;
|
||||
/// the animator to mirror to
|
||||
public Animator TargetAnimator;
|
||||
|
||||
protected AnimatorControllerParameter[] _sourceParameters;
|
||||
protected AnimatorControllerParameter[] _targetParameters;
|
||||
protected List<MMAnimatorMirrorBind> _updateParameters;
|
||||
|
||||
/// <summary>
|
||||
/// On Awake we initialize
|
||||
/// </summary>
|
||||
protected virtual void Awake()
|
||||
{
|
||||
Initialization();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stores animation parameters hashes
|
||||
/// </summary>
|
||||
public virtual void Initialization()
|
||||
{
|
||||
if (TargetAnimator == null)
|
||||
{
|
||||
TargetAnimator = this.gameObject.GetComponent<Animator>();
|
||||
}
|
||||
|
||||
if ((TargetAnimator == null) || (SourceAnimator == null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// we store our source parameters
|
||||
int numberOfParameters = SourceAnimator.parameterCount;
|
||||
_sourceParameters = new AnimatorControllerParameter[numberOfParameters];
|
||||
for (int i = 0; i < numberOfParameters; i++)
|
||||
{
|
||||
_sourceParameters[i] = SourceAnimator.GetParameter(i);
|
||||
}
|
||||
|
||||
// we store our target parameters
|
||||
numberOfParameters = TargetAnimator.parameterCount;
|
||||
_targetParameters = new AnimatorControllerParameter[numberOfParameters];
|
||||
for (int i = 0; i < numberOfParameters; i++)
|
||||
{
|
||||
_targetParameters[i] = TargetAnimator.GetParameter(i);
|
||||
}
|
||||
|
||||
// we store our matching parameters
|
||||
_updateParameters = new List<MMAnimatorMirrorBind>();
|
||||
|
||||
foreach (AnimatorControllerParameter sourceParam in _sourceParameters)
|
||||
{
|
||||
foreach (AnimatorControllerParameter targetParam in _targetParameters)
|
||||
{
|
||||
if (sourceParam.name == targetParam.name)
|
||||
{
|
||||
MMAnimatorMirrorBind bind = new MMAnimatorMirrorBind();
|
||||
bind.ParameterHash = sourceParam.nameHash;
|
||||
bind.ParameterType = sourceParam.type;
|
||||
_updateParameters.Add(bind);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On Update we mirror our behaviours
|
||||
/// </summary>
|
||||
protected virtual void Update()
|
||||
{
|
||||
Mirror();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies animation parameter states from one animator to the other
|
||||
/// </summary>
|
||||
protected virtual void Mirror()
|
||||
{
|
||||
if ((TargetAnimator == null) || (SourceAnimator == null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (MMAnimatorMirrorBind bind in _updateParameters)
|
||||
{
|
||||
switch (bind.ParameterType)
|
||||
{
|
||||
case AnimatorControllerParameterType.Bool:
|
||||
TargetAnimator.SetBool(bind.ParameterHash, SourceAnimator.GetBool(bind.ParameterHash));
|
||||
break;
|
||||
case AnimatorControllerParameterType.Float:
|
||||
TargetAnimator.SetFloat(bind.ParameterHash, SourceAnimator.GetFloat(bind.ParameterHash));
|
||||
break;
|
||||
case AnimatorControllerParameterType.Int:
|
||||
TargetAnimator.SetInteger(bind.ParameterHash, SourceAnimator.GetInteger(bind.ParameterHash));
|
||||
break;
|
||||
case AnimatorControllerParameterType.Trigger:
|
||||
if (SourceAnimator.GetBool(bind.ParameterHash))
|
||||
{
|
||||
TargetAnimator.SetTrigger(bind.ParameterHash);
|
||||
}
|
||||
else
|
||||
{
|
||||
TargetAnimator.ResetTrigger(bind.ParameterHash);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMAnimatorMirror.cs.meta
vendored
Normal file
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMAnimatorMirror.cs.meta
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5d1374627ebc7d4491c7eb256713f69
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 183370
|
||||
packageName: Feel
|
||||
packageVersion: 5.9.1
|
||||
assetPath: Assets/Feel/MMTools/Foundation/MMAnimation/MMAnimatorMirror.cs
|
||||
uploadId: 830868
|
||||
74
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMOffsetAnimation.cs
vendored
Normal file
74
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMOffsetAnimation.cs
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Use this class to offset an animation by a random range
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Animator))]
|
||||
[AddComponentMenu("More Mountains/Tools/Animation/MM Offset Animation")]
|
||||
public class MMOffsetAnimation : MonoBehaviour
|
||||
{
|
||||
/// the minimum amount (in seconds) by which to offset the animation
|
||||
public float MinimumRandomRange = 0f;
|
||||
/// the maximum amount (in seconds) by which to offset the animation
|
||||
public float MaximumRandomRange = 1f;
|
||||
/// the layer to affect
|
||||
public int AnimationLayerID = 0;
|
||||
/// whether or not to apply that offset on Start
|
||||
public bool OffsetOnStart = true;
|
||||
/// whether or not to offset animation on enable
|
||||
public bool OffsetOnEnable = false;
|
||||
/// whether or not to self disable after offsetting
|
||||
public bool DisableAfterOffset = true;
|
||||
|
||||
protected Animator _animator;
|
||||
protected AnimatorStateInfo _stateInfo;
|
||||
|
||||
/// <summary>
|
||||
/// On awake we store our animator
|
||||
/// </summary>
|
||||
protected virtual void Awake()
|
||||
{
|
||||
_animator = this.gameObject.GetComponent<Animator>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On Start we offset our animation
|
||||
/// </summary>
|
||||
protected virtual void Start()
|
||||
{
|
||||
if (!OffsetOnStart)
|
||||
{
|
||||
return;
|
||||
}
|
||||
OffsetCurrentAnimation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On Enable we offset our animation if needed
|
||||
/// </summary>
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
if (!OffsetOnEnable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
OffsetCurrentAnimation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// offsets the target animation
|
||||
/// </summary>
|
||||
public virtual void OffsetCurrentAnimation()
|
||||
{
|
||||
_stateInfo = _animator.GetCurrentAnimatorStateInfo(AnimationLayerID);
|
||||
_animator.Play(_stateInfo.fullPathHash, -1, Random.Range(MinimumRandomRange, MaximumRandomRange));
|
||||
if (DisableAfterOffset)
|
||||
{
|
||||
this.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMOffsetAnimation.cs.meta
vendored
Normal file
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMOffsetAnimation.cs.meta
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c77c6d59898ea34989b338214db7de1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 183370
|
||||
packageName: Feel
|
||||
packageVersion: 5.9.1
|
||||
assetPath: Assets/Feel/MMTools/Foundation/MMAnimation/MMOffsetAnimation.cs
|
||||
uploadId: 830868
|
||||
326
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMRagdoller.cs
vendored
Normal file
326
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMRagdoller.cs
vendored
Normal file
@@ -0,0 +1,326 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// A class used to store ragdoll body parts informations
|
||||
/// </summary>
|
||||
public class RagdollBodyPart
|
||||
{
|
||||
public Transform BodyPartTransform;
|
||||
public Vector3 StoredPosition;
|
||||
public Quaternion StoredRotation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this class to pilot a ragdoll on a character that is usually driven by an animator and have it fall elegantly
|
||||
/// If you have parts of your ragdoll that you don't want to be affected by this script (a weapon for example), just add a MMRagdollerIgnore component to them
|
||||
/// </summary>
|
||||
[AddComponentMenu("More Mountains/Tools/Animation/MM Ragdoller")]
|
||||
public class MMRagdoller : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// The possible states of the ragdoll :
|
||||
/// - animated : driven by an animator controller, rigidbodies asleep
|
||||
/// - ragdolling : full ragdoll mode, purely physics driven
|
||||
/// - blending : transitioning between ragdolling and animated
|
||||
/// </summary>
|
||||
public enum RagdollStates
|
||||
{
|
||||
Animated,
|
||||
Ragdolling,
|
||||
Blending
|
||||
}
|
||||
|
||||
[Header("Ragdoll")]
|
||||
/// the current state of the ragdoll
|
||||
public RagdollStates CurrentState = RagdollStates.Animated;
|
||||
/// the duration in seconds it takes to blend from Ragdolling to Animated
|
||||
public float RagdollToMecanimBlendDuration = 0.5f;
|
||||
|
||||
[Header("Rigidbodies")]
|
||||
/// The rigidbody attached to the main body part of the ragdoll (usually the Pelvis)
|
||||
public Rigidbody MainRigidbody;
|
||||
/// if this is true, all rigidbodies will be forced to sleep every frame
|
||||
public bool ForceSleep = true;
|
||||
/// whether or not blending will occur when going from ragdolling to animated
|
||||
public bool AllowBlending = true;
|
||||
|
||||
protected float _mecanimToGetUpTransitionTime = 0.05f;
|
||||
protected float _ragdollingEndTimestamp = -float.MaxValue;
|
||||
protected Vector3 _ragdolledHipPosition;
|
||||
protected Vector3 _ragdolledHeadPosition;
|
||||
protected Vector3 _ragdolledFeetPosition;
|
||||
protected List<RagdollBodyPart> _bodyparts = new List<RagdollBodyPart>();
|
||||
protected Animator _animator;
|
||||
protected List<Component> _rigidbodiesTempList;
|
||||
protected Component[] _rigidbodies;
|
||||
protected HashSet<int> _animatorParameters;
|
||||
|
||||
protected const string _getUpFromBackAnimationParameterName = "GetUpFromBack";
|
||||
protected int _getUpFromBackAnimationParameter;
|
||||
protected const string _getUpFromBellyAnimationParameterName = "GetUpFromBelly";
|
||||
protected int _getUpFromBellyAnimationParameter;
|
||||
protected bool _initialized = false;
|
||||
|
||||
/// <summary>
|
||||
/// Use this to get the current state of the ragdoll or to set a new one
|
||||
/// </summary>
|
||||
public bool Ragdolling
|
||||
{
|
||||
get
|
||||
{
|
||||
// if we're not animated, we're ragdolling
|
||||
return CurrentState != RagdollStates.Animated;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == true)
|
||||
{
|
||||
// if we're
|
||||
if (CurrentState == RagdollStates.Animated)
|
||||
{
|
||||
SetIsKinematic(false);
|
||||
_animator.enabled = false;
|
||||
CurrentState = RagdollStates.Ragdolling;
|
||||
MMAnimatorExtensions.UpdateAnimatorBool(_animator, _getUpFromBackAnimationParameter, false, _animatorParameters);
|
||||
MMAnimatorExtensions.UpdateAnimatorBool(_animator, _getUpFromBellyAnimationParameter, false, _animatorParameters);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CurrentState == RagdollStates.Ragdolling)
|
||||
{
|
||||
SetIsKinematic(true);
|
||||
_ragdollingEndTimestamp = Time.time;
|
||||
_animator.enabled = true;
|
||||
|
||||
CurrentState = AllowBlending ? RagdollStates.Blending: RagdollStates.Animated;
|
||||
|
||||
|
||||
foreach (RagdollBodyPart bodypart in _bodyparts)
|
||||
{
|
||||
bodypart.StoredRotation = bodypart.BodyPartTransform.rotation;
|
||||
bodypart.StoredPosition = bodypart.BodyPartTransform.position;
|
||||
}
|
||||
|
||||
_ragdolledFeetPosition = 0.5f * (_animator.GetBoneTransform(HumanBodyBones.LeftToes).position + _animator.GetBoneTransform(HumanBodyBones.RightToes).position);
|
||||
_ragdolledHeadPosition = _animator.GetBoneTransform(HumanBodyBones.Head).position;
|
||||
_ragdolledHipPosition = _animator.GetBoneTransform(HumanBodyBones.Hips).position;
|
||||
|
||||
if (_animator.GetBoneTransform(HumanBodyBones.Hips).forward.y > 0)
|
||||
{
|
||||
MMAnimatorExtensions.UpdateAnimatorBool(_animator, _getUpFromBackAnimationParameter, true, _animatorParameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
MMAnimatorExtensions.UpdateAnimatorBool(_animator, _getUpFromBellyAnimationParameter, true, _animatorParameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On start we initialize our ragdoller
|
||||
/// </summary>
|
||||
protected virtual void Start()
|
||||
{
|
||||
Initialization();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs rigidbodies, adds body parts and stores the animator
|
||||
/// </summary>
|
||||
protected virtual void Initialization()
|
||||
{
|
||||
// we grab all rigidbodies and set them to kinematic
|
||||
_rigidbodies = GetComponentsInChildren(typeof(Rigidbody));
|
||||
|
||||
_rigidbodiesTempList = new List<Component>();
|
||||
foreach (Component rigidbody in _rigidbodies)
|
||||
{
|
||||
if (rigidbody.gameObject.MMGetComponentNoAlloc<MMRagdollerIgnore>() == null)
|
||||
{
|
||||
_rigidbodiesTempList.Add(rigidbody);
|
||||
}
|
||||
}
|
||||
|
||||
_rigidbodies = null;
|
||||
_rigidbodies = _rigidbodiesTempList.ToArray();
|
||||
|
||||
|
||||
if (CurrentState == RagdollStates.Animated)
|
||||
{
|
||||
SetIsKinematic(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetIsKinematic(false);
|
||||
}
|
||||
|
||||
// we grab all transforms and add a RagdollBodyPart to them
|
||||
Component[] transforms = GetComponentsInChildren(typeof(Transform));
|
||||
foreach (Component component in transforms)
|
||||
{
|
||||
if (component.transform != this.transform)
|
||||
{
|
||||
RagdollBodyPart bodyPart = new RagdollBodyPart { BodyPartTransform = component as Transform };
|
||||
_bodyparts.Add(bodyPart);
|
||||
}
|
||||
}
|
||||
|
||||
// we store our animator
|
||||
_animator = this.gameObject.GetComponent<Animator>();
|
||||
RegisterAnimatorParameters();
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers our animation parameters
|
||||
/// </summary>
|
||||
protected virtual void RegisterAnimatorParameters()
|
||||
{
|
||||
_animatorParameters = new HashSet<int>();
|
||||
|
||||
_getUpFromBackAnimationParameter = Animator.StringToHash(_getUpFromBackAnimationParameterName);
|
||||
_getUpFromBellyAnimationParameter = Animator.StringToHash(_getUpFromBellyAnimationParameterName);
|
||||
|
||||
if (_animator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_animator.MMHasParameterOfType(_getUpFromBackAnimationParameterName, AnimatorControllerParameterType.Bool))
|
||||
{
|
||||
_animatorParameters.Add(_getUpFromBackAnimationParameter);
|
||||
}
|
||||
if (_animator.MMHasParameterOfType(_getUpFromBellyAnimationParameterName, AnimatorControllerParameterType.Bool))
|
||||
{
|
||||
_animatorParameters.Add(_getUpFromBellyAnimationParameter);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets all rigidbodies in the ragdoll to kinematic and stops them from detecting collisions (or the other way around)
|
||||
/// </summary>
|
||||
/// <param name="isKinematic"></param>
|
||||
protected virtual void SetIsKinematic(bool isKinematic)
|
||||
{
|
||||
foreach (Component rigidbody in _rigidbodies)
|
||||
{
|
||||
if (rigidbody.transform != this.transform)
|
||||
{
|
||||
(rigidbody as Rigidbody).detectCollisions = !isKinematic;
|
||||
(rigidbody as Rigidbody).isKinematic = isKinematic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forces all rigidbodies in the ragdoll to sleep
|
||||
/// </summary>
|
||||
public virtual void ForceRigidbodiesToSleep()
|
||||
{
|
||||
foreach (Component rigidbody in _rigidbodies)
|
||||
{
|
||||
if (rigidbody.transform != this.transform)
|
||||
{
|
||||
(rigidbody as Rigidbody).Sleep();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On late update, we force our ragdoll elements to sleep and handle blending
|
||||
/// </summary>
|
||||
protected virtual void LateUpdate()
|
||||
{
|
||||
if ((CurrentState == RagdollStates.Animated) && ForceSleep)
|
||||
{
|
||||
ForceRigidbodiesToSleep();
|
||||
}
|
||||
|
||||
HandleBlending();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Blends between ragdolling and animated and switches to Animated at the end
|
||||
/// </summary>
|
||||
protected virtual void HandleBlending()
|
||||
{
|
||||
if (CurrentState == RagdollStates.Blending)
|
||||
{
|
||||
if (Time.time <= _ragdollingEndTimestamp + _mecanimToGetUpTransitionTime)
|
||||
{
|
||||
transform.position = GetRootPosition();
|
||||
|
||||
Vector3 ragdollingDirection = _ragdolledHeadPosition - _ragdolledFeetPosition;
|
||||
ragdollingDirection.y = 0;
|
||||
|
||||
Vector3 meanFeetPosition = 0.5f * (_animator.GetBoneTransform(HumanBodyBones.LeftFoot).position + _animator.GetBoneTransform(HumanBodyBones.RightFoot).position);
|
||||
Vector3 animatedDirection = _animator.GetBoneTransform(HumanBodyBones.Head).position - meanFeetPosition;
|
||||
animatedDirection.y = 0;
|
||||
|
||||
transform.rotation *= Quaternion.FromToRotation(animatedDirection.normalized, ragdollingDirection.normalized);
|
||||
}
|
||||
float ragdollBlendAmount = 1.0f - (Time.time - _ragdollingEndTimestamp - _mecanimToGetUpTransitionTime) / RagdollToMecanimBlendDuration;
|
||||
ragdollBlendAmount = Mathf.Clamp01(ragdollBlendAmount);
|
||||
|
||||
foreach (RagdollBodyPart bodypart in _bodyparts)
|
||||
{
|
||||
if (bodypart.BodyPartTransform != transform)
|
||||
{
|
||||
if (bodypart.BodyPartTransform == _animator.GetBoneTransform(HumanBodyBones.Hips))
|
||||
{
|
||||
bodypart.BodyPartTransform.position = Vector3.Lerp(bodypart.BodyPartTransform.position, bodypart.StoredPosition, ragdollBlendAmount);
|
||||
}
|
||||
bodypart.BodyPartTransform.rotation = Quaternion.Slerp(bodypart.BodyPartTransform.rotation, bodypart.StoredRotation, ragdollBlendAmount);
|
||||
}
|
||||
}
|
||||
|
||||
if (ragdollBlendAmount == 0)
|
||||
{
|
||||
CurrentState = RagdollStates.Animated;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current position of the ragdoll (technically the hips position)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Vector3 GetPosition()
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
Initialization();
|
||||
}
|
||||
Vector3 newPosition = (_animator.GetBoneTransform(HumanBodyBones.Hips) == null) ? MainRigidbody.position : _animator.GetBoneTransform(HumanBodyBones.Hips).position;
|
||||
return newPosition;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the offset root position
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected Vector3 GetRootPosition()
|
||||
{
|
||||
Vector3 ragdollPosition = (_animator.GetBoneTransform(HumanBodyBones.Hips) == null) ? MainRigidbody.position : _animator.GetBoneTransform(HumanBodyBones.Hips).position;
|
||||
Vector3 animatedToRagdolling = _ragdolledHipPosition - ragdollPosition;
|
||||
Vector3 newRootPosition = transform.position + animatedToRagdolling;
|
||||
RaycastHit[] hits = Physics.RaycastAll(new Ray(newRootPosition, Vector3.down));
|
||||
newRootPosition.y = 0;
|
||||
foreach (RaycastHit hit in hits)
|
||||
{
|
||||
if (!hit.transform.IsChildOf(transform))
|
||||
{
|
||||
newRootPosition.y = Mathf.Max(newRootPosition.y, hit.point.y);
|
||||
}
|
||||
}
|
||||
return newRootPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMRagdoller.cs.meta
vendored
Normal file
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMRagdoller.cs.meta
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9687a46a55ccbca4f92cdff319b70844
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 183370
|
||||
packageName: Feel
|
||||
packageVersion: 5.9.1
|
||||
assetPath: Assets/Feel/MMTools/Foundation/MMAnimation/MMRagdoller.cs
|
||||
uploadId: 830868
|
||||
15
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMRagdollerIgnore.cs
vendored
Normal file
15
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMRagdollerIgnore.cs
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Add this class to objects you'd like to be unaffected by the MMRagdoller (like weapons for example)
|
||||
/// </summary>
|
||||
[AddComponentMenu("More Mountains/Tools/Animation/MM Ragdoller Ignore")]
|
||||
public class MMRagdollerIgnore : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMRagdollerIgnore.cs.meta
vendored
Normal file
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMRagdollerIgnore.cs.meta
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38f5f99a403324842b72d7bb5d781405
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 183370
|
||||
packageName: Feel
|
||||
packageVersion: 5.9.1
|
||||
assetPath: Assets/Feel/MMTools/Foundation/MMAnimation/MMRagdollerIgnore.cs
|
||||
uploadId: 830868
|
||||
94
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMStopMotionAnimation.cs
vendored
Normal file
94
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMStopMotionAnimation.cs
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
[AddComponentMenu("More Mountains/Tools/Animation/MM Stop Motion Animation")]
|
||||
public class MMStopMotionAnimation : MonoBehaviour
|
||||
{
|
||||
public enum FramerateModes { Manual, Automatic }
|
||||
|
||||
[Header("General Settings")]
|
||||
public bool StopMotionEnabled = true;
|
||||
public int AnimationLayerID = 0;
|
||||
|
||||
[Header("Framerate")]
|
||||
public FramerateModes FramerateMode = FramerateModes.Automatic;
|
||||
|
||||
[MMEnumCondition("FramerateMode", (int)FramerateModes.Automatic)]
|
||||
public float FramesPerSecond = 4f;
|
||||
[MMEnumCondition("FramerateMode", (int)FramerateModes.Automatic)]
|
||||
public float PollFrequency = 1f;
|
||||
|
||||
[MMEnumCondition("FramerateMode", (int)FramerateModes.Manual)]
|
||||
public float ManualTimeBetweenFrames = 0.125f;
|
||||
[MMEnumCondition("FramerateMode", (int)FramerateModes.Manual)]
|
||||
public float ManualAnimatorSpeed = 2;
|
||||
|
||||
public float timet = 0;
|
||||
|
||||
protected float _currentClipFPS = 0;
|
||||
protected float _currentClipLength = 0f;
|
||||
protected float _lastPollAt = -10f;
|
||||
protected Animator _animator;
|
||||
protected AnimationClip _currentClip;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
_animator = this.gameObject.GetComponent<Animator>();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
StopMotion();
|
||||
|
||||
if (Time.time - _lastPollAt > PollFrequency)
|
||||
{
|
||||
Poll();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void StopMotion()
|
||||
{
|
||||
if (!StopMotionEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float timeBetweenFrames = 0f;
|
||||
float animatorSpeed = 0f;
|
||||
|
||||
switch(FramerateMode)
|
||||
{
|
||||
case FramerateModes.Manual:
|
||||
timeBetweenFrames = ManualTimeBetweenFrames;
|
||||
animatorSpeed = ManualAnimatorSpeed;
|
||||
break;
|
||||
case FramerateModes.Automatic:
|
||||
timeBetweenFrames = (1 / FramesPerSecond);
|
||||
animatorSpeed = (1 / (FramesPerSecond - 1)) * 2f * _currentClipFPS;
|
||||
break;
|
||||
}
|
||||
|
||||
timet += Time.deltaTime;
|
||||
if (timet > timeBetweenFrames)
|
||||
{
|
||||
timet -= timeBetweenFrames;
|
||||
_animator.speed = animatorSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_animator.speed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Poll()
|
||||
{
|
||||
_currentClip = _animator.GetCurrentAnimatorClipInfo(AnimationLayerID)[0].clip;
|
||||
_currentClipLength = _currentClip.length;
|
||||
_currentClipFPS = _currentClip.frameRate;
|
||||
_lastPollAt = Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMStopMotionAnimation.cs.meta
vendored
Normal file
18
Assets/External/Feel/MMTools/Foundation/MMAnimation/MMStopMotionAnimation.cs.meta
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 409ecbe35fc2afd4b82ade0142839256
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 183370
|
||||
packageName: Feel
|
||||
packageVersion: 5.9.1
|
||||
assetPath: Assets/Feel/MMTools/Foundation/MMAnimation/MMStopMotionAnimation.cs
|
||||
uploadId: 830868
|
||||
Reference in New Issue
Block a user