From c6475eebd20f42a5af1b1ea52ec41c0745801ec4 Mon Sep 17 00:00:00 2001 From: Ethan Cheung Date: Tue, 4 Jan 2022 14:45:18 +0800 Subject: [PATCH] enable non xr use for zinnia not to be merged directly -------------- both XRNodeHapticPulser and XRNodeVelocityEstimator uses XRNode for serialized property, cannot be modified readily to ignore those properties without losing the serialized data. I chose to complete #if out the components. PlatformDeviceAssociation (and deprecated LoadedXrDeviceAssociation) uses XRNode, XRDevice, XRSettings but some of the logic can be ignored, so I chose to #if just those parts. ------------------------------------- Zinnia.Runtime.asmdef added versionDefines XRNode and InputDevices are within com.unity.modules.xr XRDevice and XRSettings are within com.unity.modules.vr com.unity.modules.vr depends on com.unity.modules.xr although technically we would expect them both to be enabled in a vr project, I chose to make separate define symbols for each of them. -------------------------------- The following Tilia have reference to XR/VR: "io.extendreality.tilia.camerarigs.spatialsimulator.unity": "1.4.21", "io.extendreality.tilia.camerarigs.unityxr": "1.5.9", "io.extendreality.tilia.camerarigs.xrpluginframework.unity": "1.1.10", "io.extendreality.tilia.output.interactorhaptics.unity": "1.1.34", "io.extendreality.tilia.sdk.oculusintegration.unity": "1.3.19", "io.extendreality.tilia.sdk.steamvr.unity": "1.1.22", --- Runtime/Association/LoadedXrDeviceAssociation.cs | 6 ++++++ Runtime/Association/PlatformDeviceAssociation.cs | 8 ++++++++ Runtime/Haptics/XRNodeHapticPulser.cs | 6 ++++-- .../Tracking/Velocity/XRNodeVelocityEstimator.cs | 6 ++++-- Runtime/Zinnia.Runtime.asmdef | 15 ++++++++++++++- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Runtime/Association/LoadedXrDeviceAssociation.cs b/Runtime/Association/LoadedXrDeviceAssociation.cs index 4bdb68c1..e80f79da 100644 --- a/Runtime/Association/LoadedXrDeviceAssociation.cs +++ b/Runtime/Association/LoadedXrDeviceAssociation.cs @@ -5,7 +5,9 @@ using System; using System.Text.RegularExpressions; using UnityEngine; +#if UNITY_XR || UNITY_VR using UnityEngine.XR; +#endif /// /// Holds s to (de)activate based on the loaded XR device's name. @@ -23,7 +25,11 @@ public class LoadedXrDeviceAssociation : GameObjectsAssociation /// public override bool ShouldBeActive() { +#if UNITY_VR return Regex.IsMatch(XRSettings.loadedDeviceName, XrDeviceNamePattern); +#else + return false; +#endif } } } \ No newline at end of file diff --git a/Runtime/Association/PlatformDeviceAssociation.cs b/Runtime/Association/PlatformDeviceAssociation.cs index 1cdbcb03..700c1099 100644 --- a/Runtime/Association/PlatformDeviceAssociation.cs +++ b/Runtime/Association/PlatformDeviceAssociation.cs @@ -4,7 +4,9 @@ using Malimbe.XmlDocumentationAttribute; using System.Text.RegularExpressions; using UnityEngine; +#if UNITY_XR || UNITY_VR using UnityEngine.XR; +#endif /// /// Holds s to (de)activate based on the current platform and loaded XR device type. @@ -36,13 +38,19 @@ public override bool ShouldBeActive() { string modelName = ""; #if UNITY_2020_2_OR_NEWER +#if UNITY_XR InputDevice currentDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head); modelName = currentDevice != null && currentDevice.name != null ? currentDevice.name : ""; +#endif #else +#if UNITY_VR modelName = XRDevice.model; +#endif #endif return Regex.IsMatch(Application.platform.ToString(), PlatformPattern) && +#if UNITY_VR Regex.IsMatch(XRSettings.loadedDeviceName, XrSdkPattern) && +#endif Regex.IsMatch(modelName, XrModelPattern); } diff --git a/Runtime/Haptics/XRNodeHapticPulser.cs b/Runtime/Haptics/XRNodeHapticPulser.cs index 3266ace3..dfe5f46e 100644 --- a/Runtime/Haptics/XRNodeHapticPulser.cs +++ b/Runtime/Haptics/XRNodeHapticPulser.cs @@ -1,4 +1,5 @@ -namespace Zinnia.Haptics +#if UNITY_XR +namespace Zinnia.Haptics { using Malimbe.PropertySerializationAttribute; using Malimbe.XmlDocumentationAttribute; @@ -83,4 +84,5 @@ protected virtual byte[] GeneratePulseBuffer(float intensity, float duration) return clip; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Runtime/Tracking/Velocity/XRNodeVelocityEstimator.cs b/Runtime/Tracking/Velocity/XRNodeVelocityEstimator.cs index 747df74f..899283a2 100644 --- a/Runtime/Tracking/Velocity/XRNodeVelocityEstimator.cs +++ b/Runtime/Tracking/Velocity/XRNodeVelocityEstimator.cs @@ -1,4 +1,5 @@ -namespace Zinnia.Tracking.Velocity +#if UNITY_XR +namespace Zinnia.Tracking.Velocity { using Malimbe.MemberClearanceMethod; using Malimbe.PropertySerializationAttribute; @@ -66,4 +67,5 @@ protected virtual XRNodeState GetNodeState() return new XRNodeState(); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Runtime/Zinnia.Runtime.asmdef b/Runtime/Zinnia.Runtime.asmdef index 91aef1af..a366fb84 100644 --- a/Runtime/Zinnia.Runtime.asmdef +++ b/Runtime/Zinnia.Runtime.asmdef @@ -14,5 +14,18 @@ "Malimbe.XmlDocumentationAttribute.dll" ], "autoReferenced": true, - "defineConstraints": [] + "defineConstraints": [], + "versionDefines": [ + { + "name": "com.unity.modules.xr", + "expression": "", + "define": "UNITY_XR" + }, + { + "name": "com.unity.modules.vr", + "expression": "", + "define": "UNITY_VR" + } + ], + "noEngineReferences": false } \ No newline at end of file