UNITY 6 compatibility improvements

This commit is contained in:
Pascal Serrarens 2024-11-28 12:36:48 +01:00
parent fd9bc37467
commit ab5d034f6e
28 changed files with 199 additions and 41 deletions

View File

@ -52,7 +52,11 @@ namespace Passer.Tracking {
if (_hmd != null) if (_hmd != null)
return _hmd; return _hmd;
#if UNITY_6000_0_OR_NEWER
_hmd = FindAnyObjectByType<UnityXRHmd>();
#else
_hmd = FindObjectOfType<UnityXRHmd>(); _hmd = FindObjectOfType<UnityXRHmd>();
#endif
return _hmd; return _hmd;
} }
} }
@ -135,7 +139,7 @@ namespace Passer.Tracking {
Object.DestroyImmediate(plane.gameObject); Object.DestroyImmediate(plane.gameObject);
} }
#endregion Hmd #endregion Hmd
#region Controller #region Controller
@ -238,7 +242,7 @@ namespace Passer.Tracking {
#endregion #endregion
#endregion Manage #endregion Manage
#region Init #region Init

View File

@ -32,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>();
} }
@ -825,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;
#else
objRigidbody.velocity = handRigidbody.velocity; objRigidbody.velocity = handRigidbody.velocity;
#endif
objRigidbody.angularVelocity = handRigidbody.angularVelocity; objRigidbody.angularVelocity = handRigidbody.angularVelocity;
} }
HumanoidNetworking.ReenableNetworkSync(objRigidbody.gameObject); HumanoidNetworking.ReenableNetworkSync(objRigidbody.gameObject);
@ -853,7 +861,11 @@ 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;
#else
grabbedRigidbody.velocity = handRigidbody.velocity; grabbedRigidbody.velocity = handRigidbody.velocity;
#endif
grabbedRigidbody.angularVelocity = handRigidbody.angularVelocity; grabbedRigidbody.angularVelocity = handRigidbody.angularVelocity;
} }

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_2017_1_OR_NEWER
handTarget.handRigidbody.linearDamping = 0;
handTarget.handRigidbody.angularDamping = 10;
#else
handTarget.handRigidbody.drag = 0; handTarget.handRigidbody.drag = 0;
handTarget.handRigidbody.angularDrag = 10; 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

