summaryrefslogtreecommitdiff
path: root/ActiveRagdoll/Assets/TABG/Scripts/Animation
diff options
context:
space:
mode:
Diffstat (limited to 'ActiveRagdoll/Assets/TABG/Scripts/Animation')
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs153
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs.meta11
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Animation/DragHandler.cs33
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Animation/DragHandler.cs.meta11
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Animation/PhysicsAnimation.cs43
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Animation/PhysicsAnimation.cs.meta11
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Animation/StartRotation.cs26
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Animation/StartRotation.cs.meta11
8 files changed, 299 insertions, 0 deletions
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: