summaryrefslogtreecommitdiff
path: root/_ActiveRagdoll/Handlers
diff options
context:
space:
mode:
Diffstat (limited to '_ActiveRagdoll/Handlers')
-rw-r--r--_ActiveRagdoll/Handlers/AnimationHandler.cs9
-rw-r--r--_ActiveRagdoll/Handlers/DragHandler.cs26
-rw-r--r--_ActiveRagdoll/Handlers/FootHandler.cs75
-rw-r--r--_ActiveRagdoll/Handlers/HeadCollisionHandler.cs31
-rw-r--r--_ActiveRagdoll/Handlers/RagdollHandler.cs21
-rw-r--r--_ActiveRagdoll/Handlers/RigidbodyHolder.cs45
-rw-r--r--_ActiveRagdoll/Handlers/RotationHandler.cs73
-rw-r--r--_ActiveRagdoll/Handlers/StandingDataHandler.cs69
-rw-r--r--_ActiveRagdoll/Handlers/WeaponHandler.cs75
9 files changed, 423 insertions, 1 deletions
diff --git a/_ActiveRagdoll/Handlers/AnimationHandler.cs b/_ActiveRagdoll/Handlers/AnimationHandler.cs
index 382b3a5..437a8dd 100644
--- a/_ActiveRagdoll/Handlers/AnimationHandler.cs
+++ b/_ActiveRagdoll/Handlers/AnimationHandler.cs
@@ -3,7 +3,14 @@ using UnityEngine;
//Player AnimationHandler 记录当前动作状态编号
public class AnimationHandler : MonoBehaviour
{
- public int animationState;
+ /*
+ 0 Stand
+ 1 Sprint
+ 2 Run
+ 3 Jump
+ */
+
+ public int animationState;
private void Start()
{
diff --git a/_ActiveRagdoll/Handlers/DragHandler.cs b/_ActiveRagdoll/Handlers/DragHandler.cs
new file mode 100644
index 0000000..5f6556c
--- /dev/null
+++ b/_ActiveRagdoll/Handlers/DragHandler.cs
@@ -0,0 +1,26 @@
+using UnityEngine;
+
+// 设置当前骨骼的drag和angularDrag
+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/Handlers/FootHandler.cs b/_ActiveRagdoll/Handlers/FootHandler.cs
new file mode 100644
index 0000000..7343e21
--- /dev/null
+++ b/_ActiveRagdoll/Handlers/FootHandler.cs
@@ -0,0 +1,75 @@
+using UnityEngine;
+
+public class FootHandler : MonoBehaviour
+{
+ private AnimationHandler animHandler;
+
+ private Collider collider;
+
+ public PhysicMaterial slippery;
+
+ private PhysicMaterial footMaterial;
+
+ private Transform torso;
+
+ private MovementDataHandler moveData;
+
+ private Rigidbody rig;
+
+ private RotationHandler rot;
+
+ private Vector3 rotationDif;
+
+ private AnimationObject anim;
+
+ private StepHandler handler;
+
+ private void Start()
+ {
+ animHandler = base.transform.root.GetComponent<AnimationHandler>();
+ moveData = base.transform.root.GetComponent<MovementDataHandler>();
+ collider = GetComponentInChildren<Collider>();
+ rig = GetComponent<Rigidbody>();
+ footMaterial = collider.material;
+ torso = base.transform.root.GetComponentInChildren<Torso>().transform;
+ rot = base.transform.root.GetComponent<RotationHandler>();
+ handler = base.transform.root.GetComponent<StepHandler>();
+ anim = GetComponentInChildren<AnimationObject>();
+ }
+
+ private void Update()
+ {
+ float num = Mathf.Abs(torso.position.x - base.transform.position.x) + Mathf.Abs(torso.position.z - base.transform.position.z);
+ if (rot.hipCorrectionAmount > 30f || ((bool)anim && anim.isLeft != handler.isLeft))
+ {
+ SetFoot(active: false);
+ }
+ else if (animHandler.animationState == 0)
+ {
+ if (num > 0.1f || rotationDif.magnitude > 15f)
+ {
+ SetFoot(active: false);
+ }
+ else
+ {
+ SetFoot(active: true);
+ }
+ }
+ else
+ {
+ SetFoot(active: true);
+ }
+ }
+
+ private void FixedUpdate()
+ {
+ }
+
+ private void SetFoot(bool active)
+ {
+ if (active)
+ {
+ collider.material = footMaterial;
+ }
+ }
+}
diff --git a/_ActiveRagdoll/Handlers/HeadCollisionHandler.cs b/_ActiveRagdoll/Handlers/HeadCollisionHandler.cs
new file mode 100644
index 0000000..c929f0e
--- /dev/null
+++ b/_ActiveRagdoll/Handlers/HeadCollisionHandler.cs
@@ -0,0 +1,31 @@
+using UnityEngine;
+
+public class HeadCollisionHandler : MonoBehaviour
+{
+ public float collisionValue;
+
+ private void Start()
+ {
+ }
+
+ private void Update()
+ {
+ collisionValue = Mathf.Lerp(collisionValue, 0f, Time.deltaTime * 6f);
+ }
+
+ private void OnCollisionEnter(Collision collision)
+ {
+ if (!(collision.transform.root == base.transform.root))
+ {
+ collisionValue += collision.relativeVelocity.magnitude * 0.5f;
+ }
+ }
+
+ private void OnCollisionStay(Collision collision)
+ {
+ if (!(collision.transform.root == base.transform.root))
+ {
+ collisionValue += collision.relativeVelocity.magnitude * 0.1f;
+ }
+ }
+}
diff --git a/_ActiveRagdoll/Handlers/RagdollHandler.cs b/_ActiveRagdoll/Handlers/RagdollHandler.cs
new file mode 100644
index 0000000..29daa68
--- /dev/null
+++ b/_ActiveRagdoll/Handlers/RagdollHandler.cs
@@ -0,0 +1,21 @@
+using UnityEngine;
+
+public class RagdollHandler : MonoBehaviour
+{
+ public float ragdollValue = 1f;//1
+
+ private RigidbodyHolder rigs;//14
+
+ private void Start()
+ {
+ rigs = GetComponent<RigidbodyHolder>();
+ }
+
+ private void Update()
+ {
+ for (int i = 0; i < rigs.GetAllRigs().Length; i++)
+ {
+ rigs.GetAllRigs()[i].GetComponent<DragHandler>().dragAmount = ragdollValue;
+ }
+ }
+}
diff --git a/_ActiveRagdoll/Handlers/RigidbodyHolder.cs b/_ActiveRagdoll/Handlers/RigidbodyHolder.cs
new file mode 100644
index 0000000..3ef0c54
--- /dev/null
+++ b/_ActiveRagdoll/Handlers/RigidbodyHolder.cs
@@ -0,0 +1,45 @@
+using System.Collections.Generic;
+using UnityEngine;
+
+// 保存所有14个骨骼
+public class RigidbodyHolder : MonoBehaviour
+{
+ private Rigidbody[] allRigs;
+
+ private WeaponHandler weapons;
+
+ private void Start()
+ {
+ allRigs = GetComponentsInChildren<Rigidbody>();
+ weapons = GetComponent<WeaponHandler>();
+ }
+
+ private void Update()
+ {
+ }
+
+ public Rigidbody[] GetAllRigs()
+ {
+ if (!weapons.leftGun && !weapons.rightGun)
+ {
+ return allRigs;
+ }
+ List<Rigidbody> list = new List<Rigidbody>();
+ for (int i = 0; i < allRigs.Length; i++)
+ {
+ list.Add(allRigs[i]);
+ }
+ if ((bool)weapons)
+ {
+ if ((bool)weapons.leftGun)
+ {
+ list.Add(weapons.leftGun.rig);
+ }
+ if ((bool)weapons.rightGun)
+ {
+ list.Add(weapons.rightGun.rig);
+ }
+ }
+ return list.ToArray();
+ }
+}
diff --git a/_ActiveRagdoll/Handlers/RotationHandler.cs b/_ActiveRagdoll/Handlers/RotationHandler.cs
new file mode 100644
index 0000000..ee33545
--- /dev/null
+++ b/_ActiveRagdoll/Handlers/RotationHandler.cs
@@ -0,0 +1,73 @@
+using UnityEngine;
+
+public class RotationHandler : MonoBehaviour
+{
+ private Transform rotationTarget;
+
+ private Rigidbody hip;
+
+ private Rigidbody torso;
+
+ private Rigidbody head;
+
+ public float rotationTorque;
+
+ public float clamp;
+
+ private InputHandler input;
+
+ private PlayerDeath death;
+
+ [HideInInspector]
+ public float hipCorrectionAmount;
+
+ public bool useHip = true;
+
+ public bool useTorso = true;
+
+ public bool useHead = true;
+
+ private void Start()
+ {
+ death = GetComponent<PlayerDeath>();
+ rotationTarget = GetComponentInChildren<RotationTarget>().transform;
+ hip = GetComponentInChildren<Hip>().GetComponent<Rigidbody>();
+ torso = GetComponentInChildren<Torso>().GetComponent<Rigidbody>();
+ head = GetComponentInChildren<Head>().GetComponent<Rigidbody>();
+ input = GetComponent<InputHandler>();
+ }
+
+ private void FixedUpdate()
+ {
+ if (!death.dead)
+ {
+ float num = head.transform.InverseTransformPoint(rotationTarget.position).x;
+ float num2 = torso.transform.InverseTransformPoint(rotationTarget.position).x;
+ hipCorrectionAmount = hip.transform.InverseTransformPoint(hip.transform.position + input.lastInputDirection * 10f).x;
+ float muscleFunction = death.muscleFunction;
+ float num3 = 0.3f;
+ if (input.inputMovementDirection.magnitude > 0.1f)
+ {
+ num3 = 1f;
+ }
+ if (clamp != 0f)
+ {
+ hipCorrectionAmount = Mathf.Clamp(hipCorrectionAmount, 0f - clamp, clamp);
+ num = Mathf.Clamp(num, 0f - clamp, clamp);
+ num2 = Mathf.Clamp(num2, 0f - clamp, clamp);
+ }
+ if (useHip)
+ {
+ hip.AddTorque(Vector3.up * muscleFunction * rotationTorque * num3 * hipCorrectionAmount, ForceMode.Acceleration);
+ }
+ if (useTorso)
+ {
+ torso.AddTorque(Vector3.up * muscleFunction * rotationTorque * num2, ForceMode.Acceleration);
+ }
+ if (useHead)
+ {
+ head.AddTorque(Vector3.up * muscleFunction * rotationTorque * num, ForceMode.Acceleration);
+ }
+ }
+ }
+}
diff --git a/_ActiveRagdoll/Handlers/StandingDataHandler.cs b/_ActiveRagdoll/Handlers/StandingDataHandler.cs
new file mode 100644
index 0000000..a72ec09
--- /dev/null
+++ b/_ActiveRagdoll/Handlers/StandingDataHandler.cs
@@ -0,0 +1,69 @@
+using UnityEngine;
+
+public class StandingDataHandler : MonoBehaviour
+{
+ public Rigidbody mainRig;
+
+ public float sinceGrounded; // 离地时间
+
+ public float sinceLanded;
+
+ public bool isGrounded;
+
+ public float distanceToGround = 1f;
+
+ private bool hasRecievedTouchedGround;
+
+ private MovementDataHandler moveMentData;
+
+ private PlayerKnockback knockback;
+
+ private WobbleShake wobbleShake;
+
+ private void Start()
+ {
+ wobbleShake = GetComponentInChildren<WobbleShake>();
+ knockback = GetComponent<PlayerKnockback>();
+ }
+
+ private void FixedUpdate()
+ {
+ sinceGrounded += Time.fixedDeltaTime;
+ sinceLanded += Time.fixedDeltaTime;
+ moveMentData = GetComponent<MovementDataHandler>();
+ if ((double)sinceGrounded > 0.1)
+ {
+ isGrounded = false;
+ }
+ }
+
+ private void LateUpdate()
+ {
+ hasRecievedTouchedGround = false;
+ }
+
+ public void TouchGround(float distance, Vector3 normal)
+ {
+ if (sinceGrounded > 0.5f && (bool)wobbleShake)
+ {
+ wobbleShake.AddShake(-Vector3.up * 5f * Mathf.Pow(sinceGrounded, 1.5f), 0.8f);
+ }
+ if (sinceGrounded > 0.5f)
+ {
+ Land(sinceGrounded);
+ }
+ sinceGrounded = 0f;
+ isGrounded = true;
+ if (distance > distanceToGround || !hasRecievedTouchedGround)
+ {
+ distanceToGround = distance;
+ }
+ hasRecievedTouchedGround = true;
+ moveMentData.SetSlope(normal);
+ }
+
+ private void Land(float landForce)
+ {
+ sinceLanded = 0f;
+ }
+}
diff --git a/_ActiveRagdoll/Handlers/WeaponHandler.cs b/_ActiveRagdoll/Handlers/WeaponHandler.cs
new file mode 100644
index 0000000..7b3d80f
--- /dev/null
+++ b/_ActiveRagdoll/Handlers/WeaponHandler.cs
@@ -0,0 +1,75 @@
+using UnityEngine;
+
+public class WeaponHandler : MonoBehaviour
+{
+ [HideInInspector]
+ public Gun leftGun;
+
+ [HideInInspector]
+ public Gun rightGun;
+
+ [HideInInspector]
+ public Transform gunADS;
+
+ [HideInInspector]
+ public float ADSFOV;
+
+ public bool isDualWeilding;
+
+ private void Start()
+ {
+ }
+
+ private void Update()
+ {
+ }
+
+ public void SetWeapon(Weapon w, bool mainHand)
+ {
+ }
+
+ public void SetGun(Gun g, bool mainHand)
+ {
+ if (mainHand)
+ {
+ rightGun = g;
+ gunADS = g.GetComponentInChildren<ADS>().transform;
+ ADSFOV = g.ADSFOV;
+ }
+ else
+ {
+ leftGun = g;
+ }
+ if ((bool)leftGun && (bool)rightGun)
+ {
+ isDualWeilding = true;
+ }
+ }
+
+ public void HoldAttack(bool shootWithRightGun, bool ADS)
+ {
+ if (shootWithRightGun)
+ {
+ if (rightGun.auto)
+ {
+ rightGun.Shoot(base.transform.root, ADS);
+ }
+ }
+ else if (leftGun.auto)
+ {
+ leftGun.Shoot(base.transform.root, ADS);
+ }
+ }
+
+ public void PressAttack(bool shootWithRightGun, bool ADS)
+ {
+ if (shootWithRightGun)
+ {
+ rightGun.Shoot(base.transform.root, ADS);
+ }
+ else
+ {
+ leftGun.Shoot(base.transform.root, ADS);
+ }
+ }
+}