@ -1718,7 +1718,11 @@ namespace Passer.Humanoid {
public static List<HumanoidControl> FindLocalHumanoids() { public static List<HumanoidControl> FindLocalHumanoids() {
List<HumanoidControl> humanoidList = new List<HumanoidControl>(); List<HumanoidControl> humanoidList = new List<HumanoidControl>();
#if UNITY_6000_0_OR_NEWER
HumanoidControl[] foundHumanoids = UnityEngine.Object.FindObjectsByType<HumanoidControl>(FindObjectsSortMode.None);
#else
HumanoidControl[] foundHumanoids = UnityEngine.Object.FindObjectsOfType<HumanoidControl>(); HumanoidControl[] foundHumanoids = UnityEngine.Object.FindObjectsOfType<HumanoidControl>();
#endif
for (int i = 0; i < foundHumanoids.Length; i++) { for (int i = 0; i < foundHumanoids.Length; i++) {
if (!foundHumanoids[i].isRemote) { if (!foundHumanoids[i].isRemote) {
humanoidList.Add(foundHumanoids[i]); humanoidList.Add(foundHumanoids[i]);
@ -1728,7 +1732,11 @@ namespace Passer.Humanoid {
} }
public static IHumanoidNetworking GetLocalHumanoidNetworking() { public static IHumanoidNetworking GetLocalHumanoidNetworking() {
#if UNITY_6000_0_OR_NEWER
HumanoidPlayer[] humanoidNetworkings = UnityEngine.Object.FindObjectsByType<HumanoidPlayer>(FindObjectsSortMode.None);
#else
HumanoidPlayer[] humanoidNetworkings = UnityEngine.Object.FindObjectsOfType<HumanoidPlayer>(); HumanoidPlayer[] humanoidNetworkings = UnityEngine.Object.FindObjectsOfType<HumanoidPlayer>();
#endif
foreach (IHumanoidNetworking humanoidNetworking in humanoidNetworkings) { foreach (IHumanoidNetworking humanoidNetworking in humanoidNetworkings) {
if (humanoidNetworking.isLocal) if (humanoidNetworking.isLocal)
return humanoidNetworking; return humanoidNetworking;

View File

@ -6,18 +6,19 @@ namespace Passer {
protected NetworkingStarter networkingStarter; protected NetworkingStarter networkingStarter;
protected UnityEngine.UI.Text textcomponent; protected UnityEngine.UI.Text textcomponent;
void Start() { protected void Start() {
#if UNITY_6000_0_OR_NEWER
networkingStarter = Object.FindAnyObjectByType<NetworkingStarter>();
#else
networkingStarter = FindObjectOfType<NetworkingStarter>(); networkingStarter = FindObjectOfType<NetworkingStarter>();
#endif
textcomponent = GetComponent<UnityEngine.UI.Text>(); textcomponent = GetComponent<UnityEngine.UI.Text>();
} }
void Update() { protected void Update() {
#if hNW_UNET || hNW_PHOTON #if hNW_UNET || hNW_PHOTON
if (networkingStarter == null) if (networkingStarter == null)
return; return;
//if (textcomponent != null)
// textcomponent.text = networkingStarter.networkingStatus.ToString();
#endif #endif
} }
} }

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;
#else
Vector3 residualVelocity = handRigidbody.velocity - velocityTowardsTarget; 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);
#else
handRigidbody.velocity = Vector3.MoveTowards(handRigidbody.velocity, velocityTarget, MaxVelocityChange); 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;
angularDrag = rb.angularDamping;
#else
drag = rb.drag; drag = rb.drag;
angularDrag = rb.angularDrag; 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.angularDamping = angularDrag;
#else
rb.drag = drag; rb.drag = drag;
rb.angularDrag = angularDrag; rb.angularDrag = angularDrag;
#endif
rb.useGravity = useGravity; rb.useGravity = useGravity;
rb.isKinematic = isKinematic; rb.isKinematic = isKinematic;
rb.interpolation = interpolation; rb.interpolation = interpolation;

View File

@ -649,7 +649,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].leftFootTarget != null && humanoids[i].leftFootTarget.transform == this.transform) || if ((humanoids[i].leftFootTarget != null && humanoids[i].leftFootTarget.transform == this.transform) ||
@ -829,7 +833,7 @@ namespace Passer.Humanoid {
toes.MatchTargetToAvatar(); toes.MatchTargetToAvatar();
} }
#endregion #endregion
#region Update #region Update

View File

@ -1163,7 +1163,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) ||
@ -1195,8 +1199,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.angularDamping = 10;
#else
handRigidbody.drag = 0; handRigidbody.drag = 0;
handRigidbody.angularDrag = 10; handRigidbody.angularDrag = 10;
#endif
handRigidbody.useGravity = false; handRigidbody.useGravity = false;
handRigidbody.isKinematic = true; handRigidbody.isKinematic = true;
handRigidbody.interpolation = RigidbodyInterpolation.None; handRigidbody.interpolation = RigidbodyInterpolation.None;

View File

@ -750,7 +750,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].headTarget != null && humanoids[i].headTarget.transform == this.transform) if (humanoids[i].headTarget != null && humanoids[i].headTarget.transform == this.transform)
@ -876,7 +880,7 @@ namespace Passer.Humanoid {
#endif #endif
} }
#endregion #endregion
#region Update #region Update
@ -1218,15 +1222,6 @@ namespace Passer.Humanoid {
} }
} }
public void DisableVR() {
UnityEngine.XR.XRSettings.LoadDeviceByName("None");
}
public void EnableVR() {
// Just oculus for now
UnityEngine.XR.XRSettings.LoadDeviceByName("Oculus");
}
#endregion #endregion
} }
} }

