From 793c4eae324d394f19a8bac66a803bf03a67ae9d Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Sat, 16 Mar 2024 12:39:34 +0800 Subject: *misc --- _ActiveRagdoll/Actions/Balance.cs | 130 +++++++++++++++++++++++++ _ActiveRagdoll/Actions/Standing.cs | 57 +++++++++++ _ActiveRagdoll/Balance.cs | 130 ------------------------- _ActiveRagdoll/Handlers/AnimationHandler.cs | 15 +++ _ActiveRagdoll/Handlers/InputHandler.cs | 120 +++++++++++++++++++++++ _ActiveRagdoll/Handlers/MovementDataHandler.cs | 92 +++++++++++++++++ _ActiveRagdoll/Handlers/MovementHandler.cs | 86 ++++++++++++++++ _ActiveRagdoll/Handlers/PickupHandler.cs | 64 ++++++++++++ _ActiveRagdoll/Handlers/StepHandler.cs | 53 ++++++++++ _ActiveRagdoll/InputHandler.cs | 120 ----------------------- _ActiveRagdoll/Player/AnimationHandler.cs | 15 --- _ActiveRagdoll/Player/MovementDataHandler.cs | 92 ----------------- _ActiveRagdoll/Player/MovementHandler.cs | 86 ---------------- _ActiveRagdoll/Player/PickupHandler.cs | 64 ------------ _ActiveRagdoll/Standing.cs | 57 ----------- _ActiveRagdoll/StepHandler.cs | 53 ---------- 16 files changed, 617 insertions(+), 617 deletions(-) create mode 100644 _ActiveRagdoll/Actions/Balance.cs create mode 100644 _ActiveRagdoll/Actions/Standing.cs delete mode 100644 _ActiveRagdoll/Balance.cs create mode 100644 _ActiveRagdoll/Handlers/AnimationHandler.cs create mode 100644 _ActiveRagdoll/Handlers/InputHandler.cs create mode 100644 _ActiveRagdoll/Handlers/MovementDataHandler.cs create mode 100644 _ActiveRagdoll/Handlers/MovementHandler.cs create mode 100644 _ActiveRagdoll/Handlers/PickupHandler.cs create mode 100644 _ActiveRagdoll/Handlers/StepHandler.cs delete mode 100644 _ActiveRagdoll/InputHandler.cs delete mode 100644 _ActiveRagdoll/Player/AnimationHandler.cs delete mode 100644 _ActiveRagdoll/Player/MovementDataHandler.cs delete mode 100644 _ActiveRagdoll/Player/MovementHandler.cs delete mode 100644 _ActiveRagdoll/Player/PickupHandler.cs delete mode 100644 _ActiveRagdoll/Standing.cs delete mode 100644 _ActiveRagdoll/StepHandler.cs diff --git a/_ActiveRagdoll/Actions/Balance.cs b/_ActiveRagdoll/Actions/Balance.cs new file mode 100644 index 0000000..7776c88 --- /dev/null +++ b/_ActiveRagdoll/Actions/Balance.cs @@ -0,0 +1,130 @@ +using UnityEngine; + +//Player Balance 动作-控制双脚的位置,让双脚和双脚的中点尽可能和重心在水平的投影重合 +public class Balance : MonoBehaviour +{ + #region rigs + private Rigidbody handLeft; + private Rigidbody handRight; + private Rigidbody footLeft; // kneeLeft + private Rigidbody footRight; // kneeRight + private Rigidbody hip; + #endregion + + private Vector3 centerOfMass; // 5.0759, 0, -7.2038 + + private Rigidbody[] allRigs;//所有14个parts + + public float[] balanceForce; // 50 30 30 30 + + public float[] footCenterForces; // 50 20 20 20 + + private AnimationHandler animationHandler; // 当前动作编号 + + private PlayerDeath death; + + private Strength str; + + private float muscleMultiplier; // 1 + + private void Start() + { + death = GetComponent(); + str = GetComponent(); + allRigs = GetComponentsInChildren(); + HandLeft componentInChildren = GetComponentInChildren(); + if ((bool)componentInChildren) + { + handLeft = componentInChildren.GetComponent(); + } + HandRight componentInChildren2 = GetComponentInChildren(); + if ((bool)componentInChildren2) + { + handRight = componentInChildren2.GetComponent(); + } + footLeft = GetComponentInChildren().GetComponent(); + footRight = GetComponentInChildren().GetComponent(); + hip = GetComponentInChildren().GetComponent(); + animationHandler = GetComponent(); + } + + private void FixedUpdate() + { + if (!death.dead) + { + muscleMultiplier = str.strength; + centerOfMass = Vector3.zero; + Rigidbody[] array = allRigs; + foreach (Rigidbody rigidbody in array) + { + centerOfMass += rigidbody.worldCenterOfMass; + } + centerOfMass /= (float)allRigs.Length; + centerOfMass.y = 0f; + BalanceLegs(); + CenterLegs(); + } + } + + // 让双脚尽量靠近重心的水平投影 + private void CenterLegs() + { + Vector3 vector = footLeft.transform.position + footLeft.transform.forward * 0.5f; + Vector3 vector2 = footRight.transform.position + footRight.transform.forward * 0.5f; + Vector3 vector3 = vector; + if (vector.y + 0.3f < hip.worldCenterOfMass.y) + { + vector3.y = 0f; + footLeft.AddForceAtPosition((centerOfMass - vector3) * muscleMultiplier * footCenterForces[animationHandler.animationState], vector, ForceMode.Acceleration); + } + Vector3 vector4 = vector2; + if (vector4.y + 0.3f < hip.worldCenterOfMass.y) + { + vector4.y = 0f; + footRight.AddForceAtPosition((centerOfMass - vector4) * muscleMultiplier * footCenterForces[animationHandler.animationState], vector2, ForceMode.Acceleration); + } + } + + // 让双脚的中点尽量和重心的水平投影重合 + private void BalanceLegs() + { + Vector3 vector = footLeft.transform.position + footLeft.transform.forward * 0.5f; + Vector3 vector2 = footRight.transform.position + footRight.transform.forward * 0.5f; + Vector3 vector3 = (vector + vector2) / 2f; + + Vector3 pos = vector3; + pos.y += 0.3f; + Vector3 vector03 = vector3; + + if (!(vector3.y + 0.3f > hip.worldCenterOfMass.y)) + { + vector3.y = 0f; + Vector3 vector4 = centerOfMass - vector3; // centerOfMass是xoz平面,不含y + + REPL.footCenter.GetComponent().customDraw = () => + { + return; + + Draw.Sphere(vector, 0.05f); + Draw.Sphere(vector2, 0.05f); + + Draw.color = Color.red; + Draw.Sphere(pos, 0.05f); + Draw.Sphere(vector03, 0.05f); + Draw.color = Color.white; + + Draw.Sphere(hip.worldCenterOfMass, 0.2f); + + Draw.Sphere(centerOfMass, 0.05f); + + Draw.color = Color.green; + Draw.Line3D(vector, vector + vector4); + Draw.Line3D(vector2, vector2 + vector4); + Draw.color = Color.white; + }; + + footLeft.AddForceAtPosition(vector4 * muscleMultiplier * balanceForce[animationHandler.animationState], vector, ForceMode.Acceleration); + footRight.AddForceAtPosition(vector4 * muscleMultiplier * balanceForce[animationHandler.animationState], vector2, ForceMode.Acceleration); + }; + } +} diff --git a/_ActiveRagdoll/Actions/Standing.cs b/_ActiveRagdoll/Actions/Standing.cs new file mode 100644 index 0000000..2af0e4b --- /dev/null +++ b/_ActiveRagdoll/Actions/Standing.cs @@ -0,0 +1,57 @@ +using UnityEngine; + +//Player Standing 动作-站立 +public class Standing : MonoBehaviour +{ + public RigidbodyMovment[] rigsToLift; //Head, Torso + + public AnimationCurve[] animationLiftCurves; + + private StandingDataHandler standingData; + + private AnimationHandler animationHandler; + + public float offset; + + private PlayerDeath death; + + private Strength str; + + private float muscleMultiplier = 1f; + + private float legAngleMultiplier; + + private MovementDataHandler moveData; + + private void Start() + { + death = GetComponent(); + str = GetComponent(); + standingData = GetComponent(); + moveData = GetComponent(); + animationHandler = GetComponent(); + } + + private void FixedUpdate() + { + if (!death.dead) + { + muscleMultiplier = str.strength; + if (standingData.isGrounded) + { + Stand(animationLiftCurves[animationHandler.animationState]); + } + } + } + + private void Stand(AnimationCurve curve) + { + legAngleMultiplier = 1f; + RigidbodyMovment[] array = rigsToLift; + foreach (RigidbodyMovment rigidbodyMovment in array) + { + // 施加一个向上的力 + rigidbodyMovment.rig.AddForce(Vector3.up * muscleMultiplier * rigidbodyMovment.force * legAngleMultiplier * curve.Evaluate(standingData.distanceToGround + offset + moveData.slopeVelocityStrenght * -0.2f), ForceMode.Acceleration); + } + } +} diff --git a/_ActiveRagdoll/Balance.cs b/_ActiveRagdoll/Balance.cs deleted file mode 100644 index f034290..0000000 --- a/_ActiveRagdoll/Balance.cs +++ /dev/null @@ -1,130 +0,0 @@ -using UnityEngine; - -//Player Balance 动作-控制双脚的位置,让双脚和双脚的中点尽可能和重心在水平的投影重合 -public class Balance : MonoBehaviour -{ - #region rigs - private Rigidbody handLeft; - private Rigidbody handRight; - private Rigidbody footLeft; // kneeLeft - private Rigidbody footRight; // kneeRight - private Rigidbody hip; - #endregion - - private Vector3 centerOfMass; // 5.0759, 0, -7.2038 - - private Rigidbody[] allRigs;//所有14个parts - - public float[] balanceForce; // 50 30 30 30 - - public float[] footCenterForces; // 50 20 20 20 - - private AnimationHandler animationHandler; // 当前动作编号 - - private PlayerDeath death; - - private Strength str; - - private float muscleMultiplier; // 1 - - private void Start() - { - death = GetComponent(); - str = GetComponent(); - allRigs = GetComponentsInChildren(); - HandLeft componentInChildren = GetComponentInChildren(); - if ((bool)componentInChildren) - { - handLeft = componentInChildren.GetComponent(); - } - HandRight componentInChildren2 = GetComponentInChildren(); - if ((bool)componentInChildren2) - { - handRight = componentInChildren2.GetComponent(); - } - footLeft = GetComponentInChildren().GetComponent(); - footRight = GetComponentInChildren().GetComponent(); - hip = GetComponentInChildren().GetComponent(); - animationHandler = GetComponent(); - } - - private void FixedUpdate() - { - if (!death.dead) - { - muscleMultiplier = str.strength; - centerOfMass = Vector3.zero; - Rigidbody[] array = allRigs; - foreach (Rigidbody rigidbody in array) - { - centerOfMass += rigidbody.worldCenterOfMass; - } - centerOfMass /= (float)allRigs.Length; - centerOfMass.y = 0f; - BalanceLegs(); - CenterLegs(); - } - } - - // 让双脚尽量靠近重心的水平投影 - private void CenterLegs() - { - Vector3 vector = footLeft.transform.position + footLeft.transform.forward * 0.5f; - Vector3 vector2 = footRight.transform.position + footRight.transform.forward * 0.5f; - Vector3 vector3 = vector; - if (vector.y + 0.3f < hip.worldCenterOfMass.y) - { - vector3.y = 0f; - footLeft.AddForceAtPosition((centerOfMass - vector3) * muscleMultiplier * footCenterForces[animationHandler.animationState], vector, ForceMode.Acceleration); - } - Vector3 vector4 = vector2; - if (vector4.y + 0.3f < hip.worldCenterOfMass.y) - { - vector4.y = 0f; - footRight.AddForceAtPosition((centerOfMass - vector4) * muscleMultiplier * footCenterForces[animationHandler.animationState], vector2, ForceMode.Acceleration); - } - } - - // 让双脚的中点尽量和重心的水平投影重合 - private void BalanceLegs() - { - Vector3 vector = footLeft.transform.position + footLeft.transform.forward * 0.5f; - Vector3 vector2 = footRight.transform.position + footRight.transform.forward * 0.5f; - Vector3 vector3 = (vector + vector2) / 2f; - - Vector3 pos = vector3; - pos.y += 0.3f; - Vector3 vector03 = vector3; - - if (!(vector3.y + 0.3f > hip.worldCenterOfMass.y)) - { - vector3.y = 0f; - Vector3 vector4 = centerOfMass - vector3; // centerOfMass是xoz平面,不含y - - REPL.footCenter.GetComponent().customDraw = () => - { - //return; - - Draw.Sphere(vector, 0.05f); - Draw.Sphere(vector2, 0.05f); - - Draw.color = Color.red; - Draw.Sphere(pos, 0.05f); - Draw.Sphere(vector03, 0.05f); - Draw.color = Color.white; - - Draw.Sphere(hip.worldCenterOfMass, 0.2f); - - Draw.Sphere(centerOfMass, 0.05f); - - Draw.color = Color.green; - Draw.Line3D(vector, vector + vector4); - Draw.Line3D(vector2, vector2 + vector4); - Draw.color = Color.white; - }; - - footLeft.AddForceAtPosition(vector4 * muscleMultiplier * balanceForce[animationHandler.animationState], vector, ForceMode.Acceleration); - footRight.AddForceAtPosition(vector4 * muscleMultiplier * balanceForce[animationHandler.animationState], vector2, ForceMode.Acceleration); - }; - } -} diff --git a/_ActiveRagdoll/Handlers/AnimationHandler.cs b/_ActiveRagdoll/Handlers/AnimationHandler.cs new file mode 100644 index 0000000..382b3a5 --- /dev/null +++ b/_ActiveRagdoll/Handlers/AnimationHandler.cs @@ -0,0 +1,15 @@ +using UnityEngine; + +//Player AnimationHandler 记录当前动作状态编号 +public class AnimationHandler : MonoBehaviour +{ + public int animationState; + + private void Start() + { + } + + private void Update() + { + } +} diff --git a/_ActiveRagdoll/Handlers/InputHandler.cs b/_ActiveRagdoll/Handlers/InputHandler.cs new file mode 100644 index 0000000..27adc82 --- /dev/null +++ b/_ActiveRagdoll/Handlers/InputHandler.cs @@ -0,0 +1,120 @@ +using UnityEngine; + +public class InputHandler : MonoBehaviour +{ + public Vector3 inputMovementDirection; + + public Vector3 lastInputDirection; + + public bool isSpringting; + + private WeaponHandler wepaonHandler; + + private MovementDataHandler movementData; + + private WeaponHandler weaponHandler; + + private CameraMovement cameraMovement; + + private PlayerDeath death; + + private HasControl hasControl; + + private MovementHandler movement; + + public bool allowStrafe = true; + + private void Start() + { + death = GetComponent(); + movement = GetComponent(); + wepaonHandler = GetComponent(); + hasControl = GetComponent(); + movementData = GetComponent(); + weaponHandler = GetComponent(); + cameraMovement = GetComponentInChildren(); + } + + private void Update() + { + if ((bool)death && death.dead) + { + return; + } + if (!hasControl || hasControl.hasControl) + { + isSpringting = false; + inputMovementDirection = Vector3.zero; + if (Input.GetKey(KeyCode.W)) + { + inputMovementDirection += movementData.groundedForward; + } + if (Input.GetKey(KeyCode.S)) + { + inputMovementDirection += movementData.groundedBack; + } + if (Input.GetKey(KeyCode.D) && allowStrafe) + { + inputMovementDirection += movementData.right; + } + if (Input.GetKey(KeyCode.A) && allowStrafe) + { + inputMovementDirection += movementData.left; + } + if (Input.GetKey(KeyCode.LeftShift) && (!cameraMovement || !cameraMovement.ADS)) + { + isSpringting = true; + } + inputMovementDirection = inputMovementDirection.normalized; + if ((bool)movement && Input.GetKeyDown(KeyCode.Space)) + { + movement.Jump(); + } + if ((bool)weaponHandler) + { + if (weaponHandler.isDualWeilding) + { + if (Input.GetKey(KeyCode.Mouse1)) + { + weaponHandler.HoldAttack(shootWithRightGun: true, ADS: false); + } + if (Input.GetKeyDown(KeyCode.Mouse1)) + { + weaponHandler.PressAttack(shootWithRightGun: true, ADS: false); + } + if (Input.GetKey(KeyCode.Mouse0)) + { + weaponHandler.HoldAttack(shootWithRightGun: false, ADS: false); + } + if (Input.GetKeyDown(KeyCode.Mouse0)) + { + weaponHandler.PressAttack(shootWithRightGun: false, ADS: false); + } + } + else + { + if (Input.GetKey(KeyCode.Mouse1)) + { + cameraMovement.ADS = true; + } + else + { + cameraMovement.ADS = false; + } + if (Input.GetKey(KeyCode.Mouse0)) + { + weaponHandler.HoldAttack(shootWithRightGun: true, cameraMovement.ADS); + } + if (Input.GetKeyDown(KeyCode.Mouse0)) + { + weaponHandler.PressAttack(shootWithRightGun: true, cameraMovement.ADS); + } + } + } + } + if (inputMovementDirection != Vector3.zero) + { + lastInputDirection = inputMovementDirection; + } + } +} diff --git a/_ActiveRagdoll/Handlers/MovementDataHandler.cs b/_ActiveRagdoll/Handlers/MovementDataHandler.cs new file mode 100644 index 0000000..18d43f5 --- /dev/null +++ b/_ActiveRagdoll/Handlers/MovementDataHandler.cs @@ -0,0 +1,92 @@ +using UnityEngine; + +public class MovementDataHandler : MonoBehaviour +{ + [HideInInspector] + public Vector3 groundedForward; + + [HideInInspector] + public Vector3 right; + + [HideInInspector] + public Vector3 left; + + [HideInInspector] + public Vector3 groundedBack; + + private Transform hip; + + private Transform torso; + + public Transform rotationTarget; + + [HideInInspector] + public float slopeStrenght; + + public float slopeVelocityStrenght; + + [HideInInspector] + public float sinceJump = 1f; + + [HideInInspector] + public Vector3 groundNormal; + + private InputHandler inputHandler; + + private Transform leftKnee; + + private Transform rightKnee; + + private void Start() + { + inputHandler = GetComponent(); + hip = GetComponentInChildren().transform; + torso = GetComponentInChildren().transform; + if (!rotationTarget) + { + rotationTarget = GetComponentInChildren().transform; + } + KneeLeft componentInChildren = GetComponentInChildren(); + if ((bool)componentInChildren) + { + leftKnee = componentInChildren.transform; + } + KneeRight componentInChildren2 = GetComponentInChildren(); + if ((bool)componentInChildren2) + { + rightKnee = componentInChildren2.transform; + } + } + + private void Update() + { + sinceJump += Time.deltaTime; + groundedForward = rotationTarget.forward; + groundedForward.y = slopeStrenght * 1f; + groundedForward = groundedForward.normalized; + groundedBack = -groundedForward; + right = rotationTarget.right; + left = -rotationTarget.right; + slopeStrenght = Mathf.Lerp(slopeStrenght, 0f, Time.deltaTime * 1f); + Debug.DrawLine(hip.position, hip.position + groundedForward * 10f); + } + + public void SetSlope(Vector3 normal) + { + groundNormal = normal; + slopeStrenght = Vector3.Cross(rotationTarget.right, normal).y; + Vector3 lhs = Vector3.Cross(Vector3.up, inputHandler.inputMovementDirection); + slopeVelocityStrenght = Vector3.Cross(lhs, normal).y; + } + + public float GetSmallestLegAngle() + { + float num = Vector3.Angle(leftKnee.forward, Vector3.down); + float num2 = Vector3.Angle(rightKnee.forward, Vector3.down); + if (num < num2) + { + return num; + } + return num2; + } +} diff --git a/_ActiveRagdoll/Handlers/MovementHandler.cs b/_ActiveRagdoll/Handlers/MovementHandler.cs new file mode 100644 index 0000000..4579efc --- /dev/null +++ b/_ActiveRagdoll/Handlers/MovementHandler.cs @@ -0,0 +1,86 @@ +using System.Collections; +using UnityEngine; + +//Player MovementHandler 控制移动、跳跃 +public class MovementHandler : MonoBehaviour +{ + private InputHandler inputHandler; + + public float friction = 0.9f; + + public Vector3 movementVector; + + public float[] animationForceAmounts; + + private AnimationHandler animationHandler; + + private RigidbodyHolder allRigs; + + public AnimationCurve jumpCurve; + + public float jumpForce; + + private StandingDataHandler standingData; + + private MovementDataHandler data; + + private PlayerDeath death; + + [HideInInspector] + public float multiplier = 1f; + + private WobbleShake wobbleShake; + + private void Start() + { + wobbleShake = GetComponentInChildren(); + death = GetComponent(); + standingData = GetComponent(); + inputHandler = GetComponent(); + animationHandler = GetComponent(); + allRigs = GetComponent(); + data = GetComponent(); + } + + private void FixedUpdate() + { + if (!death.dead) + { + data.sinceJump += Time.fixedDeltaTime; + movementVector += inputHandler.inputMovementDirection * animationForceAmounts[animationHandler.animationState]; + movementVector *= friction; + for (int i = 0; i < allRigs.GetAllRigs().Length; i++) + { + allRigs.GetAllRigs()[i].AddForce(movementVector * multiplier, ForceMode.Acceleration); + } + } + } + + public void Jump() + { + if (!(data.sinceJump < 0.5f) && !(standingData.sinceGrounded > 0.3f)) + { + data.sinceJump = 0f; + StartCoroutine(AddJumpForce()); + wobbleShake.AddShake(Vector3.up * 2f, 0.8f); + } + } + + private IEnumerator AddJumpForce() + { + float counter = 0f; + for (int i = 0; i < allRigs.GetAllRigs().Length; i++) + { + allRigs.GetAllRigs()[i].velocity = new Vector3(allRigs.GetAllRigs()[i].velocity.x, 0f, allRigs.GetAllRigs()[i].velocity.z); + } + while (counter < jumpCurve.keys[jumpCurve.length - 1].time && !death.dead) + { + counter += Time.deltaTime; + for (int j = 0; j < allRigs.GetAllRigs().Length; j++) + { + allRigs.GetAllRigs()[j].AddForce(Vector3.up * multiplier * jumpForce * jumpCurve.Evaluate(counter) * Time.deltaTime, ForceMode.Acceleration); + } + yield return null; + } + } +} diff --git a/_ActiveRagdoll/Handlers/PickupHandler.cs b/_ActiveRagdoll/Handlers/PickupHandler.cs new file mode 100644 index 0000000..6a3a249 --- /dev/null +++ b/_ActiveRagdoll/Handlers/PickupHandler.cs @@ -0,0 +1,64 @@ +using UnityEngine; + +//Player PickupHandler 捡武器 +public class PickupHandler : MonoBehaviour +{ + public Pickup setWeapon; + + public Pickup setWeapon2; + + private WeaponHandler weaponHandler; + + private Holding holding; // holding动作 + + private float counter; + + private void Start() + { + weaponHandler = GetComponent(); + holding = GetComponent(); + if ((bool)setWeapon) + { + PickUp(setWeapon); + } + if ((bool)setWeapon2) + { + PickUp2(setWeapon2); + } + } + + private void Update() + { + counter += Time.deltaTime; + } + + public void PickUp(Pickup objectToPickUp) + { + if (!(counter < 1f)) + { + counter = 0f; + holding.Drop(); + Weapon component = objectToPickUp.GetComponent(); + Gun component2 = component.GetComponent(); + weaponHandler.SetGun(component2, mainHand: true); + bool hasOffHand = false; + if ((bool)setWeapon2) + { + hasOffHand = true; + } + HoldableObject component3 = component.GetComponent(); + component3.holder = base.transform; + holding.StartHolding(component3, hasOffHand); + } + } + + public void PickUp2(Pickup objectToPickUp) + { + Weapon component = objectToPickUp.GetComponent(); + Gun component2 = component.GetComponent(); + weaponHandler.SetGun(component2, mainHand: false); + HoldableObject component3 = component.GetComponent(); + component3.holder = base.transform; + holding.StartHolding(component3, hasOffHand: true); + } +} diff --git a/_ActiveRagdoll/Handlers/StepHandler.cs b/_ActiveRagdoll/Handlers/StepHandler.cs new file mode 100644 index 0000000..fd8110b --- /dev/null +++ b/_ActiveRagdoll/Handlers/StepHandler.cs @@ -0,0 +1,53 @@ +using UnityEngine; + +public class StepHandler : MonoBehaviour +{ + public float staticCounter; + + public Step[] steps; + + public bool isLeft; + + private float counter; + + private Transform leftLeg; + + private Transform rightLeg; + + private AnimationHandler animationHandler; + + private Transform hip; + + private void Start() + { + if (staticCounter == 0f) + { + leftLeg = GetComponentInChildren().transform; + rightLeg = GetComponentInChildren().transform; + animationHandler = GetComponent(); + hip = GetComponentInChildren().transform; + } + } + + private void Update() + { + counter += Time.deltaTime; + if (staticCounter != 0f) + { + if (counter > staticCounter) + { + Switch(); + } + } + else if (counter > steps[animationHandler.animationState].minTime && (steps[animationHandler.animationState].minAngle == 0f || steps[animationHandler.animationState].minAngle < Vector3.Angle(leftLeg.forward, rightLeg.forward)) && isLeft == hip.InverseTransformPoint(leftLeg.position + leftLeg.forward).z > hip.InverseTransformPoint(rightLeg.position + rightLeg.forward).z) + { + Switch(); + } + } + + private void Switch() + { + isLeft = !isLeft; + counter = 0f; + } +} diff --git a/_ActiveRagdoll/InputHandler.cs b/_ActiveRagdoll/InputHandler.cs deleted file mode 100644 index 27adc82..0000000 --- a/_ActiveRagdoll/InputHandler.cs +++ /dev/null @@ -1,120 +0,0 @@ -using UnityEngine; - -public class InputHandler : MonoBehaviour -{ - public Vector3 inputMovementDirection; - - public Vector3 lastInputDirection; - - public bool isSpringting; - - private WeaponHandler wepaonHandler; - - private MovementDataHandler movementData; - - private WeaponHandler weaponHandler; - - private CameraMovement cameraMovement; - - private PlayerDeath death; - - private HasControl hasControl; - - private MovementHandler movement; - - public bool allowStrafe = true; - - private void Start() - { - death = GetComponent(); - movement = GetComponent(); - wepaonHandler = GetComponent(); - hasControl = GetComponent(); - movementData = GetComponent(); - weaponHandler = GetComponent(); - cameraMovement = GetComponentInChildren(); - } - - private void Update() - { - if ((bool)death && death.dead) - { - return; - } - if (!hasControl || hasControl.hasControl) - { - isSpringting = false; - inputMovementDirection = Vector3.zero; - if (Input.GetKey(KeyCode.W)) - { - inputMovementDirection += movementData.groundedForward; - } - if (Input.GetKey(KeyCode.S)) - { - inputMovementDirection += movementData.groundedBack; - } - if (Input.GetKey(KeyCode.D) && allowStrafe) - { - inputMovementDirection += movementData.right; - } - if (Input.GetKey(KeyCode.A) && allowStrafe) - { - inputMovementDirection += movementData.left; - } - if (Input.GetKey(KeyCode.LeftShift) && (!cameraMovement || !cameraMovement.ADS)) - { - isSpringting = true; - } - inputMovementDirection = inputMovementDirection.normalized; - if ((bool)movement && Input.GetKeyDown(KeyCode.Space)) - { - movement.Jump(); - } - if ((bool)weaponHandler) - { - if (weaponHandler.isDualWeilding) - { - if (Input.GetKey(KeyCode.Mouse1)) - { - weaponHandler.HoldAttack(shootWithRightGun: true, ADS: false); - } - if (Input.GetKeyDown(KeyCode.Mouse1)) - { - weaponHandler.PressAttack(shootWithRightGun: true, ADS: false); - } - if (Input.GetKey(KeyCode.Mouse0)) - { - weaponHandler.HoldAttack(shootWithRightGun: false, ADS: false); - } - if (Input.GetKeyDown(KeyCode.Mouse0)) - { - weaponHandler.PressAttack(shootWithRightGun: false, ADS: false); - } - } - else - { - if (Input.GetKey(KeyCode.Mouse1)) - { - cameraMovement.ADS = true; - } - else - { - cameraMovement.ADS = false; - } - if (Input.GetKey(KeyCode.Mouse0)) - { - weaponHandler.HoldAttack(shootWithRightGun: true, cameraMovement.ADS); - } - if (Input.GetKeyDown(KeyCode.Mouse0)) - { - weaponHandler.PressAttack(shootWithRightGun: true, cameraMovement.ADS); - } - } - } - } - if (inputMovementDirection != Vector3.zero) - { - lastInputDirection = inputMovementDirection; - } - } -} diff --git a/_ActiveRagdoll/Player/AnimationHandler.cs b/_ActiveRagdoll/Player/AnimationHandler.cs deleted file mode 100644 index 382b3a5..0000000 --- a/_ActiveRagdoll/Player/AnimationHandler.cs +++ /dev/null @@ -1,15 +0,0 @@ -using UnityEngine; - -//Player AnimationHandler 记录当前动作状态编号 -public class AnimationHandler : MonoBehaviour -{ - public int animationState; - - private void Start() - { - } - - private void Update() - { - } -} diff --git a/_ActiveRagdoll/Player/MovementDataHandler.cs b/_ActiveRagdoll/Player/MovementDataHandler.cs deleted file mode 100644 index 18d43f5..0000000 --- a/_ActiveRagdoll/Player/MovementDataHandler.cs +++ /dev/null @@ -1,92 +0,0 @@ -using UnityEngine; - -public class MovementDataHandler : MonoBehaviour -{ - [HideInInspector] - public Vector3 groundedForward; - - [HideInInspector] - public Vector3 right; - - [HideInInspector] - public Vector3 left; - - [HideInInspector] - public Vector3 groundedBack; - - private Transform hip; - - private Transform torso; - - public Transform rotationTarget; - - [HideInInspector] - public float slopeStrenght; - - public float slopeVelocityStrenght; - - [HideInInspector] - public float sinceJump = 1f; - - [HideInInspector] - public Vector3 groundNormal; - - private InputHandler inputHandler; - - private Transform leftKnee; - - private Transform rightKnee; - - private void Start() - { - inputHandler = GetComponent(); - hip = GetComponentInChildren().transform; - torso = GetComponentInChildren().transform; - if (!rotationTarget) - { - rotationTarget = GetComponentInChildren().transform; - } - KneeLeft componentInChildren = GetComponentInChildren(); - if ((bool)componentInChildren) - { - leftKnee = componentInChildren.transform; - } - KneeRight componentInChildren2 = GetComponentInChildren(); - if ((bool)componentInChildren2) - { - rightKnee = componentInChildren2.transform; - } - } - - private void Update() - { - sinceJump += Time.deltaTime; - groundedForward = rotationTarget.forward; - groundedForward.y = slopeStrenght * 1f; - groundedForward = groundedForward.normalized; - groundedBack = -groundedForward; - right = rotationTarget.right; - left = -rotationTarget.right; - slopeStrenght = Mathf.Lerp(slopeStrenght, 0f, Time.deltaTime * 1f); - Debug.DrawLine(hip.position, hip.position + groundedForward * 10f); - } - - public void SetSlope(Vector3 normal) - { - groundNormal = normal; - slopeStrenght = Vector3.Cross(rotationTarget.right, normal).y; - Vector3 lhs = Vector3.Cross(Vector3.up, inputHandler.inputMovementDirection); - slopeVelocityStrenght = Vector3.Cross(lhs, normal).y; - } - - public float GetSmallestLegAngle() - { - float num = Vector3.Angle(leftKnee.forward, Vector3.down); - float num2 = Vector3.Angle(rightKnee.forward, Vector3.down); - if (num < num2) - { - return num; - } - return num2; - } -} diff --git a/_ActiveRagdoll/Player/MovementHandler.cs b/_ActiveRagdoll/Player/MovementHandler.cs deleted file mode 100644 index 4579efc..0000000 --- a/_ActiveRagdoll/Player/MovementHandler.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Collections; -using UnityEngine; - -//Player MovementHandler 控制移动、跳跃 -public class MovementHandler : MonoBehaviour -{ - private InputHandler inputHandler; - - public float friction = 0.9f; - - public Vector3 movementVector; - - public float[] animationForceAmounts; - - private AnimationHandler animationHandler; - - private RigidbodyHolder allRigs; - - public AnimationCurve jumpCurve; - - public float jumpForce; - - private StandingDataHandler standingData; - - private MovementDataHandler data; - - private PlayerDeath death; - - [HideInInspector] - public float multiplier = 1f; - - private WobbleShake wobbleShake; - - private void Start() - { - wobbleShake = GetComponentInChildren(); - death = GetComponent(); - standingData = GetComponent(); - inputHandler = GetComponent(); - animationHandler = GetComponent(); - allRigs = GetComponent(); - data = GetComponent(); - } - - private void FixedUpdate() - { - if (!death.dead) - { - data.sinceJump += Time.fixedDeltaTime; - movementVector += inputHandler.inputMovementDirection * animationForceAmounts[animationHandler.animationState]; - movementVector *= friction; - for (int i = 0; i < allRigs.GetAllRigs().Length; i++) - { - allRigs.GetAllRigs()[i].AddForce(movementVector * multiplier, ForceMode.Acceleration); - } - } - } - - public void Jump() - { - if (!(data.sinceJump < 0.5f) && !(standingData.sinceGrounded > 0.3f)) - { - data.sinceJump = 0f; - StartCoroutine(AddJumpForce()); - wobbleShake.AddShake(Vector3.up * 2f, 0.8f); - } - } - - private IEnumerator AddJumpForce() - { - float counter = 0f; - for (int i = 0; i < allRigs.GetAllRigs().Length; i++) - { - allRigs.GetAllRigs()[i].velocity = new Vector3(allRigs.GetAllRigs()[i].velocity.x, 0f, allRigs.GetAllRigs()[i].velocity.z); - } - while (counter < jumpCurve.keys[jumpCurve.length - 1].time && !death.dead) - { - counter += Time.deltaTime; - for (int j = 0; j < allRigs.GetAllRigs().Length; j++) - { - allRigs.GetAllRigs()[j].AddForce(Vector3.up * multiplier * jumpForce * jumpCurve.Evaluate(counter) * Time.deltaTime, ForceMode.Acceleration); - } - yield return null; - } - } -} diff --git a/_ActiveRagdoll/Player/PickupHandler.cs b/_ActiveRagdoll/Player/PickupHandler.cs deleted file mode 100644 index 6a3a249..0000000 --- a/_ActiveRagdoll/Player/PickupHandler.cs +++ /dev/null @@ -1,64 +0,0 @@ -using UnityEngine; - -//Player PickupHandler 捡武器 -public class PickupHandler : MonoBehaviour -{ - public Pickup setWeapon; - - public Pickup setWeapon2; - - private WeaponHandler weaponHandler; - - private Holding holding; // holding动作 - - private float counter; - - private void Start() - { - weaponHandler = GetComponent(); - holding = GetComponent(); - if ((bool)setWeapon) - { - PickUp(setWeapon); - } - if ((bool)setWeapon2) - { - PickUp2(setWeapon2); - } - } - - private void Update() - { - counter += Time.deltaTime; - } - - public void PickUp(Pickup objectToPickUp) - { - if (!(counter < 1f)) - { - counter = 0f; - holding.Drop(); - Weapon component = objectToPickUp.GetComponent(); - Gun component2 = component.GetComponent(); - weaponHandler.SetGun(component2, mainHand: true); - bool hasOffHand = false; - if ((bool)setWeapon2) - { - hasOffHand = true; - } - HoldableObject component3 = component.GetComponent(); - component3.holder = base.transform; - holding.StartHolding(component3, hasOffHand); - } - } - - public void PickUp2(Pickup objectToPickUp) - { - Weapon component = objectToPickUp.GetComponent(); - Gun component2 = component.GetComponent(); - weaponHandler.SetGun(component2, mainHand: false); - HoldableObject component3 = component.GetComponent(); - component3.holder = base.transform; - holding.StartHolding(component3, hasOffHand: true); - } -} diff --git a/_ActiveRagdoll/Standing.cs b/_ActiveRagdoll/Standing.cs deleted file mode 100644 index 2af0e4b..0000000 --- a/_ActiveRagdoll/Standing.cs +++ /dev/null @@ -1,57 +0,0 @@ -using UnityEngine; - -//Player Standing 动作-站立 -public class Standing : MonoBehaviour -{ - public RigidbodyMovment[] rigsToLift; //Head, Torso - - public AnimationCurve[] animationLiftCurves; - - private StandingDataHandler standingData; - - private AnimationHandler animationHandler; - - public float offset; - - private PlayerDeath death; - - private Strength str; - - private float muscleMultiplier = 1f; - - private float legAngleMultiplier; - - private MovementDataHandler moveData; - - private void Start() - { - death = GetComponent(); - str = GetComponent(); - standingData = GetComponent(); - moveData = GetComponent(); - animationHandler = GetComponent(); - } - - private void FixedUpdate() - { - if (!death.dead) - { - muscleMultiplier = str.strength; - if (standingData.isGrounded) - { - Stand(animationLiftCurves[animationHandler.animationState]); - } - } - } - - private void Stand(AnimationCurve curve) - { - legAngleMultiplier = 1f; - RigidbodyMovment[] array = rigsToLift; - foreach (RigidbodyMovment rigidbodyMovment in array) - { - // 施加一个向上的力 - rigidbodyMovment.rig.AddForce(Vector3.up * muscleMultiplier * rigidbodyMovment.force * legAngleMultiplier * curve.Evaluate(standingData.distanceToGround + offset + moveData.slopeVelocityStrenght * -0.2f), ForceMode.Acceleration); - } - } -} diff --git a/_ActiveRagdoll/StepHandler.cs b/_ActiveRagdoll/StepHandler.cs deleted file mode 100644 index fd8110b..0000000 --- a/_ActiveRagdoll/StepHandler.cs +++ /dev/null @@ -1,53 +0,0 @@ -using UnityEngine; - -public class StepHandler : MonoBehaviour -{ - public float staticCounter; - - public Step[] steps; - - public bool isLeft; - - private float counter; - - private Transform leftLeg; - - private Transform rightLeg; - - private AnimationHandler animationHandler; - - private Transform hip; - - private void Start() - { - if (staticCounter == 0f) - { - leftLeg = GetComponentInChildren().transform; - rightLeg = GetComponentInChildren().transform; - animationHandler = GetComponent(); - hip = GetComponentInChildren().transform; - } - } - - private void Update() - { - counter += Time.deltaTime; - if (staticCounter != 0f) - { - if (counter > staticCounter) - { - Switch(); - } - } - else if (counter > steps[animationHandler.animationState].minTime && (steps[animationHandler.animationState].minAngle == 0f || steps[animationHandler.animationState].minAngle < Vector3.Angle(leftLeg.forward, rightLeg.forward)) && isLeft == hip.InverseTransformPoint(leftLeg.position + leftLeg.forward).z > hip.InverseTransformPoint(rightLeg.position + rightLeg.forward).z) - { - Switch(); - } - } - - private void Switch() - { - isLeft = !isLeft; - counter = 0f; - } -} -- cgit v1.1-26-g67d0