Pre-Unity6 compatibilty

This commit is contained in:
Pascal Serrarens 2025-05-27 14:51:00 +02:00
parent 402300960e
commit 1c6a404dfd
11 changed files with 105 additions and 39 deletions

View File

@ -24,8 +24,7 @@ namespace Passer.Humanoid {
if (humanoid.isRemote) if (humanoid.isRemote)
return; return;
if (grabSocket != null) grabSocket.handTarget = this;
grabSocket.handTarget = this;
// Gun Interaction pointer creates an Event System // Gun Interaction pointer creates an Event System
// First solve that before enabling this warning // First solve that before enabling this warning
@ -33,7 +32,11 @@ namespace Passer.Humanoid {
inputModule = humanoid.GetComponent<InteractionModule>(); inputModule = humanoid.GetComponent<InteractionModule>();
if (inputModule == null) { if (inputModule == null) {
#if UNITY_6000_0_OR_NEWER
inputModule = Object.FindAnyObjectByType<InteractionModule>();
#else
inputModule = Object.FindObjectOfType<InteractionModule>(); inputModule = Object.FindObjectOfType<InteractionModule>();
#endif
if (inputModule == null) { if (inputModule == null) {
inputModule = humanoid.gameObject.AddComponent<InteractionModule>(); inputModule = humanoid.gameObject.AddComponent<InteractionModule>();
} }
@ -826,7 +829,11 @@ namespace Passer.Humanoid {
Rigidbody objRigidbody = RigidbodyDisabled.UnparentRigidbody(handPalm, grabbedObject.transform); Rigidbody objRigidbody = RigidbodyDisabled.UnparentRigidbody(handPalm, grabbedObject.transform);
if (objRigidbody != null && !objRigidbody.isKinematic) { if (objRigidbody != null && !objRigidbody.isKinematic) {
if (handRigidbody != null) { if (handRigidbody != null) {
#if UNITY_6000_0_OR_NEWER
objRigidbody.linearVelocity = handRigidbody.linearVelocity; objRigidbody.linearVelocity = handRigidbody.linearVelocity;
#else
objRigidbody.velocity = handRigidbody.velocity;
#endif
objRigidbody.angularVelocity = handRigidbody.angularVelocity; objRigidbody.angularVelocity = handRigidbody.angularVelocity;
} }
HumanoidNetworking.ReenableNetworkSync(objRigidbody.gameObject); HumanoidNetworking.ReenableNetworkSync(objRigidbody.gameObject);
@ -854,13 +861,17 @@ namespace Passer.Humanoid {
//grabbedRigidbody.centerOfMass = handTarget.storedCOM; //grabbedRigidbody.centerOfMass = handTarget.storedCOM;
if (grabbedRigidbody.isKinematic == false) { if (grabbedRigidbody.isKinematic == false) {
#if UNITY_6000_0_OR_NEWER
grabbedRigidbody.linearVelocity = handRigidbody.linearVelocity; grabbedRigidbody.linearVelocity = handRigidbody.linearVelocity;
#else
grabbedRigidbody.velocity = handRigidbody.velocity;
#endif
grabbedRigidbody.angularVelocity = handRigidbody.angularVelocity; grabbedRigidbody.angularVelocity = handRigidbody.angularVelocity;
} }
if (grabbedHandle != null) if (grabbedHandle != null)
LetGoHandle(grabbedHandle); LetGoHandle(grabbedHandle);
handRigidbody.mass = 1; handRigidbody.mass = 1;
} }
this.grabbedRigidbody = false; this.grabbedRigidbody = false;

View File

@ -53,8 +53,13 @@ namespace Passer.Humanoid {
handTarget.handRigidbody = handTarget.hand.bone.transform.gameObject.AddComponent<Rigidbody>(); handTarget.handRigidbody = handTarget.hand.bone.transform.gameObject.AddComponent<Rigidbody>();
} }
handTarget.handRigidbody.mass = 1; handTarget.handRigidbody.mass = 1;
#if UNITY_6000_0_OR_NEWER
handTarget.handRigidbody.linearDamping = 0; handTarget.handRigidbody.linearDamping = 0;
handTarget.handRigidbody.angularDamping = 10; handTarget.handRigidbody.angularDamping = 10;
#else
handTarget.handRigidbody.drag = 0;
handTarget.handRigidbody.angularDrag = 10;
#endif
handTarget.handRigidbody.useGravity = false; handTarget.handRigidbody.useGravity = false;
handTarget.handRigidbody.isKinematic = true; handTarget.handRigidbody.isKinematic = true;
handTarget.handRigidbody.interpolation = RigidbodyInterpolation.None; handTarget.handRigidbody.interpolation = RigidbodyInterpolation.None;

View File

@ -5,7 +5,7 @@ using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using GLTFast; //using GLTFast;
#if hNW_ROBOID #if hNW_ROBOID

View File

@ -227,7 +227,11 @@ namespace Passer.Humanoid {
//Compensate for absolute rigidbody speed (specifically when on a moving platform) //Compensate for absolute rigidbody speed (specifically when on a moving platform)
if (handRigidbody != null) { if (handRigidbody != null) {
#if UNITY_6000_0_OR_NEWER
Vector3 residualVelocity = handRigidbody.linearVelocity - velocityTowardsTarget; Vector3 residualVelocity = handRigidbody.linearVelocity - velocityTowardsTarget;
#else
Vector3 residualVelocity = handRigidbody.velocity - velocityTowardsTarget;
#endif
damper += residualVelocity * 10; damper += residualVelocity * 10;
} }
} }
@ -552,7 +556,11 @@ namespace Passer.Humanoid {
Vector3 velocityTarget = (positionDelta * velocityMagic) * Time.fixedDeltaTime; Vector3 velocityTarget = (positionDelta * velocityMagic) * Time.fixedDeltaTime;
if (float.IsNaN(velocityTarget.x) == false) if (float.IsNaN(velocityTarget.x) == false)
#if UNITY_6000_0_OR_NEWER
handRigidbody.linearVelocity = Vector3.MoveTowards(handRigidbody.linearVelocity, velocityTarget, MaxVelocityChange); handRigidbody.linearVelocity = Vector3.MoveTowards(handRigidbody.linearVelocity, velocityTarget, MaxVelocityChange);
#else
handRigidbody.velocity = Vector3.MoveTowards(handRigidbody.velocity, velocityTarget, MaxVelocityChange);
#endif
rotationDelta.ToAngleAxis(out angle, out axis); rotationDelta.ToAngleAxis(out angle, out axis);

View File

@ -15,8 +15,13 @@ namespace Passer {
public RigidbodyData(Rigidbody rb) { public RigidbodyData(Rigidbody rb) {
mass = rb.mass; mass = rb.mass;
#if UNITY_6000_0_OR_NEWER
drag = rb.linearDamping; drag = rb.linearDamping;
angularDrag = rb.angularDamping; angularDrag = rb.angularDamping;
#else
drag = rb.drag;
angularDrag = rb.angularDrag;
#endif
useGravity = rb.useGravity; useGravity = rb.useGravity;
isKinematic = rb.isKinematic; isKinematic = rb.isKinematic;
interpolation = rb.interpolation; interpolation = rb.interpolation;
@ -28,8 +33,13 @@ namespace Passer {
public void CopyToRigidbody(Rigidbody rb) { public void CopyToRigidbody(Rigidbody rb) {
rb.mass = mass; rb.mass = mass;
#if UNITY_6000_0_OR_NEWER
rb.linearDamping = drag; rb.linearDamping = drag;
rb.angularDamping = angularDrag; rb.angularDamping = angularDrag;
#else
rb.drag = drag;
rb.angularDrag = angularDrag;
#endif
rb.useGravity = useGravity; rb.useGravity = useGravity;
rb.isKinematic = isKinematic; rb.isKinematic = isKinematic;
rb.interpolation = interpolation; rb.interpolation = interpolation;

View File

@ -103,13 +103,7 @@ namespace Passer.Humanoid {
[System.Serializable] [System.Serializable]
[HelpURL("https://passervr.com/apis/HumanoidControl/Unity/class_passer_1_1_humanoid_1_1_hand_target.html")] [HelpURL("https://passervr.com/apis/HumanoidControl/Unity/class_passer_1_1_humanoid_1_1_hand_target.html")]
public partial class HandTarget : HumanoidTarget { public partial class HandTarget : HumanoidTarget {
/// <summary> public HandTarget() {
/// Pseudo-constructor because Unity does not use real constructors
/// </summary>
/// <param name="humanoid">The humanoid for this hand target</param>
/// <param name="isLeft">Is this the left hand target?</param>
public void Constructor(HumanoidControl humanoid, bool isLeft) {
this.humanoid = humanoid;
shoulder = new TargetedShoulderBone(this); shoulder = new TargetedShoulderBone(this);
upperArm = new TargetedUpperArmBone(this); upperArm = new TargetedUpperArmBone(this);
forearm = new TargetedForearmBone(this); forearm = new TargetedForearmBone(this);
@ -122,11 +116,6 @@ namespace Passer.Humanoid {
}; };
fingers = new FingersTarget(this); fingers = new FingersTarget(this);
this.isLeft = isLeft;
this.side = isLeft ? Side.Left : Side.Right;
this.outward = this.isLeft ? Vector3.left : Vector3.right;
InitSubTargets();
} }
#if pCEREBELLUM #if pCEREBELLUM
@ -202,7 +191,7 @@ namespace Passer.Humanoid {
#if pUNITYXR #if pUNITYXR
public UnityXRHand unityXR = new UnityXRHand(); public UnityXRHand unityXR = new UnityXRHand();
#endif #endif
#if hVIVETRACKER #if hVIVETRACKER && UNITY_STANDALONE_WIN
public ViveTrackerArm viveTracker = new ViveTrackerArm(); public ViveTrackerArm viveTracker = new ViveTrackerArm();
#endif #endif
#if hWINDOWSMR && UNITY_WSA_10_0 #if hWINDOWSMR && UNITY_WSA_10_0
@ -211,9 +200,9 @@ namespace Passer.Humanoid {
#if hWAVEVR #if hWAVEVR
public WaveVRHand waveVR = new WaveVRHand(); public WaveVRHand waveVR = new WaveVRHand();
#endif #endif
//#if hNEURON //#if hNEURON
// public NeuronHand neuron = new NeuronHand(); // public NeuronHand neuron = new NeuronHand();
//#endif //#endif
#if hLEAP #if hLEAP
public LeapHand leap = new LeapHand(); public LeapHand leap = new LeapHand();
#endif #endif
@ -291,11 +280,9 @@ namespace Passer.Humanoid {
#if hWAVEVR #if hWAVEVR
waveVR, waveVR,
#endif #endif
#if hSTEAMVR && UNITY_STANDALONE_WIN #if hVIVETRACKER && UNITY_STANDALONE_WIN
#if hVIVETRACKER
viveTracker, viveTracker,
#endif #endif
#endif
#if hREALSENSE #if hREALSENSE
//realsenseHand, //realsenseHand,
#endif #endif
@ -334,7 +321,7 @@ namespace Passer.Humanoid {
#if hLEAP #if hLEAP
(leap.handSkeleton != null && leap.handSkeleton.status == Tracker.Status.Tracking) | (leap.handSkeleton != null && leap.handSkeleton.status == Tracker.Status.Tracking) |
#endif #endif
#if pUNITYXR && (hOCHAND || hVIVEHAND) #if pUNITYXR && (hOCHAND || hHTCVIVE)
(unityXR.handSkeleton != null && unityXR.handSkeleton.status == Tracker.Status.Tracking) | (unityXR.handSkeleton != null && unityXR.handSkeleton.status == Tracker.Status.Tracking) |
#endif #endif
false; false;
@ -390,7 +377,7 @@ namespace Passer.Humanoid {
get { return hand; } get { return hand; }
} }
public Transform stretchlessTarget; public Transform stretchlessTarget;
private TargetedBone[] subTargets; private readonly TargetedBone[] subTargets;
#region Shoulder #region Shoulder
@ -728,10 +715,7 @@ namespace Passer.Humanoid {
targetTransform.position = oldTarget.transform.position; targetTransform.position = oldTarget.transform.position;
targetTransform.rotation = oldTarget.transform.rotation; targetTransform.rotation = oldTarget.transform.rotation;
//HandTarget handTarget = Constructor(humanoid, oldTarget.isLeft, targetTransform); HandTarget handTarget = Constructor(humanoid, oldTarget.isLeft, targetTransform);
HandTarget handTarget = targetTransform.gameObject.AddComponent<HandTarget>();
handTarget.Constructor(humanoid, oldTarget.isLeft);
if (oldTarget.isLeft) { if (oldTarget.isLeft) {
humanoid.leftHandTarget = handTarget; humanoid.leftHandTarget = handTarget;
//handTarget.otherHand = humanoid.rightHandTarget; //handTarget.otherHand = humanoid.rightHandTarget;
@ -1210,7 +1194,11 @@ namespace Passer.Humanoid {
private HumanoidControl GetHumanoid() { private HumanoidControl GetHumanoid() {
// This does not work for prefabs // This does not work for prefabs
#if UNITY_6000_0_OR_NEWER
HumanoidControl[] humanoids = FindObjectsByType<HumanoidControl>(FindObjectsSortMode.None);
#else
HumanoidControl[] humanoids = FindObjectsOfType<HumanoidControl>(); HumanoidControl[] humanoids = FindObjectsOfType<HumanoidControl>();
#endif
for (int i = 0; i < humanoids.Length; i++) { for (int i = 0; i < humanoids.Length; i++) {
if ((humanoids[i].leftHandTarget != null && humanoids[i].leftHandTarget.transform == this.transform) || if ((humanoids[i].leftHandTarget != null && humanoids[i].leftHandTarget.transform == this.transform) ||
@ -1242,8 +1230,13 @@ namespace Passer.Humanoid {
handRigidbody = hand.bone.transform.gameObject.AddComponent<Rigidbody>(); handRigidbody = hand.bone.transform.gameObject.AddComponent<Rigidbody>();
} }
handRigidbody.mass = 1; handRigidbody.mass = 1;
#if UNITY_6000_0_OR_NEWER
handRigidbody.linearDamping = 0; handRigidbody.linearDamping = 0;
handRigidbody.angularDamping = 10; handRigidbody.angularDamping = 10;
#else
handRigidbody.drag = 0;
handRigidbody.angularDrag = 10;
#endif
handRigidbody.useGravity = false; handRigidbody.useGravity = false;
handRigidbody.isKinematic = true; handRigidbody.isKinematic = true;
handRigidbody.interpolation = RigidbodyInterpolation.None; handRigidbody.interpolation = RigidbodyInterpolation.None;
@ -1272,6 +1265,18 @@ namespace Passer.Humanoid {
#endif #endif
} }
// This function is called only when the humanoid is created
private static HandTarget Constructor(HumanoidControl humanoid, bool isLeft, Transform handTargetTransform) {
HandTarget handTarget = handTargetTransform.gameObject.AddComponent<HandTarget>();
handTarget.humanoid = humanoid;
handTarget.isLeft = isLeft;
handTarget.side = isLeft ? Side.Left : Side.Right;
handTarget.outward = handTarget.isLeft ? Vector3.left : Vector3.right;
handTarget.InitSubTargets();
return handTarget;
}
public override void NewComponent(HumanoidControl _humanoid) { public override void NewComponent(HumanoidControl _humanoid) {
humanoid = _humanoid; humanoid = _humanoid;
isLeft = (this == humanoid.leftHandTarget); isLeft = (this == humanoid.leftHandTarget);
@ -1382,13 +1387,10 @@ namespace Passer.Humanoid {
} }
handTarget = handTargetTransform.GetComponent<HandTarget>(); handTarget = handTargetTransform.GetComponent<HandTarget>();
if (handTarget == null) if (handTarget == null)
handTarget = handTargetTransform.gameObject.AddComponent<HandTarget>(); handTarget = Constructor(humanoid, isLeft, handTargetTransform);
} }
if (handTarget.subTargets == null)
handTarget.Constructor(humanoid, isLeft);
if (isLeft) if (isLeft)
humanoid.leftHandTarget = handTarget; humanoid.leftHandTarget = handTarget;
else else

View File

@ -12,18 +12,18 @@ namespace Passer {
private Vector3 startPosition; private Vector3 startPosition;
private Quaternion startRotation; private Quaternion startRotation;
void Start() { protected void Start() {
startPosition = transform.position; startPosition = transform.position;
startRotation = transform.rotation; startRotation = transform.rotation;
} }
void Update() { protected void Update() {
if (groundCollider == null && transform.position.y < 0) { if (groundCollider == null && transform.position.y < 0) {
MoveToStart(); MoveToStart();
} }
} }
private void OnCollisionEnter(Collision collision) { protected void OnCollisionEnter(Collision collision) {
if (collision.collider == groundCollider) { if (collision.collider == groundCollider) {
MoveToStart(); MoveToStart();
} }
@ -34,7 +34,11 @@ namespace Passer {
if (thisRigidbody != null) { if (thisRigidbody != null) {
thisRigidbody.MovePosition(new Vector3(startPosition.x, startPosition.y + 0.1F, startPosition.z)); thisRigidbody.MovePosition(new Vector3(startPosition.x, startPosition.y + 0.1F, startPosition.z));
thisRigidbody.MoveRotation(startRotation); thisRigidbody.MoveRotation(startRotation);
#if UNITY_6000_0_OR_NEWER
thisRigidbody.linearVelocity = Vector3.zero; thisRigidbody.linearVelocity = Vector3.zero;
#else
thisRigidbody.velocity = Vector3.zero;
#endif
thisRigidbody.angularVelocity = Vector3.zero; thisRigidbody.angularVelocity = Vector3.zero;
} }
} }

View File

@ -229,7 +229,11 @@ namespace Passer {
damper = -velocityTowardsTarget * damping; damper = -velocityTowardsTarget * damping;
//Compensate for absolute rigidbody speed (specifically when on a moving platform) //Compensate for absolute rigidbody speed (specifically when on a moving platform)
#if UNITY_6000_0_OR_NEWER
Vector3 residualVelocity = thisRigidbody.linearVelocity - velocityTowardsTarget; Vector3 residualVelocity = thisRigidbody.linearVelocity - velocityTowardsTarget;
#else
Vector3 residualVelocity = thisRigidbody.velocity - velocityTowardsTarget;
#endif
damper += residualVelocity * 10; damper += residualVelocity * 10;
} }
lastDistanceToTarget = distanceToTarget; lastDistanceToTarget = distanceToTarget;

View File

@ -30,8 +30,13 @@ namespace Passer {
public void CopyFromRigidbody(Rigidbody rb) { public void CopyFromRigidbody(Rigidbody rb) {
mass = rb.mass; mass = rb.mass;
#if UNITY_6000_0_OR_NEWER
drag = rb.linearDamping; drag = rb.linearDamping;
angularDrag = rb.angularDamping; angularDrag = rb.angularDamping;
#else
drag = rb.drag;
angularDrag = rb.angularDrag;
#endif
useGravity = rb.useGravity; useGravity = rb.useGravity;
isKinematic = rb.isKinematic; isKinematic = rb.isKinematic;
interpolation = rb.interpolation; interpolation = rb.interpolation;
@ -44,8 +49,13 @@ namespace Passer {
public void CopyToRigidbody(Rigidbody rb) { public void CopyToRigidbody(Rigidbody rb) {
rb.mass = mass; rb.mass = mass;
#if UNITY_6000_0_OR_NEWER
rb.linearDamping = drag; rb.linearDamping = drag;
rb.angularDamping = angularDrag; rb.angularDamping = angularDrag;
#else
rb.drag = drag;
rb.angularDrag = angularDrag;
#endif
rb.useGravity = useGravity; rb.useGravity = useGravity;
rb.isKinematic = isKinematic; rb.isKinematic = isKinematic;
rb.interpolation = interpolation; rb.interpolation = interpolation;

View File

@ -224,7 +224,11 @@ namespace Passer {
protected virtual void Awake() { protected virtual void Awake() {
Transform rootTransform = this.transform.root; Transform rootTransform = this.transform.root;
#if UNITY_6000_0_OR_NEWER
interactionModule = FindAnyObjectByType<InteractionModule>();
#else
interactionModule = FindObjectOfType<InteractionModule>(); interactionModule = FindObjectOfType<InteractionModule>();
#endif
if (interactionModule == null) if (interactionModule == null)
interactionModule = CreateInteractionModule(); interactionModule = CreateInteractionModule();
EventSystem eventSystem = interactionModule.GetComponent<EventSystem>(); EventSystem eventSystem = interactionModule.GetComponent<EventSystem>();
@ -585,7 +589,11 @@ namespace Passer {
if (rayType != RayType.Gravity) if (rayType != RayType.Gravity)
return; return;
#if UNITY_6000_0_OR_NEWER
rigidbody.linearVelocity = transform.forward * speed; rigidbody.linearVelocity = transform.forward * speed;
#else
rigidbody.velocity = transform.forward * speed;
#endif
} }
public void LaunchPrefab(GameObject prefab) { public void LaunchPrefab(GameObject prefab) {

View File

@ -694,7 +694,11 @@ namespace Passer {
Humanoid.HumanoidNetworking.ReenableNetworkSync(objRigidbody.gameObject); Humanoid.HumanoidNetworking.ReenableNetworkSync(objRigidbody.gameObject);
if (thisRigidbody != null) { if (thisRigidbody != null) {
#if UNITY_6000_0_OR_NEWER
objRigidbody.linearVelocity = thisRigidbody.linearVelocity; objRigidbody.linearVelocity = thisRigidbody.linearVelocity;
#else
objRigidbody.velocity = thisRigidbody.velocity;
#endif
objRigidbody.angularVelocity = thisRigidbody.angularVelocity; objRigidbody.angularVelocity = thisRigidbody.angularVelocity;
} }
@ -761,7 +765,7 @@ namespace Passer {
} }
} }
#endregion Rigidbody #endregion Rigidbody
#region Static Object #region Static Object
@ -807,7 +811,7 @@ namespace Passer {
#endregion Static Object #endregion Static Object
#endregion Release #endregion Release
#region Start #region Start