diff options
Diffstat (limited to 'ActiveRagdoll/Assets/TABG/Scripts')
13 files changed, 313 insertions, 16 deletions
diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Action/Movement.cs b/ActiveRagdoll/Assets/TABG/Scripts/Action/Movement.cs index 47de9de..781e998 100644 --- a/ActiveRagdoll/Assets/TABG/Scripts/Action/Movement.cs +++ b/ActiveRagdoll/Assets/TABG/Scripts/Action/Movement.cs @@ -7,17 +7,7 @@ namespace Rigging.Action public class Movement : RiggingActionBase { - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } + } }
\ No newline at end of file diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Animation.meta b/ActiveRagdoll/Assets/TABG/Scripts/Animation.meta new file mode 100644 index 0000000..c84ea3c --- /dev/null +++ b/ActiveRagdoll/Assets/TABG/Scripts/Animation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e6f95a4760ae6e34cab133aee596a3c6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs b/ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs new file mode 100644 index 0000000..9e9039f --- /dev/null +++ b/ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs @@ -0,0 +1,153 @@ +using Rigging.Data; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Events; + +namespace Rigging.Animations +{ + + // 物理控制的动作 + public class AnimationObject : MonoBehaviour + { + + public PhysicsAnimation[] animations; + + private Rigidbody rig; + + private StepHandler stepHandler; + + private Transform hip; + + public float smoothing; + + public float multiplier = 1f; + + private bool isCurrentlyLeft; + + public bool isLeft; + + public UnityEvent switchToForwardEvent; + + public UnityEvent switchToBackwardsEvent; + + public bool dontAnimateIfHoldingSomething; + + //private Holding holding; + + private AnimationHandler animationHandler; + + //private PlayerDeath death; + + private float muscleMultiplier = 1f; + + private void Start() + { + animationHandler = base.transform.root.GetComponent<AnimationHandler>(); + rig = GetComponent<Rigidbody>(); + stepHandler = base.transform.root.GetComponent<StepHandler>(); + //holding = base.transform.root.GetComponent<Holding>(); + //death = base.transform.root.GetComponent<PlayerDeath>(); + Hip componentInChildren = base.transform.root.GetComponentInChildren<Hip>(); + if ((bool)componentInChildren) + { + hip = componentInChildren.transform; + } + } + + private void FixedUpdate() + { + //if ((bool)death) + //{ + // if (death.muscleFunction < 0f) + // { + // return; + // } + // muscleMultiplier = death.muscleFunction; + //} + //if ((!holding || !dontAnimateIfHoldingSomething || !holding.heldObject) && animationHandler.animationState < animations.Length) + //{ + // SetMultiplier(); + // AddTorque(); + // AddForce(); + //} + SetMultiplier(); + AddTorque(); + AddForce(); + } + + private void AddForce() + { + Vector3 vector = Vector3.zero; + if (isCurrentlyLeft == isLeft) + { + Vector3 forwardForce = animations[animationHandler.animationState].forwardForce; + if (animations[animationHandler.animationState].forceSpace == PhysicsAnimation.ForceSpace.World) + { + vector = forwardForce; + } + if (animations[animationHandler.animationState].forceSpace == PhysicsAnimation.ForceSpace.Hip) + { + vector = hip.TransformDirection(forwardForce); + } + } + else + { + Vector3 backwardsForce = animations[animationHandler.animationState].backwardsForce; + if (animations[animationHandler.animationState].forceSpace == PhysicsAnimation.ForceSpace.World) + { + vector = backwardsForce; + } + if (animations[animationHandler.animationState].forceSpace == PhysicsAnimation.ForceSpace.Hip) + { + vector = hip.TransformDirection(backwardsForce); + } + } + rig.AddForce(vector * muscleMultiplier * multiplier, ForceMode.Acceleration); + } + + private void AddTorque() + { + Vector3 vector = ((isCurrentlyLeft != isLeft) ? hip.TransformDirection(animations[animationHandler.animationState].backwardsTorque) : hip.TransformDirection(animations[animationHandler.animationState].forwardTorque)); + rig.AddTorque(vector * muscleMultiplier * multiplier, ForceMode.Acceleration); + } + + private void SetMultiplier() + { + if (smoothing != 0f) + { + float b = 1f; + if (isCurrentlyLeft != stepHandler.isLeft) + { + b = 0f; + } + multiplier = Mathf.Lerp(multiplier, b, 1f / smoothing); + if (multiplier < 0.1f) + { + ChangeStep(); + } + } + else + { + ChangeStep(); + } + } + + private void ChangeStep() + { + if (isCurrentlyLeft != stepHandler.isLeft) + { + if (stepHandler.isLeft == isLeft) + { + switchToForwardEvent.Invoke(); + } + else + { + switchToBackwardsEvent.Invoke(); + } + isCurrentlyLeft = stepHandler.isLeft; + } + } + } + +} diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs.meta b/ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs.meta new file mode 100644 index 0000000..36fa9ba --- /dev/null +++ b/ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1f7b7bd465add9742bc770683eb2f98f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Animation/DragHandler.cs b/ActiveRagdoll/Assets/TABG/Scripts/Animation/DragHandler.cs new file mode 100644 index 0000000..7528f57 --- /dev/null +++ b/ActiveRagdoll/Assets/TABG/Scripts/Animation/DragHandler.cs @@ -0,0 +1,33 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Rigging.Animations +{ + + public class DragHandler : MonoBehaviour + { + + private float drag; + + private float angularDrag; + + private Rigidbody rig; + + public float dragAmount = 1f; + + private void Start() + { + rig = GetComponent<Rigidbody>(); + drag = rig.drag; + angularDrag = rig.angularDrag; + } + + private void Update() + { + rig.drag = drag * dragAmount; + rig.angularDrag = angularDrag * dragAmount; + } + } + +} diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Animation/DragHandler.cs.meta b/ActiveRagdoll/Assets/TABG/Scripts/Animation/DragHandler.cs.meta new file mode 100644 index 0000000..a7afaa0 --- /dev/null +++ b/ActiveRagdoll/Assets/TABG/Scripts/Animation/DragHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4c70169cb02b3a440ac55da69e72be2d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Animation/PhysicsAnimation.cs b/ActiveRagdoll/Assets/TABG/Scripts/Animation/PhysicsAnimation.cs new file mode 100644 index 0000000..b0521c9 --- /dev/null +++ b/ActiveRagdoll/Assets/TABG/Scripts/Animation/PhysicsAnimation.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Rigging.Animations +{ + [Serializable] + public class PhysicsAnimation + { + public enum TorqueSpace + { + World, + Local, + Parent, + Hip + } + + public enum ForceSpace + { + World, + Local, + Parent, + Hip + } + + [Header("TORQUES")] + public Vector3 forwardTorque; + + public Vector3 backwardsTorque; + + public TorqueSpace torqueSpace; + + [Header("FORCES")] + public Vector3 forwardForce; + + public Vector3 backwardsForce; + + public ForceSpace forceSpace; + } + + +} diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Animation/PhysicsAnimation.cs.meta b/ActiveRagdoll/Assets/TABG/Scripts/Animation/PhysicsAnimation.cs.meta new file mode 100644 index 0000000..113878e --- /dev/null +++ b/ActiveRagdoll/Assets/TABG/Scripts/Animation/PhysicsAnimation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3ec401472b5871a448f2b4212447cb38 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Animation/StartRotation.cs b/ActiveRagdoll/Assets/TABG/Scripts/Animation/StartRotation.cs new file mode 100644 index 0000000..1256dde --- /dev/null +++ b/ActiveRagdoll/Assets/TABG/Scripts/Animation/StartRotation.cs @@ -0,0 +1,26 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Rigging.Animations +{ + + // 记录初始rotation + public class StartRotation : MonoBehaviour + { + public Quaternion startRotation; + + public Quaternion startRotationLocal; + + private void Start() + { + startRotation = base.transform.rotation; + startRotationLocal = base.transform.localRotation; + } + + private void Update() + { + } + } + +} diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Animation/StartRotation.cs.meta b/ActiveRagdoll/Assets/TABG/Scripts/Animation/StartRotation.cs.meta new file mode 100644 index 0000000..0488045 --- /dev/null +++ b/ActiveRagdoll/Assets/TABG/Scripts/Animation/StartRotation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 955e6a7dcac3f0f4c84ea79136fddc01 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Data/AnimationHandler.cs b/ActiveRagdoll/Assets/TABG/Scripts/Data/AnimationHandler.cs index 6591e45..7a1a9f7 100644 --- a/ActiveRagdoll/Assets/TABG/Scripts/Data/AnimationHandler.cs +++ b/ActiveRagdoll/Assets/TABG/Scripts/Data/AnimationHandler.cs @@ -20,8 +20,8 @@ namespace Rigging.Data { /* 0 Stand - 1 Sprint - 2 Run + 1 Run + 2 Sprint 3 Jump */ public IntString[] animationStates; diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Data/SetAnimationByInput.cs b/ActiveRagdoll/Assets/TABG/Scripts/Data/SetAnimationByInput.cs index 3a90eb6..98444e3 100644 --- a/ActiveRagdoll/Assets/TABG/Scripts/Data/SetAnimationByInput.cs +++ b/ActiveRagdoll/Assets/TABG/Scripts/Data/SetAnimationByInput.cs @@ -31,11 +31,11 @@ namespace Rigging.Data { if (input.isSpringting) { - anim.animationState = 1; // sprint + anim.animationState = 2; // sprint } else { - anim.animationState = 2; // run + anim.animationState = 1; // run } } else diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs b/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs index e04ff0d..f35f068 100644 --- a/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs +++ b/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs @@ -61,5 +61,5 @@ namespace Rigging.Data } } - + }
\ No newline at end of file |