using System; using UnityEngine; namespace Framework.Support { /// Provides helper methods for working with joints public static class JointHelper { #region struct HingeJointData public struct HingeJointData { /// Position of the hinge's rotational center public Vector3 Anchor; /// Whether to automatically configure the anchor position public bool AutoConfigureConnectedAnchor; /// Axis on which the hinge can rotate public Vector3 Axis; /// Force required to break the hinge public float BreakForce; /// Torque required to break the hinge public float BreakTorque; /// Position of the anchor on the connected rigidbody public Vector3 ConnectedAnchor; /// Rigidbody to which the hinge is connected public Rigidbody ConnectedBody; /// Whether the joint's limits are used public bool UseLimits; /// How far the joint can move public JointLimits Limits; /// Whether the joint's motor is enabled public bool UseMotor; /// Power that is automatically applied to the joint public JointMotor Motor; /// Whether the joint's spring is active public bool UseSpring; /// Force that moves the joint back into its original position public JointSpring Spring; } #endregion // struct HingeJointData /// Saves the properties of a hinge joint into a structure /// Hinge joint whose properties will be saved /// Structure in which the hinge joint's settings will be stored public static void Save(HingeJoint hingeJoint, ref HingeJointData data) { data.Anchor = hingeJoint.anchor; data.AutoConfigureConnectedAnchor = hingeJoint.autoConfigureConnectedAnchor; data.Axis = hingeJoint.axis; data.BreakForce = hingeJoint.breakForce; data.BreakTorque = hingeJoint.breakTorque; data.ConnectedAnchor = hingeJoint.connectedAnchor; data.ConnectedBody = hingeJoint.connectedBody; data.UseLimits = hingeJoint.useLimits; data.Limits = hingeJoint.limits; data.UseMotor = hingeJoint.useMotor; data.Motor = hingeJoint.motor; data.UseSpring = hingeJoint.useSpring; data.Spring = hingeJoint.spring; } /// Loads the properties of a hinge joint from a structure /// Hinge joint the properties will be applied to /// Structure containing the hinge joint's settings public static void Load(HingeJoint hingeJoint, ref HingeJointData data) { hingeJoint.anchor = data.Anchor; hingeJoint.autoConfigureConnectedAnchor = data.AutoConfigureConnectedAnchor; hingeJoint.axis = data.Axis; hingeJoint.breakForce = data.BreakForce; hingeJoint.breakTorque = data.BreakTorque; hingeJoint.connectedAnchor = data.ConnectedAnchor; hingeJoint.connectedBody = data.ConnectedBody; hingeJoint.useLimits = data.UseLimits; hingeJoint.limits = data.Limits; hingeJoint.useMotor = data.UseMotor; hingeJoint.motor = data.Motor; hingeJoint.useSpring = data.UseSpring; hingeJoint.spring = data.Spring; } } } // namespace Framework.Support