View File

@ -461,7 +461,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].hipsTarget != null && humanoids[i].hipsTarget.transform == this.transform) if (humanoids[i].hipsTarget != null && humanoids[i].hipsTarget.transform == this.transform)
@ -615,7 +619,7 @@ namespace Passer.Humanoid {
} }
#endregion #endregion
#region Update #region Update

View File

@ -51,7 +51,11 @@ namespace Passer {
/// </summary> /// </summary>
/// <returns>The found humanoid, null if no local humanoid has been found</returns> /// <returns>The found humanoid, null if no local humanoid has been found</returns>
protected HumanoidControl FindHumanoid() { protected HumanoidControl FindHumanoid() {
#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].isRemote == false) if (humanoids[i].isRemote == false)
return humanoids[i]; return humanoids[i];

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;
#else
thisRigidbody.velocity = Vector3.zero; thisRigidbody.velocity = Vector3.zero;
#endif
thisRigidbody.angularVelocity = Vector3.zero; thisRigidbody.angularVelocity = Vector3.zero;
} }
} }

View File

@ -1,6 +1,4 @@
using System.Collections; using UnityEngine;
using System.Collections.Generic;
using UnityEngine;
namespace Passer.Humanoid { namespace Passer.Humanoid {
@ -9,7 +7,11 @@ namespace Passer.Humanoid {
protected HandTarget handTarget; protected HandTarget handTarget;
protected void Start() { protected void Start() {
#if UNITY_6000_0_OR_NEWER
HumanoidControl[] humanoids = FindObjectsByType<HumanoidControl>(FindObjectsSortMode.None);
#else
HumanoidControl[] humanoids = FindObjectsOfType<HumanoidControl>(); HumanoidControl[] humanoids = FindObjectsOfType<HumanoidControl>();
#endif
if (humanoids.Length != 1) if (humanoids.Length != 1)
return; return;

View File

@ -29,7 +29,11 @@ namespace Passer.Humanoid {
private void Awake() { private void Awake() {
HumanoidControl humanoidInScene = GetComponentInParent<HumanoidControl>(); HumanoidControl humanoidInScene = GetComponentInParent<HumanoidControl>();
if (humanoidInScene == null) { if (humanoidInScene == null) {
#if UNITY_6000_0_OR_NEWER
HumanoidControl[] humanoids = FindObjectsByType<HumanoidControl>(FindObjectsSortMode.None);
#else
HumanoidControl[] humanoids = FindObjectsOfType<HumanoidControl>(); HumanoidControl[] humanoids = FindObjectsOfType<HumanoidControl>();
#endif
foreach (HumanoidControl humanoid in humanoids) { foreach (HumanoidControl humanoid in humanoids) {
if (humanoid.isRemote == false) if (humanoid.isRemote == false)
this.humanoid = humanoid; this.humanoid = humanoid;

View File

@ -21,7 +21,11 @@ namespace Passer {
} }
private void OnSceneLoad(Scene scene, LoadSceneMode mode) { private void OnSceneLoad(Scene scene, LoadSceneMode mode) {
#if UNITY_6000_0_OR_NEWER
Canvas[] canvases = FindObjectsByType<Canvas>(FindObjectsSortMode.None);
#else
Canvas[] canvases = FindObjectsOfType<Canvas>(); Canvas[] canvases = FindObjectsOfType<Canvas>();
#endif
foreach (Canvas canvas in canvases) foreach (Canvas canvas in canvases)
canvas.worldCamera = Camera.main; canvas.worldCamera = Camera.main;
} }

View File

@ -43,7 +43,11 @@ namespace Passer {
#if UNITY_EDITOR #if UNITY_EDITOR
UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoad; UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoad;
#if UNITY_6000_0_OR_NEWER
HumanoidControl humanoid = FindAnyObjectByType<HumanoidControl>();
#else
HumanoidControl humanoid = FindObjectOfType<HumanoidControl>(); HumanoidControl humanoid = FindObjectOfType<HumanoidControl>();
#endif
if (humanoid == null) { if (humanoid == null) {
string visitorScenePath = HumanoidPreferences.visitorSceneName; string visitorScenePath = HumanoidPreferences.visitorSceneName;
if (!string.IsNullOrEmpty(visitorScenePath)) { if (!string.IsNullOrEmpty(visitorScenePath)) {
@ -57,17 +61,29 @@ namespace Passer {
private void OnSceneLoad(Scene _, LoadSceneMode _1) { private void OnSceneLoad(Scene _, LoadSceneMode _1) {
#if UNITY_EDITOR #if UNITY_EDITOR
#if UNITY_6000_0_OR_NEWER
SiteNavigator[] siteNavigators = FindObjectsByType<SiteNavigator>(FindObjectsSortMode.None);
#else
SiteNavigator[] siteNavigators = FindObjectsOfType<SiteNavigator>(); SiteNavigator[] siteNavigators = FindObjectsOfType<SiteNavigator>();
#endif
foreach (SiteNavigator siteNavigator in siteNavigators) { foreach (SiteNavigator siteNavigator in siteNavigators) {
siteNavigator.startScene = null; siteNavigator.startScene = null;
siteNavigator.startSite = null; siteNavigator.startSite = null;
} }
#if UNITY_6000_0_OR_NEWER
HumanoidControl pawn = FindAnyObjectByType<HumanoidControl>();
#else
HumanoidControl pawn = FindObjectOfType<HumanoidControl>(); HumanoidControl pawn = FindObjectOfType<HumanoidControl>();
#endif
if (pawn == null) if (pawn == null)
return; return;
#if UNITY_6000_0_OR_NEWER
HumanoidSpawnPoint[] spawnPoints = FindObjectsByType<HumanoidSpawnPoint>(FindObjectsSortMode.None);
#else
HumanoidSpawnPoint[] spawnPoints = FindObjectsOfType<HumanoidSpawnPoint>(); HumanoidSpawnPoint[] spawnPoints = FindObjectsOfType<HumanoidSpawnPoint>();
#endif
foreach (HumanoidSpawnPoint spawnPoint in spawnPoints) { foreach (HumanoidSpawnPoint spawnPoint in spawnPoints) {
if (spawnPoint.isFree) if (spawnPoint.isFree)
pawn.transform.position = spawnPoint.transform.position; pawn.transform.position = spawnPoint.transform.position;

View File

@ -16,7 +16,11 @@ namespace Passer {
UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoad; UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoad;
#if UNITY_6000_0_OR_NEWER
HumanoidControl pawn = FindAnyObjectByType<HumanoidControl>();
#else
HumanoidControl pawn = FindObjectOfType<HumanoidControl>(); HumanoidControl pawn = FindObjectOfType<HumanoidControl>();
#endif
if (pawn == null) { if (pawn == null) {
UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName); UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName);
} }
@ -26,7 +30,11 @@ namespace Passer {
private void OnSceneLoad(UnityEngine.SceneManagement.Scene _, LoadSceneMode _1) { private void OnSceneLoad(UnityEngine.SceneManagement.Scene _, LoadSceneMode _1) {
#if UNITY_EDITOR #if UNITY_EDITOR
#if UNITY_6000_0_OR_NEWER
SiteNavigator siteNavigator = FindAnyObjectByType<SiteNavigator>();
#else
SiteNavigator siteNavigator = FindObjectOfType<SiteNavigator>(); SiteNavigator siteNavigator = FindObjectOfType<SiteNavigator>();
#endif
if (siteNavigator != null) { if (siteNavigator != null) {
siteNavigator.startScene = thisSceneName; siteNavigator.startScene = thisSceneName;
} }

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;
#else
Vector3 residualVelocity = thisRigidbody.velocity - velocityTowardsTarget; 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;
angularDrag = rb.angularDamping;
#else
drag = rb.drag; drag = rb.drag;
angularDrag = rb.angularDrag; 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.angularDamping = angularDrag;
#else
rb.drag = drag; rb.drag = drag;
rb.angularDrag = angularDrag; rb.angularDrag = angularDrag;
#endif
rb.useGravity = useGravity; rb.useGravity = useGravity;
rb.isKinematic = isKinematic; rb.isKinematic = isKinematic;
rb.interpolation = interpolation; rb.interpolation = interpolation;

View File

@ -46,13 +46,17 @@ namespace Passer.Humanoid {
} }
} }
private void Awake() { protected void Awake() {
#if UNITY_6000_0_OR_NEWER
HumanoidControl humanoid = Object.FindAnyObjectByType<HumanoidControl>();
#else
HumanoidControl humanoid = FindObjectOfType<HumanoidControl>(); HumanoidControl humanoid = FindObjectOfType<HumanoidControl>();
#endif
if (humanoid == null) if (humanoid == null)
return; return;
Vector3 humanoidXZ = new Vector3(humanoid.transform.position.x, 0, humanoid.transform.position.z); Vector3 humanoidXZ = new(humanoid.transform.position.x, 0, humanoid.transform.position.z);
Vector3 thisXZ = new Vector3(this.transform.position.x, 0, this.transform.position.z); Vector3 thisXZ = new(this.transform.position.x, 0, this.transform.position.z);
float distance = Vector3.Distance(humanoidXZ, thisXZ); float distance = Vector3.Distance(humanoidXZ, thisXZ);
if (distance < radius || isFree) if (distance < radius || isFree)
humanoid.transform.MoveTo(this.transform.position); humanoid.transform.MoveTo(this.transform.position);

View File

@ -256,7 +256,11 @@ namespace Passer {
if (pointers == null) if (pointers == null)
pointers = new InteractionPointer[maxInteractions]; // 0 = left index, 1 = right index, 2 = head, 3 = controller pointers = new InteractionPointer[maxInteractions]; // 0 = left index, 1 = right index, 2 = head, 3 = controller
#if UNITY_6000_0_OR_NEWER
EventSystem eventSystem = FindAnyObjectByType<EventSystem>();
#else
EventSystem eventSystem = GameObject.FindObjectOfType<EventSystem>(); EventSystem eventSystem = GameObject.FindObjectOfType<EventSystem>();
#endif
if (eventSystem == null) if (eventSystem == null)
eventSystem = humanoid.gameObject.AddComponent<EventSystem>(); eventSystem = humanoid.gameObject.AddComponent<EventSystem>();
@ -346,7 +350,7 @@ namespace Passer {
pointer.ProcessTouch(); pointer.ProcessTouch();
} }
#endregion #endregion
public Vector3 GetFocusPoint(int inputDeviceID) { public Vector3 GetFocusPoint(int inputDeviceID) {
return pointers[inputDeviceID].focusPosition; return pointers[inputDeviceID].focusPosition;

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;
#else
rigidbody.velocity = transform.forward * speed; 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;
#else
objRigidbody.velocity = thisRigidbody.velocity; 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

View File

@ -54,7 +54,11 @@ namespace Passer {
if (spawnPoints != null && spawnPoints.Length > 0) if (spawnPoints != null && spawnPoints.Length > 0)
return; return;
#if UNITY_6000_0_OR_NEWER
spawnPoints = FindObjectsByType<SpawnPoint>(FindObjectsSortMode.None);
#else
spawnPoints = FindObjectsOfType<SpawnPoint>(); spawnPoints = FindObjectsOfType<SpawnPoint>();
#endif
if (spawnPoints.Length == 0) { if (spawnPoints.Length == 0) {
SpawnPoint thisSpawnPoint = this.gameObject.AddComponent<SpawnPoint>(); SpawnPoint thisSpawnPoint = this.gameObject.AddComponent<SpawnPoint>();
spawnPoints = new SpawnPoint[] { thisSpawnPoint }; spawnPoints = new SpawnPoint[] { thisSpawnPoint };

View File

@ -1,6 +1,4 @@
using System.Collections; using UnityEngine;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
namespace Passer { namespace Passer {
@ -18,7 +16,7 @@ namespace Passer {
this.site = site; this.site = site;
} }
private void OnEnable() { protected void OnEnable() {
if (site == null) if (site == null)
return; return;
@ -28,7 +26,11 @@ namespace Passer {
} }
private void GoToSite() { private void GoToSite() {
#if UNITY_6000_0_OR_NEWER
SiteNavigator siteNavigator = FindAnyObjectByType<SiteNavigator>();
#else
SiteNavigator siteNavigator = FindObjectOfType<SiteNavigator>(); SiteNavigator siteNavigator = FindObjectOfType<SiteNavigator>();
#endif
if (siteNavigator == null) { if (siteNavigator == null) {
Debug.LogError("Could not find a site navigator"); Debug.LogError("Could not find a site navigator");
return; return;

View File

@ -150,7 +150,11 @@ namespace Passer {
} }
protected void ShowSite(VisitorSites.Site site, int position) { protected void ShowSite(VisitorSites.Site site, int position) {
#if UNITY_6000_0_OR_NEWER
SiteNavigator siteNavigator = FindAnyObjectByType<SiteNavigator>();
#else
SiteNavigator siteNavigator = FindObjectOfType<SiteNavigator>(); SiteNavigator siteNavigator = FindObjectOfType<SiteNavigator>();
#endif
if (siteNavigator == null) if (siteNavigator == null)
Debug.LogError("Could not find a site navigator"); Debug.LogError("Could not find a site navigator");
@ -210,7 +214,7 @@ namespace Passer {
} }
#endregion #endregion
public void AddSite(string siteName, string siteLocation) { public void AddSite(string siteName, string siteLocation) {
//Debug.Log("Add site " + siteName); //Debug.Log("Add site " + siteName);
@ -233,7 +237,11 @@ namespace Passer {
} }
private void GoToSite(VisitorSites.Site site) { private void GoToSite(VisitorSites.Site site) {
#if UNITY_6000_0_OR_NEWER
SiteNavigator siteNavigator = FindAnyObjectByType<SiteNavigator>();
#else
SiteNavigator siteNavigator = FindObjectOfType<SiteNavigator>(); SiteNavigator siteNavigator = FindObjectOfType<SiteNavigator>();
#endif
if (siteNavigator == null) { if (siteNavigator == null) {
Debug.LogError("Could not find a site navigator"); Debug.LogError("Could not find a site navigator");
return; return;

View File

@ -406,7 +406,11 @@ namespace Passer {
if (avatarIndex < 0 || avatarIndex > avatars.Count) if (avatarIndex < 0 || avatarIndex > avatars.Count)
return; return;
#if UNITY_6000_0_OR_NEWER
HumanoidControl humanoid = FindAnyObjectByType<HumanoidControl>();
#else
HumanoidControl humanoid = FindObjectOfType<HumanoidControl>(); HumanoidControl humanoid = FindObjectOfType<HumanoidControl>();
#endif
if (humanoid == null) if (humanoid == null)
return; return;
@ -420,7 +424,11 @@ namespace Passer {
} }
private static IEnumerator RetrieveAvatarAsync(Possession possession) { private static IEnumerator RetrieveAvatarAsync(Possession possession) {
#if UNITY_6000_0_OR_NEWER
HumanoidControl humanoid = FindAnyObjectByType<HumanoidControl>();
#else
HumanoidControl humanoid = FindObjectOfType<HumanoidControl>(); HumanoidControl humanoid = FindObjectOfType<HumanoidControl>();
#endif
if (humanoid == null) if (humanoid == null)
yield break; yield break;