diff --git a/Assets/HTC.UnityPlugin/VRModule/Editor/VRModuleManagerEditor.cs b/Assets/HTC.UnityPlugin/VRModule/Editor/VRModuleManagerEditor.cs index fa2228a4..eb94b31d 100644 --- a/Assets/HTC.UnityPlugin/VRModule/Editor/VRModuleManagerEditor.cs +++ b/Assets/HTC.UnityPlugin/VRModule/Editor/VRModuleManagerEditor.cs @@ -1,8 +1,10 @@ //========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== using System; +using System.Collections; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Reflection; using UnityEditor; using UnityEditor.Callbacks; @@ -16,7 +18,7 @@ public class VRModuleManagerEditor : UnityEditor.AssetModificationProcessor , UnityEditor.Build.IActiveBuildTargetChanged #endif { - private class SymbolRequirement + public class SymbolRequirement { public class ReqFieldInfo { @@ -183,12 +185,19 @@ public bool Validate() } } + public abstract class SymbolRequirementCollection : List { } + private static List s_symbolReqList; static VRModuleManagerEditor() { s_symbolReqList = new List(); + foreach (var type in Assembly.GetAssembly(typeof(SymbolRequirementCollection)).GetTypes().Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(SymbolRequirementCollection)))) + { + s_symbolReqList.AddRange((SymbolRequirementCollection)Activator.CreateInstance(type)); + } + s_symbolReqList.Add(new SymbolRequirement() { symbol = "VIU_PLUGIN", @@ -196,156 +205,6 @@ static VRModuleManagerEditor() reqFileNames = new string[] { "ViveInput.cs", "VRModuleManagerEditor.cs" }, }); - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_STEAMVR", - reqTypeNames = new string[] { "Valve.VR.OpenVR" }, - reqFileNames = new string[] { "openvr_api.cs" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_STEAMVR_1_1_1", - reqTypeNames = new string[] { "SteamVR_Utils+Event" }, - reqFileNames = new string[] { "SteamVR_Utils.cs" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_STEAMVR_1_2_0_OR_NEWER", - reqTypeNames = new string[] { "SteamVR_Events" }, - reqFileNames = new string[] { "SteamVR_Events.cs" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_STEAMVR_1_2_1_OR_NEWER", - reqMethods = new SymbolRequirement.ReqMethodInfo[] - { - new SymbolRequirement.ReqMethodInfo() - { - typeName = "SteamVR_Events", - name = "System", - argTypeNames = new string[] { "Valve.VR.EVREventType" }, - bindingAttr = BindingFlags.Public | BindingFlags.Static, - } - }, - reqFileNames = new string[] { "SteamVR_Events.cs" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_STEAMVR_1_2_2_OR_NEWER", - reqFields = new SymbolRequirement.ReqFieldInfo[] - { - new SymbolRequirement.ReqFieldInfo() - { - typeName = "SteamVR_ExternalCamera+Config", - name = "r", - bindingAttr = BindingFlags.Public | BindingFlags.Instance, - } - }, - reqFileNames = new string[] { "SteamVR_ExternalCamera.cs" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_STEAMVR_1_2_3_OR_NEWER", - reqMethods = new SymbolRequirement.ReqMethodInfo[] - { - new SymbolRequirement.ReqMethodInfo() - { - typeName = "Valve.VR.CVRSystem", - name = "IsInputAvailable", - bindingAttr = BindingFlags.Public | BindingFlags.Instance, - } - }, - reqFileNames = new string[] { "openvr_api.cs" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_STEAMVR_2_0_0_OR_NEWER", - reqTypeNames = new string[] { "Valve.VR.SteamVR" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_STEAMVR_2_1_0_OR_NEWER", - reqTypeNames = new string[] { "Valve.VR.SteamVR_ActionSet_Manager" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_OCULUSVR", - reqTypeNames = new string[] { "OVRInput" }, - reqFileNames = new string[] { "OVRInput.cs" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_GOOGLEVR", - reqTypeNames = new string[] { "GvrUnitySdkVersion" }, - reqFileNames = new string[] { "GvrUnitySdkVersion.cs" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_GOOGLEVR_1_150_0_NEWER", - reqTypeNames = new string[] { "GvrControllerInputDevice" }, - reqFileNames = new string[] { "GvrControllerInputDevice.cs" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_WAVEVR", - reqTypeNames = new string[] { "WaveVR" }, - reqFileNames = new string[] { "WaveVR.cs" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_WAVEVR_2_0_32_OR_NEWER", - reqMethods = new SymbolRequirement.ReqMethodInfo[] - { - new SymbolRequirement.ReqMethodInfo() - { - typeName = "wvr.Interop", - name = "WVR_GetInputDeviceState", - argTypeNames = new string[] - { - "wvr.WVR_DeviceType", - "System.UInt32", - "System.UInt32&", - "System.UInt32&", - "wvr.WVR_AnalogState_t[]", - "System.UInt32", - }, - bindingAttr = BindingFlags.Public | BindingFlags.Static, - } - }, - reqFileNames = new string[] { "wvr.cs" }, - }); - - s_symbolReqList.Add(new SymbolRequirement() - { - symbol = "VIU_WAVEVR_2_1_0_OR_NEWER", - reqTypeNames = new string[] { "wvr.WVR_InputId" }, - validateFunc = (req) => - { - Type wvrInputIdType; - if (SymbolRequirement.s_foundTypes.TryGetValue("wvr.WVR_InputId", out wvrInputIdType) && wvrInputIdType.IsEnum) - { - if (Enum.IsDefined(wvrInputIdType, "WVR_InputId_Alias1_Digital_Trigger")) - { - return true; - } - } - return false; - }, - reqFileNames = new string[] { "wvr.cs" }, - }); - // Obsolete symbol, will be removed in all condition s_symbolReqList.Add(new SymbolRequirement() { diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/GoogleVRModuleEditor.cs b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/GoogleVRModuleEditor.cs new file mode 100644 index 00000000..c0c40b68 --- /dev/null +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/GoogleVRModuleEditor.cs @@ -0,0 +1,27 @@ +//========= Copyright 2016-2018, HTC Corporation. All rights reserved. =========== + +using SymbolRequirement = HTC.UnityPlugin.VRModuleManagement.VRModuleManagerEditor.SymbolRequirement; +using SymbolRequirementCollection = HTC.UnityPlugin.VRModuleManagement.VRModuleManagerEditor.SymbolRequirementCollection; + +namespace HTC.UnityPlugin.VRModuleManagement +{ + public class GoogleVRSymbolRequirementCollection : SymbolRequirementCollection + { + public GoogleVRSymbolRequirementCollection() + { + Add(new SymbolRequirement() + { + symbol = "VIU_GOOGLEVR", + reqTypeNames = new string[] { "GvrUnitySdkVersion" }, + reqFileNames = new string[] { "GvrUnitySdkVersion.cs" }, + }); + + Add(new SymbolRequirement() + { + symbol = "VIU_GOOGLEVR_1_150_0_NEWER", + reqTypeNames = new string[] { "GvrControllerInputDevice" }, + reqFileNames = new string[] { "GvrControllerInputDevice.cs" }, + }); + } + } +} \ No newline at end of file diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/GoogleVRModuleEditor.cs.meta b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/GoogleVRModuleEditor.cs.meta new file mode 100644 index 00000000..2abefb7a --- /dev/null +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/GoogleVRModuleEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3ed2561d406e73a48af2cdd0594e9516 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/OculusVRModuleEditor.cs b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/OculusVRModuleEditor.cs new file mode 100644 index 00000000..5cabb6b6 --- /dev/null +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/OculusVRModuleEditor.cs @@ -0,0 +1,20 @@ +//========= Copyright 2016-2018, HTC Corporation. All rights reserved. =========== + +using SymbolRequirement = HTC.UnityPlugin.VRModuleManagement.VRModuleManagerEditor.SymbolRequirement; +using SymbolRequirementCollection = HTC.UnityPlugin.VRModuleManagement.VRModuleManagerEditor.SymbolRequirementCollection; + +namespace HTC.UnityPlugin.VRModuleManagement +{ + public class OculusVRSymbolRequirementCollection : SymbolRequirementCollection + { + public OculusVRSymbolRequirementCollection() + { + Add(new SymbolRequirement() + { + symbol = "VIU_OCULUSVR", + reqTypeNames = new string[] { "OVRInput" }, + reqFileNames = new string[] { "OVRInput.cs" }, + }); + } + } +} \ No newline at end of file diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/OculusVRModuleEditor.cs.meta b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/OculusVRModuleEditor.cs.meta new file mode 100644 index 00000000..2ad7f3e4 --- /dev/null +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/OculusVRModuleEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bcd15f6aecadeae40a05d47638446aeb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/SteamVRModuleEditor.cs b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/SteamVRModuleEditor.cs new file mode 100644 index 00000000..fcbb4873 --- /dev/null +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/SteamVRModuleEditor.cs @@ -0,0 +1,119 @@ +//========= Copyright 2016-2018, HTC Corporation. All rights reserved. =========== + +using System.Reflection; +using SymbolRequirement = HTC.UnityPlugin.VRModuleManagement.VRModuleManagerEditor.SymbolRequirement; +using SymbolRequirementCollection = HTC.UnityPlugin.VRModuleManagement.VRModuleManagerEditor.SymbolRequirementCollection; + +namespace HTC.UnityPlugin.VRModuleManagement +{ + public class SteamVRSymbolRequirementCollection : SymbolRequirementCollection + { + public SteamVRSymbolRequirementCollection() + { + Add(new SymbolRequirement() + { + symbol = "VIU_OPENVR_API", + reqTypeNames = new string[] { "Valve.VR.OpenVR" }, + reqFileNames = new string[] { "openvr_api.cs" }, + }); + + Add(new SymbolRequirement() + { + symbol = "VIU_STEAMVR", + reqTypeNames = new string[] { "Valve.VR.OpenVR" }, + reqAnyTypeNames = new string[] { "SteamVR", "Valve.VR.SteamVR" }, + reqFileNames = new string[] { "openvr_api.cs", "SteamVR.cs" }, + }); + + Add(new SymbolRequirement() + { + symbol = "VIU_STEAMVR_1_1_1", + reqTypeNames = new string[] { "SteamVR_Utils+Event" }, + reqFileNames = new string[] { "SteamVR_Utils.cs" }, + }); + + Add(new SymbolRequirement() + { + symbol = "VIU_STEAMVR_1_2_0_OR_NEWER", + reqTypeNames = new string[] { "SteamVR_Events" }, + reqFileNames = new string[] { "SteamVR_Events.cs" }, + }); + + Add(new SymbolRequirement() + { + symbol = "VIU_STEAMVR_1_2_1_OR_NEWER", + reqMethods = new SymbolRequirement.ReqMethodInfo[] + { + new SymbolRequirement.ReqMethodInfo() + { + typeName = "SteamVR_Events", + name = "System", + argTypeNames = new string[] { "Valve.VR.EVREventType" }, + bindingAttr = BindingFlags.Public | BindingFlags.Static, + } + }, + reqFileNames = new string[] { "SteamVR_Events.cs" }, + }); + + Add(new SymbolRequirement() + { + symbol = "VIU_STEAMVR_1_2_2_OR_NEWER", + reqFields = new SymbolRequirement.ReqFieldInfo[] + { + new SymbolRequirement.ReqFieldInfo() + { + typeName = "SteamVR_ExternalCamera+Config", + name = "r", + bindingAttr = BindingFlags.Public | BindingFlags.Instance, + } + }, + reqFileNames = new string[] { "SteamVR_ExternalCamera.cs" }, + }); + + Add(new SymbolRequirement() + { + symbol = "VIU_STEAMVR_1_2_3_OR_NEWER", + reqMethods = new SymbolRequirement.ReqMethodInfo[] + { + new SymbolRequirement.ReqMethodInfo() + { + typeName = "Valve.VR.CVRSystem", + name = "IsInputAvailable", + bindingAttr = BindingFlags.Public | BindingFlags.Instance, + } + }, + reqFileNames = new string[] { "openvr_api.cs" }, + }); + + Add(new SymbolRequirement() + { + symbol = "VIU_STEAMVR_2_0_0_OR_NEWER", + reqTypeNames = new string[] { "Valve.VR.SteamVR" }, + }); + + Add(new SymbolRequirement() + { + symbol = "VIU_STEAMVR_2_1_0_OR_NEWER", + reqTypeNames = new string[] { "Valve.VR.SteamVR_ActionSet_Manager" }, + }); + + Add(new SymbolRequirement() + { + symbol = "VIU_STEAMVR_2_2_0_OR_NEWER", + reqMethods = new SymbolRequirement.ReqMethodInfo[] + { + new SymbolRequirement.ReqMethodInfo() + { + typeName = "Valve.VR.SteamVR_ActionSet_Manager", + name = "UpdateActionStates", + argTypeNames = new string[] + { + "System.Boolean", + }, + bindingAttr = BindingFlags.Public | BindingFlags.Static, + } + }, + }); + } + } +} \ No newline at end of file diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/SteamVRModuleEditor.cs.meta b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/SteamVRModuleEditor.cs.meta new file mode 100644 index 00000000..6b545262 --- /dev/null +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/SteamVRModuleEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: de219d81bd5f2054fb730d1e02ca64dc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/WaveVRModuleEditor.cs b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/WaveVRModuleEditor.cs new file mode 100644 index 00000000..a67db156 --- /dev/null +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/WaveVRModuleEditor.cs @@ -0,0 +1,65 @@ +//========= Copyright 2016-2018, HTC Corporation. All rights reserved. =========== + +using System; +using System.Reflection; +using SymbolRequirement = HTC.UnityPlugin.VRModuleManagement.VRModuleManagerEditor.SymbolRequirement; +using SymbolRequirementCollection = HTC.UnityPlugin.VRModuleManagement.VRModuleManagerEditor.SymbolRequirementCollection; + +namespace HTC.UnityPlugin.VRModuleManagement +{ + public class WaveVRSymbolRequirementCollection : SymbolRequirementCollection + { + public WaveVRSymbolRequirementCollection() + { + Add(new SymbolRequirement() + { + symbol = "VIU_WAVEVR", + reqTypeNames = new string[] { "WaveVR" }, + reqFileNames = new string[] { "WaveVR.cs" }, + }); + + Add(new SymbolRequirement() + { + symbol = "VIU_WAVEVR_2_0_32_OR_NEWER", + reqMethods = new SymbolRequirement.ReqMethodInfo[] + { + new SymbolRequirement.ReqMethodInfo() + { + typeName = "wvr.Interop", + name = "WVR_GetInputDeviceState", + argTypeNames = new string[] + { + "wvr.WVR_DeviceType", + "System.UInt32", + "System.UInt32&", + "System.UInt32&", + "wvr.WVR_AnalogState_t[]", + "System.UInt32", + }, + bindingAttr = BindingFlags.Public | BindingFlags.Static, + } + }, + reqFileNames = new string[] { "wvr.cs" }, + }); + + Add(new SymbolRequirement() + { + symbol = "VIU_WAVEVR_2_1_0_OR_NEWER", + reqTypeNames = new string[] { "wvr.WVR_InputId" }, + validateFunc = (req) => + { + Type wvrInputIdType; + if (SymbolRequirement.s_foundTypes.TryGetValue("wvr.WVR_InputId", out wvrInputIdType) && wvrInputIdType.IsEnum) + { + if (Enum.IsDefined(wvrInputIdType, "WVR_InputId_Alias1_Digital_Trigger")) + { + return true; + } + } + return false; + }, + reqFileNames = new string[] { "wvr.cs" }, + }); + } + } +} \ No newline at end of file diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/WaveVRModuleEditor.cs.meta b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/WaveVRModuleEditor.cs.meta new file mode 100644 index 00000000..fdeaf8d9 --- /dev/null +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/Editor/WaveVRModuleEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fc02ecd46efaec0469f5c9a170948d4f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/GoogleVRModule.cs b/Assets/HTC.UnityPlugin/VRModule/Modules/GoogleVRModule.cs index dd9157ec..38a93c01 100644 --- a/Assets/HTC.UnityPlugin/VRModule/Modules/GoogleVRModule.cs +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/GoogleVRModule.cs @@ -1,9 +1,8 @@ //========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== +using HTC.UnityPlugin.Utility; #if VIU_GOOGLEVR && UNITY_5_6_OR_NEWER - using UnityEngine; -using HTC.UnityPlugin.Utility; using HTC.UnityPlugin.Vive; #if UNITY_2017_2_OR_NEWER @@ -19,8 +18,20 @@ namespace HTC.UnityPlugin.VRModuleManagement { + public partial class VRModule : SingletonBehaviour + { + public static readonly bool isGoogleVRPluginDetected = +#if VIU_GOOGLEVR + true; +#else + false; +#endif + } + public sealed class GoogleVRModule : VRModule.ModuleBase { + public override int moduleIndex { get { return (int)VRModuleActiveEnum.DayDream; } } + #if VIU_GOOGLEVR && UNITY_5_6_OR_NEWER private const uint HEAD_INDEX = 0u; diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/OculusVRModule.cs b/Assets/HTC.UnityPlugin/VRModule/Modules/OculusVRModule.cs index 14db4d4f..4ac8d9f1 100644 --- a/Assets/HTC.UnityPlugin/VRModule/Modules/OculusVRModule.cs +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/OculusVRModule.cs @@ -1,5 +1,6 @@ //========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== +using HTC.UnityPlugin.Utility; #if VIU_OCULUSVR using UnityEngine; using HTC.UnityPlugin.Utility; @@ -14,8 +15,20 @@ namespace HTC.UnityPlugin.VRModuleManagement { + public partial class VRModule : SingletonBehaviour + { + public static readonly bool isOculusVRPluginDetected = +#if VIU_OCULUSVR + true; +#else + false; +#endif + } + public sealed class OculusVRModule : VRModule.ModuleBase { + public override int moduleIndex { get { return (int)VRModuleActiveEnum.OculusVR; } } + #if VIU_OCULUSVR public const int VALID_NODE_COUNT = 7; private static readonly OVRPlugin.Node[] s_index2node; diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/SimulatorModule.cs b/Assets/HTC.UnityPlugin/VRModule/Modules/SimulatorModule.cs index aceb4425..0ddf3227 100644 --- a/Assets/HTC.UnityPlugin/VRModule/Modules/SimulatorModule.cs +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/SimulatorModule.cs @@ -43,6 +43,8 @@ public sealed class SimulatorVRModule : VRModule.ModuleBase, ISimulatorVRModule public event Action onDeactivated; public event UpdateDeviceStateHandler onUpdateDeviceState; + public override int moduleIndex { get { return (int)VRModuleActiveEnum.Simulator; } } + public uint selectedDeviceIndex { get; private set; } public bool hasControlFocus { get; private set; } diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/SteamVRModule.cs b/Assets/HTC.UnityPlugin/VRModule/Modules/SteamVRModule.cs index a522dd5b..cae50e76 100644 --- a/Assets/HTC.UnityPlugin/VRModule/Modules/SteamVRModule.cs +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/SteamVRModule.cs @@ -1,8 +1,9 @@ //========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== -#if VIU_STEAMVR using HTC.UnityPlugin.Utility; +#if VIU_STEAMVR using HTC.UnityPlugin.Vive; +using HTC.UnityPlugin.Vive.SteamVRExtension; using System.Text; using UnityEngine; using Valve.VR; @@ -15,8 +16,83 @@ namespace HTC.UnityPlugin.VRModuleManagement { + public partial class VRModule : SingletonBehaviour + { + public static readonly bool isSteamVRPluginDetected = +#if VIU_STEAMVR + true; +#else + false; +#endif + } + public sealed partial class SteamVRModule : VRModule.ModuleBase { + public override int moduleIndex { get { return (int)VRModuleActiveEnum.SteamVR; } } + +#if VIU_STEAMVR + private class CameraCreator : VRCameraHook.CameraCreator + { + public override bool shouldActive { get { return s_moduleInstance == null ? false : s_moduleInstance.isActivated; } } + + public override void CreateCamera(VRCameraHook hook) + { + if (hook.GetComponent() == null) + { + hook.gameObject.AddComponent(); + } + } + } + + private class RenderModelCreator : RenderModelHook.RenderModelCreator + { + private uint m_index = INVALID_DEVICE_INDEX; + private VIUSteamVRRenderModel m_model; + + public override bool shouldActive { get { return s_moduleInstance == null ? false : s_moduleInstance.isActivated; } } + + public override void UpdateRenderModel() + { + if (!ChangeProp.Set(ref m_index, hook.GetModelDeviceIndex())) { return; } + + if (VRModule.IsValidDeviceIndex(m_index)) + { + // create object for render model + if (m_model == null) + { + var go = new GameObject("Model"); + go.transform.SetParent(hook.transform, false); + m_model = go.AddComponent(); + } + + // set render model index + m_model.gameObject.SetActive(true); + m_model.shaderOverride = hook.overrideShader; + m_model.SetDeviceIndex(m_index); + } + else + { + // deacitvate object for render model + if (m_model != null) + { + m_model.gameObject.SetActive(false); + } + } + } + + public override void CleanUpRenderModel() + { + if (m_model != null) + { + Object.Destroy(m_model.gameObject); + m_model = null; + } + } + } + + private static SteamVRModule s_moduleInstance; +#endif + #if VIU_STEAMVR && !VIU_STEAMVR_2_0_0_OR_NEWER private static readonly uint s_sizeOfControllerStats = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VRControllerState_t)); @@ -58,6 +134,7 @@ public override void OnActivated() SteamVR_Utils.Event.Listen("input_focus", OnInputFocusArgs); SteamVR_Utils.Event.Listen("TrackedDeviceRoleChanged", OnTrackedDeviceRoleChangedArgs); #endif + s_moduleInstance = this; } public override void OnDeactivated() @@ -77,6 +154,7 @@ public override void OnDeactivated() SteamVR_Utils.Event.Remove("input_focus", OnInputFocusArgs); SteamVR_Utils.Event.Remove("TrackedDeviceRoleChanged", OnTrackedDeviceRoleChangedArgs); #endif + s_moduleInstance = null; } public override void Update() diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/SteamVRv2Module.cs b/Assets/HTC.UnityPlugin/VRModule/Modules/SteamVRv2Module.cs index e08f69c4..691da686 100644 --- a/Assets/HTC.UnityPlugin/VRModule/Modules/SteamVRv2Module.cs +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/SteamVRv2Module.cs @@ -160,8 +160,6 @@ public enum HapticStruct { Haptic } public const string ACTION_SET_NAME = "/actions/htc_viu"; - private static SteamVRModule s_moduleInstance; - private static bool s_pathInitialized; private static bool s_actionInitialized; @@ -285,7 +283,9 @@ public static void InitializeHandles() InitializePaths(); SteamVR.Initialize(); -#if VIU_STEAMVR_2_1_0_OR_NEWER +#if VIU_STEAMVR_2_2_0_OR_NEWER + SteamVR_ActionSet_Manager.UpdateActionStates(); +#elif VIU_STEAMVR_2_1_0_OR_NEWER SteamVR_ActionSet_Manager.UpdateActionSetsState(); #else SteamVR_ActionSet.UpdateActionSetsState(); @@ -378,8 +378,13 @@ public override void OnActivated() m_activeActionSets = new VRActiveActionSet_t[1] { new VRActiveActionSet_t() { ulActionSet = s_actionSetHandle, } }; +#if VIU_STEAMVR_2_2_0_OR_NEWER + SteamVR_Input.onNonVisualActionsUpdated += UpdateDeviceInput; + SteamVR_Input.onPosesUpdated += UpdateDevicePose; +#else SteamVR_Input.OnNonVisualActionsUpdated += UpdateDeviceInput; SteamVR_Input.OnPosesUpdated += UpdateDevicePose; +#endif s_devicePathHandles = new ulong[OpenVR.k_unMaxTrackedDeviceCount]; EnsureDeviceStateLength(OpenVR.k_unMaxTrackedDeviceCount); @@ -400,8 +405,13 @@ public override void OnDeactivated() SteamVR_Events.InputFocus.RemoveListener(OnInputFocus); SteamVR_Events.System(EVREventType.VREvent_TrackedDeviceRoleChanged).RemoveListener(OnTrackedDeviceRoleChanged); +#if VIU_STEAMVR_2_2_0_OR_NEWER + SteamVR_Input.onNonVisualActionsUpdated -= UpdateDeviceInput; + SteamVR_Input.onPosesUpdated -= UpdateDevicePose; +#else SteamVR_Input.OnNonVisualActionsUpdated -= UpdateDeviceInput; SteamVR_Input.OnPosesUpdated -= UpdateDevicePose; +#endif trackingSpace = m_prevTrackingSpace; diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/UnityEngineVRModule.cs b/Assets/HTC.UnityPlugin/VRModule/Modules/UnityEngineVRModule.cs index 66adc045..7d44faf0 100644 --- a/Assets/HTC.UnityPlugin/VRModule/Modules/UnityEngineVRModule.cs +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/UnityEngineVRModule.cs @@ -85,6 +85,9 @@ public static float GetUnityAxis(int id) public static int GetUnityAxisIdByIndex(int index) { return index + 1; } #endif + + public override int moduleIndex { get { return (int)VRModuleActiveEnum.UnityNativeVR; } } + public override bool ShouldActiveModule() { return VIUSettings.activateUnityNativeVRModule && XRSettings.enabled; } public override void Update() diff --git a/Assets/HTC.UnityPlugin/VRModule/Modules/WaveVRModule.cs b/Assets/HTC.UnityPlugin/VRModule/Modules/WaveVRModule.cs index 246bf410..06ba83ef 100644 --- a/Assets/HTC.UnityPlugin/VRModule/Modules/WaveVRModule.cs +++ b/Assets/HTC.UnityPlugin/VRModule/Modules/WaveVRModule.cs @@ -1,16 +1,184 @@ -using HTC.UnityPlugin.Utility; +//========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== + +using HTC.UnityPlugin.Utility; using HTC.UnityPlugin.Vive; using System; +using System.Collections.Generic; using UnityEngine; #if VIU_WAVEVR && UNITY_ANDROID using wvr; +using Object = UnityEngine.Object; #endif namespace HTC.UnityPlugin.VRModuleManagement { + public partial class VRModule : SingletonBehaviour + { + public static readonly bool isWaveVRPluginDetected = +#if VIU_WAVEVR + true; +#else + false; +#endif + } + public sealed class WaveVRModule : VRModule.ModuleBase { + public override int moduleIndex { get { return (int)VRModuleActiveEnum.WaveVR; } } + #if VIU_WAVEVR && UNITY_ANDROID + private class CameraCreator : VRCameraHook.CameraCreator + { + public override bool shouldActive { get { return s_moduleInstance == null ? false : s_moduleInstance.isActivated; } } + + public override void CreateCamera(VRCameraHook hook) + { + if (hook.GetComponent() == null) + { + hook.gameObject.AddComponent(); + } + if (hook.GetComponent() == null) + { + hook.gameObject.AddComponent().viveRole.SetEx(DeviceRole.Hmd); + } + if (hook.GetComponent() != null) + { + Object.Destroy(hook.GetComponent()); + } + } + } + + private class RenderModelCreator : RenderModelHook.RenderModelCreator + { + private uint m_index = INVALID_DEVICE_INDEX; + private GameObject m_model; + private WVR_DeviceType m_loadedHandType; + + public override bool shouldActive { get { return s_moduleInstance == null ? false : s_moduleInstance.isActivated; } } + + public override void UpdateRenderModel() + { + if (!ChangeProp.Set(ref m_index, hook.GetModelDeviceIndex())) { return; } + + var hasValidModel = false; + var handType = default(WVR_DeviceType); + if (VRModule.IsValidDeviceIndex(m_index)) + { + if (m_index == VRModule.GetRightControllerDeviceIndex()) + { + hasValidModel = true; + handType = WVR_DeviceType.WVR_DeviceType_Controller_Right; + } + else if (m_index == VRModule.GetLeftControllerDeviceIndex()) + { + hasValidModel = true; + handType = WVR_DeviceType.WVR_DeviceType_Controller_Left; + } + } + + // NOTE: load renderModel only if it hasn't been loaded or user changes handType + if (hasValidModel) + { + if (m_model != null && m_loadedHandType != handType) + { + CleanUpRenderModel(); + } + + if (m_model == null) + { + // Create WaveVR_ControllerLoader silently (to avoid Start and OnEnable) + var loaderGO = new GameObject("Loader"); + loaderGO.transform.SetParent(hook.transform, false); + loaderGO.SetActive(false); + var loader = loaderGO.AddComponent(); + loader.enabled = false; + loader.TrackPosition = false; + loader.TrackRotation = false; + loader.showIndicator = false; + loaderGO.SetActive(true); + // Call onLoadController to create model (chould be Finch/Link/Pico/QIYIVR) + switch (handType) + { + case WVR_DeviceType.WVR_DeviceType_Controller_Right: + loader.WhichHand = WaveVR_ControllerLoader.ControllerHand.Controller_Right; + loaderGO.SendMessage("onLoadController", WVR_DeviceType.WVR_DeviceType_Controller_Right); + break; + case WVR_DeviceType.WVR_DeviceType_Controller_Left: + loader.WhichHand = WaveVR_ControllerLoader.ControllerHand.Controller_Left; + loaderGO.SendMessage("onLoadController", WVR_DeviceType.WVR_DeviceType_Controller_Left); + break; + } + + // Find transform that only contains controller model (include animator, exclude PoseTracker/Beam/UIPointer) + // and remove other unnecessary objects + var ctrllerActions = FindWaveVRControllerActionsObjInChildren(); + if (ctrllerActions != null) + { + ctrllerActions.transform.SetParent(hook.transform, false); + ctrllerActions.transform.SetAsFirstSibling(); + for (int i = hook.transform.childCount - 1; i >= 1; --i) + { + Object.Destroy(hook.transform.GetChild(i).gameObject); + } + ctrllerActions.gameObject.SetActive(true); + m_model = ctrllerActions.gameObject; + } + else + { + Debug.LogWarning("FindWaveVRControllerActionsObjInChildren failed"); + for (int i = hook.transform.childCount - 1; i >= 0; --i) + { + Object.Destroy(hook.transform.GetChild(i).gameObject); + } + } + + m_loadedHandType = handType; + } + + m_model.SetActive(true); + } + else + { + if (m_model != null) + { + m_model.SetActive(false); + } + } + } + + public override void CleanUpRenderModel() + { + if (m_model != null) + { + Object.Destroy(m_model); + m_model = null; + } + } + + // FIXME: This is for finding Controller model with animator, is reliable? + private Transform FindWaveVRControllerActionsObjInChildren() + { + var nodes = new List(); + nodes.Add(hook.transform); + for (int i = 0; i < nodes.Count; ++i) + { + var parent = nodes[i]; + for (int j = 0, jmax = parent.childCount; j < jmax; ++j) + { + var child = parent.GetChild(j); + nodes.Add(child); + if (child.GetComponent() != null) { continue; } + if (child.GetComponent() != null) { continue; } + if (child.GetComponent() != null) { continue; } + if (child.GetComponent() != null) { continue; } + return child; + } + } + + return null; + } + } + private const uint DEVICE_COUNT = 3; public static readonly Vector3 RIGHT_ARM_MULTIPLIER = new Vector3(1f, 1f, 1f); @@ -19,17 +187,14 @@ public sealed class WaveVRModule : VRModule.ModuleBase public const float MIN_EXTENSION_ANGLE = 7.0f; public const float MAX_EXTENSION_ANGLE = 60.0f; public const float EXTENSION_WEIGHT = 0.4f; + private static WaveVRModule s_moduleInstance; private static readonly WVR_DeviceType[] s_index2type; private static readonly uint[] s_type2index; private static readonly VRModuleDeviceClass[] s_type2class; private static readonly VRModuleDeviceModel[] s_type2model; - private bool m_hasInputFocus; - private WVR_PoseOriginModel m_poseOrigin; - private readonly WVR_DevicePosePair_t[] m_poses = new WVR_DevicePosePair_t[DEVICE_COUNT]; // HMD, R, L controllers. + //private bool m_hasInputFocus; private readonly bool[] m_index2deviceTouched = new bool[DEVICE_COUNT]; - private WVR_AnalogState_t[] m_analogStates = new WVR_AnalogState_t[2]; - private Vector3 m_handedMultiplier; private IVRModuleDeviceStateRW m_headState; private IVRModuleDeviceStateRW m_rightState; private IVRModuleDeviceStateRW m_leftState; @@ -77,12 +242,16 @@ static WaveVRModule() public override bool ShouldActiveModule() { - return !Application.isEditor && VIUSettings.activateWaveVRModule; +#if UNITY_EDITOR && !VIU_WAVEVR_2_1_0_OR_NEWER + return false; +#else + return VIUSettings.activateWaveVRModule; +#endif } public override void OnActivated() { - if (UnityEngine.Object.FindObjectOfType() == null) + if (Object.FindObjectOfType() == null) { VRModule.Instance.gameObject.AddComponent(); } @@ -90,23 +259,55 @@ public override void OnActivated() EnsureDeviceStateLength(DEVICE_COUNT); UpdateTrackingSpaceType(); + + s_moduleInstance = this; + + WaveVR_Utils.Event.Listen(WaveVR_Utils.Event.NEW_POSES, OnNewPoses); + } + + public override void OnDeactivated() + { + WaveVR_Utils.Event.Remove(WaveVR_Utils.Event.NEW_POSES, OnNewPoses); + + m_headState = null; + m_rightState = null; + m_leftState = null; + ResetTouchState(); + + s_moduleInstance = null; } public override void UpdateTrackingSpaceType() { - switch (VRModule.trackingSpaceType) + if (WaveVR_Render.Instance != null) { - case VRModuleTrackingSpaceType.RoomScale: - m_poseOrigin = WVR_PoseOriginModel.WVR_PoseOriginModel_OriginOnGround; - break; - case VRModuleTrackingSpaceType.Stationary: - m_poseOrigin = WVR_PoseOriginModel.WVR_PoseOriginModel_OriginOnHead; - break; + // Only effected when origin is OnHead or OnGround + // This way you can manually set WaveVR_Render origin to other value lik OnTrackingObserver or OnHead_3DoF + if (VRModule.trackingSpaceType == VRModuleTrackingSpaceType.RoomScale) + { + if (WaveVR_Render.Instance.origin == WVR_PoseOriginModel.WVR_PoseOriginModel_OriginOnHead) + { + WaveVR_Render.Instance.origin = WVR_PoseOriginModel.WVR_PoseOriginModel_OriginOnGround; + } + } + else if (VRModule.trackingSpaceType == VRModuleTrackingSpaceType.Stationary) + { + if (WaveVR_Render.Instance.origin == WVR_PoseOriginModel.WVR_PoseOriginModel_OriginOnGround) + { + WaveVR_Render.Instance.origin = WVR_PoseOriginModel.WVR_PoseOriginModel_OriginOnHead; + } + } } } public override void Update() { +#if VIU_WAVEVR_2_1_0_OR_NEWER + const WVR_InputId digitalTrggerBumpID = WVR_InputId.WVR_InputId_Alias1_Digital_Trigger; +#else + const WVR_InputId digitalTrggerBumpID = WVR_InputId.WVR_InputId_Alias1_Bumper; +#endif + for (uint deviceIndex = 0u; deviceIndex < DEVICE_COUNT; ++deviceIndex) { IVRModuleDeviceState prevState; @@ -114,78 +315,54 @@ public override void Update() if (!TryGetValidDeviceState(deviceIndex, out prevState, out currState) || !currState.isConnected) { continue; } var deviceType = s_index2type[deviceIndex]; - // update input - var buttons = 0u; - var touches = 0u; - // FIXME: What does WVR_GetInputTypeCount means? - var analogCount = Interop.WVR_GetInputTypeCount(deviceType, WVR_InputType.WVR_InputType_Analog); - if (m_analogStates == null || m_analogStates.Length < analogCount) { m_analogStates = new WVR_AnalogState_t[analogCount]; } - const uint inputType = (uint)(WVR_InputType.WVR_InputType_Button | WVR_InputType.WVR_InputType_Touch | WVR_InputType.WVR_InputType_Analog); -#if VIU_WAVEVR_2_0_32_OR_NEWER - if (Interop.WVR_GetInputDeviceState(deviceType, inputType, ref buttons, ref touches, m_analogStates, (uint)analogCount)) -#else - if (Interop.WVR_GetInputDeviceState(deviceType, inputType, ref buttons, ref touches, m_analogStates, analogCount)) -#endif + var deviceInput = WaveVR_Controller.Input(deviceType); + if (deviceInput != null) { - const uint dpadMask = - (1 << (int)(WVR_InputId.WVR_InputId_Alias1_Touchpad)) | - (1 << (int)(WVR_InputId.WVR_InputId_Alias1_DPad_Left)) | - (1 << (int)(WVR_InputId.WVR_InputId_Alias1_DPad_Up)) | - (1 << (int)(WVR_InputId.WVR_InputId_Alias1_DPad_Right)) | - (1 << (int)(WVR_InputId.WVR_InputId_Alias1_DPad_Down)); - - const uint triggerBumperMask = - (1 << (int)(WVR_InputId.WVR_InputId_Alias1_Trigger)) | -#if VIU_WAVEVR_2_1_0_OR_NEWER - (1 << (int)(WVR_InputId.WVR_InputId_Alias1_Digital_Trigger)); -#else - (1 << (int)(WVR_InputId.WVR_InputId_Alias1_Bumper)); -#endif - - currState.SetButtonPress(VRModuleRawButton.System, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_System)) != 0u); - currState.SetButtonPress(VRModuleRawButton.ApplicationMenu, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_Menu)) != 0u); - currState.SetButtonPress(VRModuleRawButton.Touchpad, (buttons & dpadMask) != 0u); - currState.SetButtonPress(VRModuleRawButton.Trigger, (buttons & triggerBumperMask) != 0u); - currState.SetButtonPress(VRModuleRawButton.Grip, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_Grip)) != 0u); - currState.SetButtonPress(VRModuleRawButton.DPadLeft, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Left)) != 0u); - currState.SetButtonPress(VRModuleRawButton.DPadUp, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Up)) != 0u); - currState.SetButtonPress(VRModuleRawButton.DPadRight, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Right)) != 0u); - currState.SetButtonPress(VRModuleRawButton.DPadDown, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Down)) != 0u); - - currState.SetButtonTouch(VRModuleRawButton.System, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_System)) != 0u); - currState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_Menu)) != 0u); - currState.SetButtonTouch(VRModuleRawButton.Touchpad, (touches & dpadMask) != 0u); - currState.SetButtonTouch(VRModuleRawButton.Trigger, (touches & triggerBumperMask) != 0u); - currState.SetButtonTouch(VRModuleRawButton.Grip, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_Grip)) != 0u); - currState.SetButtonTouch(VRModuleRawButton.DPadLeft, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Left)) != 0u); - currState.SetButtonTouch(VRModuleRawButton.DPadUp, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Up)) != 0u); - currState.SetButtonTouch(VRModuleRawButton.DPadRight, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Right)) != 0u); - currState.SetButtonTouch(VRModuleRawButton.DPadDown, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Down)) != 0u); - - for (int j = 0, jmax = m_analogStates.Length; j < jmax; ++j) - { - switch (m_analogStates[j].id) - { - case WVR_InputId.WVR_InputId_Alias1_Trigger: - if (m_analogStates[j].type == WVR_AnalogType.WVR_AnalogType_Trigger) - { - currState.SetAxisValue(VRModuleRawAxis.Trigger, m_analogStates[j].axis.x); - } - break; - case WVR_InputId.WVR_InputId_Alias1_Touchpad: - if (m_analogStates[j].type == WVR_AnalogType.WVR_AnalogType_TouchPad && currState.GetButtonTouch(VRModuleRawButton.Touchpad)) - { - currState.SetAxisValue(VRModuleRawAxis.TouchpadX, m_analogStates[j].axis.x); - currState.SetAxisValue(VRModuleRawAxis.TouchpadY, m_analogStates[j].axis.y); - } - else - { - currState.SetAxisValue(VRModuleRawAxis.TouchpadX, 0f); - currState.SetAxisValue(VRModuleRawAxis.TouchpadY, 0f); - } - break; - } - } + var systemPressed = deviceInput.GetPress(WVR_InputId.WVR_InputId_Alias1_System); + var menuPressed = deviceInput.GetPress(WVR_InputId.WVR_InputId_Alias1_Menu); + var triggerPressed = deviceInput.GetPress(WVR_InputId.WVR_InputId_Alias1_Trigger); + var digitalTriggerPressed = deviceInput.GetPress(digitalTrggerBumpID); + var gripPressed = deviceInput.GetPress(WVR_InputId.WVR_InputId_Alias1_Grip); + var touchpadPressed = deviceInput.GetPress(WVR_InputId.WVR_InputId_Alias1_Touchpad); + var dpadLeftPressed = deviceInput.GetPress(WVR_InputId.WVR_InputId_Alias1_DPad_Left); + var dpadUpPressed = deviceInput.GetPress(WVR_InputId.WVR_InputId_Alias1_DPad_Up); + var dpadRightPressed = deviceInput.GetPress(WVR_InputId.WVR_InputId_Alias1_DPad_Right); + var dpadDownPressed = deviceInput.GetPress(WVR_InputId.WVR_InputId_Alias1_DPad_Down); + currState.SetButtonPress(VRModuleRawButton.System, systemPressed); + currState.SetButtonPress(VRModuleRawButton.ApplicationMenu, menuPressed); + currState.SetButtonPress(VRModuleRawButton.Touchpad, touchpadPressed || dpadLeftPressed || dpadUpPressed || dpadRightPressed || dpadDownPressed); + currState.SetButtonPress(VRModuleRawButton.Trigger, triggerPressed || digitalTriggerPressed); + currState.SetButtonPress(VRModuleRawButton.Grip, gripPressed); + currState.SetButtonPress(VRModuleRawButton.DPadLeft, dpadLeftPressed); + currState.SetButtonPress(VRModuleRawButton.DPadUp, dpadUpPressed); + currState.SetButtonPress(VRModuleRawButton.DPadRight, dpadRightPressed); + currState.SetButtonPress(VRModuleRawButton.DPadDown, dpadDownPressed); + + var systemTouched = deviceInput.GetTouch(WVR_InputId.WVR_InputId_Alias1_System); + var menuTouched = deviceInput.GetTouch(WVR_InputId.WVR_InputId_Alias1_Menu); + var triggerTouched = deviceInput.GetTouch(WVR_InputId.WVR_InputId_Alias1_Trigger); + var digitalTriggerTouched = deviceInput.GetTouch(digitalTrggerBumpID); + var gripTouched = deviceInput.GetTouch(WVR_InputId.WVR_InputId_Alias1_Grip); + var touchpadTouched = deviceInput.GetTouch(WVR_InputId.WVR_InputId_Alias1_Touchpad); + var dpadLeftTouched = deviceInput.GetTouch(WVR_InputId.WVR_InputId_Alias1_DPad_Left); + var dpadUpTouched = deviceInput.GetTouch(WVR_InputId.WVR_InputId_Alias1_DPad_Up); + var dpadRightTouched = deviceInput.GetTouch(WVR_InputId.WVR_InputId_Alias1_DPad_Right); + var dpadDownTouched = deviceInput.GetTouch(WVR_InputId.WVR_InputId_Alias1_DPad_Down); + currState.SetButtonTouch(VRModuleRawButton.System, systemTouched); + currState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, menuTouched); + currState.SetButtonTouch(VRModuleRawButton.Touchpad, touchpadTouched || dpadLeftTouched || dpadUpTouched || dpadRightTouched || dpadDownTouched); + currState.SetButtonTouch(VRModuleRawButton.Trigger, triggerTouched || digitalTriggerTouched); + currState.SetButtonTouch(VRModuleRawButton.Grip, gripTouched); + currState.SetButtonTouch(VRModuleRawButton.DPadLeft, dpadLeftTouched); + currState.SetButtonTouch(VRModuleRawButton.DPadUp, dpadUpTouched); + currState.SetButtonTouch(VRModuleRawButton.DPadRight, dpadRightTouched); + currState.SetButtonTouch(VRModuleRawButton.DPadDown, dpadDownTouched); + + var triggerAxis = deviceInput.GetAxis(WVR_InputId.WVR_InputId_Alias1_Trigger); + var touchAxis = deviceInput.GetAxis(WVR_InputId.WVR_InputId_Alias1_Touchpad); + currState.SetAxisValue(VRModuleRawAxis.Trigger, triggerAxis.x); + currState.SetAxisValue(VRModuleRawAxis.TouchpadX, touchAxis.x); + currState.SetAxisValue(VRModuleRawAxis.TouchpadY, touchAxis.y); } else { @@ -198,25 +375,32 @@ public override void Update() ProcessDeviceInputChanged(); } - public override void BeforeRenderUpdate() + public void OnNewPoses(params object[] args) { if (WaveVR.Instance == null) { return; } - Interop.WVR_GetSyncPose(m_poseOrigin, m_poses, DEVICE_COUNT); + var poses = (WVR_DevicePosePair_t[])args[0]; + var posesRT = (WaveVR_Utils.RigidTransform[])args[1]; FlushDeviceState(); - for (int i = 0, imax = m_poses.Length; i < imax; ++i) + for (int i = 0, imax = poses.Length; i < imax; ++i) { uint deviceIndex; - var deviceType = m_poses[i].type; + var deviceType = poses[i].type; if (!TryGetAndTouchDeviceIndexByType(deviceType, out deviceIndex)) { continue; } IVRModuleDeviceState prevState; IVRModuleDeviceStateRW currState; EnsureValidDeviceState(deviceIndex, out prevState, out currState); - if (!Interop.WVR_IsDeviceConnected(deviceType)) +#if VIU_WAVEVR_2_1_0_OR_NEWER && UNITY_EDITOR + var deviceConnected = WaveVR.Instance.isSimulatorOn && WaveVR_Utils.WVR_IsDeviceConnected_S((int)deviceType); +#else + var deviceConnected = Interop.WVR_IsDeviceConnected(deviceType); +#endif + + if (!deviceConnected) { if (prevState.isConnected) { @@ -250,15 +434,15 @@ public override void BeforeRenderUpdate() } // update pose - var devicePose = m_poses[i].pose; + var devicePose = poses[i].pose; currState.velocity = new Vector3(devicePose.Velocity.v0, devicePose.Velocity.v1, -devicePose.Velocity.v2); currState.angularVelocity = new Vector3(-devicePose.AngularVelocity.v0, -devicePose.AngularVelocity.v1, devicePose.AngularVelocity.v2); - var rigidTransform = new WaveVR_Utils.RigidTransform(devicePose.PoseMatrix); + var rigidTransform = posesRT[i]; currState.position = rigidTransform.pos; currState.rotation = rigidTransform.rot; - currState.isPoseValid = currState.pose != RigidPose.identity; + currState.isPoseValid = devicePose.IsValidPose; } } @@ -266,7 +450,7 @@ public override void BeforeRenderUpdate() { ApplyVirtualArmAndSimulateInput(m_rightState, m_headState, RIGHT_ARM_MULTIPLIER); } - + if (m_leftState != null) { ApplyVirtualArmAndSimulateInput(m_leftState, m_headState, LEFT_ARM_MULTIPLIER); @@ -278,14 +462,6 @@ public override void BeforeRenderUpdate() ProcessDevicePoseChanged(); } - public override void OnDeactivated() - { - m_headState = null; - m_rightState = null; - m_leftState = null; - ResetTouchState(); - } - // FIXME: WVR_IsInputFocusCapturedBySystem currently not implemented yet //public override bool HasInputFocus() //{ @@ -357,8 +533,11 @@ private void ApplyVirtualArmAndSimulateInput(IVRModuleDeviceStateRW ctrlState, I if (!VIUSettings.waveVRAddVirtualArmTo3DoFController && !VIUSettings.simulateWaveVR6DofController) { return; } var deviceType = (int)s_index2type[ctrlState.deviceIndex]; - if (Interop.WVR_GetDegreeOfFreedom((WVR_DeviceType)deviceType) != WVR_NumDoF.WVR_NumDoF_3DoF) { return; } - +#if VIU_WAVEVR_2_1_0_OR_NEWER && UNITY_EDITOR + if (!WaveVR.Instance.isSimulatorOn || WaveVR_Utils.WVR_GetDegreeOfFreedom_S() == (int)WVR_NumDoF.WVR_NumDoF_6DoF) { return; } +#else + if (Interop.WVR_GetDegreeOfFreedom((WVR_DeviceType)deviceType) == WVR_NumDoF.WVR_NumDoF_6DoF) { return; } +#endif if (VIUSettings.simulateWaveVR6DofController) { @@ -464,7 +643,11 @@ private static Vector3 GetControllerPositionWithVirtualArm(RigidPose neckPose, Q public override void TriggerViveControllerHaptic(uint deviceIndex, ushort durationMicroSec = 500) { - Interop.WVR_TriggerVibrator(s_index2type[deviceIndex], WVR_InputId.WVR_InputId_Alias1_Touchpad, durationMicroSec); + var deviceInput = WaveVR_Controller.Input(s_index2type[deviceIndex]); + if (deviceInput != null) + { + deviceInput.TriggerHapticPulse(durationMicroSec); + } } #endif } diff --git a/Assets/HTC.UnityPlugin/VRModule/VRModule.cs b/Assets/HTC.UnityPlugin/VRModule/VRModule.cs index 5b59b999..92d9ef4c 100644 --- a/Assets/HTC.UnityPlugin/VRModule/VRModule.cs +++ b/Assets/HTC.UnityPlugin/VRModule/VRModule.cs @@ -194,33 +194,5 @@ public static void TriggerHapticVibration(uint deviceIndex, float durationSecond Instance.m_activatedModuleBase.TriggerHapticVibration(deviceIndex, durationSeconds, frequency, amplitude, startSecondsFromNow); } } - - public static readonly bool isSteamVRPluginDetected = -#if VIU_STEAMVR - true; -#else - false; -#endif - - public static readonly bool isOculusVRPluginDetected = -#if VIU_OCULUSVR - true; -#else - false; -#endif - - public static readonly bool isGoogleVRPluginDetected = -#if VIU_GOOGLEVR - true; -#else - false; -#endif - - public static readonly bool isWaveVRPluginDetected = -#if VIU_WAVEVR - true; -#else - false; -#endif } } \ No newline at end of file diff --git a/Assets/HTC.UnityPlugin/VRModule/VRModuleBase.cs b/Assets/HTC.UnityPlugin/VRModule/VRModuleBase.cs index f6238a29..844caff7 100644 --- a/Assets/HTC.UnityPlugin/VRModule/VRModuleBase.cs +++ b/Assets/HTC.UnityPlugin/VRModule/VRModuleBase.cs @@ -23,8 +23,24 @@ public abstract class ModuleBase private static readonly Regex s_leftRgx = new Regex("^.*(left|(mr|windowsmr)).*$", RegexOptions.IgnoreCase); private static readonly Regex s_rightRgx = new Regex("^.*(right|(mr|windowsmr)).*$", RegexOptions.IgnoreCase); + public bool isActivated { get; private set; } + + public abstract int moduleIndex { get; } + public virtual bool ShouldActiveModule() { return false; } + public void Activated() + { + isActivated = true; + OnActivated(); + } + + public void Deactivated() + { + isActivated = false; + OnDeactivated(); + } + public virtual void OnActivated() { } public virtual void OnDeactivated() { } @@ -196,6 +212,9 @@ public static bool AxisToPress(bool previousPressedState, float currentAxisValue } } - private sealed class DefaultModule : ModuleBase { } + private sealed class DefaultModule : ModuleBase + { + public override int moduleIndex { get { return (int)VRModuleActiveEnum.None; } } + } } } \ No newline at end of file diff --git a/Assets/HTC.UnityPlugin/VRModule/VRModuleManager.cs b/Assets/HTC.UnityPlugin/VRModule/VRModuleManager.cs index 687e74d4..16303d08 100644 --- a/Assets/HTC.UnityPlugin/VRModule/VRModuleManager.cs +++ b/Assets/HTC.UnityPlugin/VRModule/VRModuleManager.cs @@ -1,7 +1,10 @@ //========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== using HTC.UnityPlugin.Utility; +using System; using System.Collections.Generic; +using System.Linq; +using System.Reflection; using UnityEngine; #if VIU_STEAMVR_2_0_0_OR_NEWER using Valve.VR; @@ -75,14 +78,35 @@ protected override void OnSingletonBehaviourInitialized() m_activatedModule = VRModuleActiveEnum.Uninitialized; m_activatedModuleBase = null; - m_modules = new ModuleBase[EnumUtils.GetMaxValue(typeof(VRModuleActiveEnum)) + 1]; - m_modules[(int)VRModuleActiveEnum.None] = new DefaultModule(); - m_modules[(int)VRModuleActiveEnum.Simulator] = s_simulator; - m_modules[(int)VRModuleActiveEnum.UnityNativeVR] = new UnityEngineVRModule(); - m_modules[(int)VRModuleActiveEnum.SteamVR] = new SteamVRModule(); - m_modules[(int)VRModuleActiveEnum.OculusVR] = new OculusVRModule(); - m_modules[(int)VRModuleActiveEnum.DayDream] = new GoogleVRModule(); - m_modules[(int)VRModuleActiveEnum.WaveVR] = new WaveVRModule(); + try + { + var modules = new List(); + foreach (var type in Assembly.GetAssembly(typeof(ModuleBase)).GetTypes().Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(ModuleBase)))) + { + var inst = type == typeof(SimulatorVRModule) ? s_simulator : (ModuleBase)Activator.CreateInstance(type); + var index = inst.moduleIndex; + + if (index < 0) + { + Debug.LogWarning("Invalid module index, module will not be activated! module name=" + type.Name + " index=" + index); + } + else if (index < modules.Count && modules[index] != null) + { + Debug.LogWarning("Duplicated module index, module will not be activated! module name=" + type.Name + " index=" + index); + } + else + { + while (index >= modules.Count) { modules.Add(null); } + modules[index] = inst; + } + } + m_modules = modules.ToArray(); + } + catch (Exception e) + { + m_modules = new ModuleBase[] { new DefaultModule() }; + Debug.LogError(e); + } } private uint GetDeviceStateLength() { return m_currStates == null ? 0u : (uint)m_currStates.Length; } @@ -247,7 +271,7 @@ private void ActivateModule(VRModuleActiveEnum module) m_activatedModule = module; m_activatedModuleBase = m_modules[(int)module]; - m_activatedModuleBase.OnActivated(); + m_activatedModuleBase.Activated(); #if UNITY_2017_1_OR_NEWER Application.onBeforeRender += BeforeRenderUpdateModule; @@ -324,7 +348,7 @@ private void DeactivateModule() var deactivatedModuleBase = m_activatedModuleBase; m_activatedModule = VRModuleActiveEnum.Uninitialized; m_activatedModuleBase = null; - deactivatedModuleBase.OnDeactivated(); + deactivatedModuleBase.Deactivated(); InvokeActiveModuleChangedEvent(VRModuleActiveEnum.Uninitialized); } diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VIUSettingsEditor.cs b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VIUSettingsEditor.cs index 7b13180e..8437b2ab 100644 --- a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VIUSettingsEditor.cs +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VIUSettingsEditor.cs @@ -2,15 +2,18 @@ using HTC.UnityPlugin.Utility; using HTC.UnityPlugin.VRModuleManagement; +using System; using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Reflection; using UnityEditor; using UnityEngine; using UnityEngine.Rendering; namespace HTC.UnityPlugin.Vive { - public static class VIUSettingsEditor + public static partial class VIUSettingsEditor { public interface ISupportedSDK { @@ -215,42 +218,19 @@ public static void ApplyChanges() } } - private static class Foldouter + public class Foldouter { - public enum Index - { - Simulator, - Vive, - Oculus, - Daydream, - WaveVR, - AutoBinding, - BindingUISwitch, - OculusGo, - } - private static bool s_initialized; - private static uint s_expendedFlags; private static GUIStyle s_styleFoleded; private static GUIStyle s_styleExpended; - private static bool isChanged { get; set; } - - private static uint Flag(Index i) { return 1u << (int)i; } + public bool isExpended { get; private set; } public static void Initialize() { if (s_initialized) { return; } s_initialized = true; - //s_prefKey = "ViveInputUtility.VIUSettingsFolded"; - - //if (EditorPrefs.HasKey(s_prefKey)) - //{ - // s_expendedFlags = (uint)EditorPrefs.GetInt(s_prefKey); - //} - s_expendedFlags = ~0u; - s_styleFoleded = new GUIStyle(EditorStyles.foldout); s_styleExpended = new GUIStyle(EditorStyles.foldout); s_styleExpended.normal = s_styleFoleded.onNormal; @@ -262,23 +242,21 @@ public static void ShowFoldoutBlank() GUILayout.Space(20f); } - public static void ShowFoldoutButton(Index i) + public void ShowFoldoutButton() { - var flag = Flag(i); - var style = IsExpended(flag) ? s_styleExpended : s_styleFoleded; + var style = isExpended ? s_styleExpended : s_styleFoleded; if (GUILayout.Button(string.Empty, style, GUILayout.Width(12f))) { - s_expendedFlags ^= flag; - isChanged = true; + isExpended = !isExpended; } } - public static bool ShowFoldoutButtonOnToggleEnabled(Index i, GUIContent content, bool toggleValue) + public bool ShowFoldoutButtonOnToggleEnabled(GUIContent content, bool toggleValue) { GUILayout.BeginHorizontal(); if (toggleValue) { - ShowFoldoutButton(i); + ShowFoldoutButton(); } else { @@ -290,20 +268,20 @@ public static bool ShowFoldoutButtonOnToggleEnabled(Index i, GUIContent content, return toggleResult; } - public static bool ShowFoldoutButtonWithEnabledToggle(Index i, GUIContent content, bool toggleValue) + public bool ShowFoldoutButtonWithEnabledToggle(GUIContent content, bool toggleValue) { GUILayout.BeginHorizontal(); - ShowFoldoutButton(i); + ShowFoldoutButton(); var toggleResult = EditorGUILayout.ToggleLeft(content, toggleValue, s_labelStyle); if (toggleResult != toggleValue) { s_guiChanged = true; } GUILayout.EndHorizontal(); return toggleResult; } - public static void ShowFoldoutButtonWithDisbledToggle(Index i, GUIContent content) + public void ShowFoldoutButtonWithDisbledToggle(GUIContent content) { GUILayout.BeginHorizontal(); - ShowFoldoutButton(i); + ShowFoldoutButton(); GUI.enabled = false; EditorGUILayout.ToggleLeft(content, false, s_labelStyle); GUI.enabled = true; @@ -329,25 +307,23 @@ public static bool ShowFoldoutBlankWithEnabledToggle(GUIContent content, bool to GUILayout.EndHorizontal(); return toggleResult; } + } - private static bool IsExpended(uint flag) - { - return (s_expendedFlags & flag) > 0; - } - - public static bool IsExpended(Index i) - { - return IsExpended(Flag(i)); - } + private abstract class VRPlatformSetting + { + public bool isStandaloneVR { get { return requirdPlatform == BuildTargetGroup.Standalone; } } + public bool isAndroidVR { get { return requirdPlatform == BuildTargetGroup.Android; } } + public abstract bool canSupport { get; } + public abstract bool support { get; set; } - //public static void ApplyChanges() - //{ - // if (!isChanged) { return; } + public abstract int order { get; } + protected abstract BuildTargetGroup requirdPlatform { get; } - // EditorPrefs.SetInt(s_prefKey, (int)s_expendedFlags); - //} + public abstract void OnPreferenceGUI(); } + private static VRPlatformSetting[] s_platformSettings; + public const string URL_VIU_GITHUB_RELEASE_PAGE = "https://github.com/ViveSoftware/ViveInputUtility-Unity/releases"; public const string URL_STEAM_VR_PLUGIN = "https://www.assetstore.unity3d.com/en/#!/content/32647"; public const string URL_OCULUS_VR_PLUGIN = "https://developer.oculus.com/downloads/package/oculus-utilities-for-unity-5/"; @@ -361,6 +337,19 @@ public static bool IsExpended(Index i) private static bool s_guiChanged; private static string s_defaultAssetPath; + private static Foldouter s_autoBindFoldouter = new Foldouter(); + private static Foldouter s_bindingUIFoldouter = new Foldouter(); + + static VIUSettingsEditor() + { + var platformSettins = new List(); + foreach (var type in Assembly.GetAssembly(typeof(VRPlatformSetting)).GetTypes().Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(VRPlatformSetting)))) + { + platformSettins.Add((VRPlatformSetting)Activator.CreateInstance(type)); + } + s_platformSettings = platformSettins.OrderBy(e => e.order).ToArray(); + } + public static bool virtualRealitySupported { get { return VRSDKSettings.vrEnabled; } set { VRSDKSettings.vrEnabled = value; } } public static ISupportedSDK OpenVRSDK { get { return VRSDKSettings.OpenVR; } } public static ISupportedSDK OculusSDK { get { return VRSDKSettings.Oculus; } } @@ -385,272 +374,50 @@ public static string defaultAssetPath } } - public static bool supportAnyStandaloneVR { get { return supportOpenVR || supportOculus; } } - - public static bool supportAnyAndroidVR { get { return supportDaydream || supportWaveVR || supportOculusGo; } } - - public static bool supportAnyVR { get { return supportAnyStandaloneVR || supportAnyAndroidVR; } } - - public static bool canSupportSimulator - { - get - { - return true; - } - } - - public static bool supportSimulator - { - get - { - return canSupportSimulator && VIUSettings.activateSimulatorModule; - } - private set - { - VIUSettings.activateSimulatorModule = value; - } - } - - public static bool canSupportOpenVR - { - get - { - return - activeBuildTargetGroup == BuildTargetGroup.Standalone -#if !UNITY_5_5_OR_NEWER - && VRModule.isSteamVRPluginDetected -#endif - ; - } - } - - public static bool supportOpenVR + public static bool supportAnyStandaloneVR { get { -#if UNITY_5_5_OR_NEWER - return canSupportOpenVR && (VIUSettings.activateSteamVRModule || VIUSettings.activateUnityNativeVRModule) && OpenVRSDK.enabled; -#elif UNITY_5_4_OR_NEWER - return canSupportOpenVR && VIUSettings.activateSteamVRModule && OpenVRSDK.enabled; -#else - return canSupportOpenVR && VIUSettings.activateSteamVRModule && !virtualRealitySupported; -#endif - } - set - { - if (supportOpenVR == value) { return; } - - VIUSettings.activateSteamVRModule = value; - -#if UNITY_5_5_OR_NEWER - OpenVRSDK.enabled = value; - VIUSettings.activateUnityNativeVRModule = value || supportOculus; -#elif UNITY_5_4_OR_NEWER - OpenVRSDK.enabled = value; -#else - if (value) + foreach (var ps in s_platformSettings) { - virtualRealitySupported = false; - } -#endif - } - } - - public static bool canSupportOculus - { - get - { - return - activeBuildTargetGroup == BuildTargetGroup.Standalone -#if !UNITY_5_5_OR_NEWER || UNITY_5_6_0 || UNITY_5_6_1 || UNITY_5_6_2 - && VRModule.isOculusVRPluginDetected -#endif - ; - } - } - - public static bool supportOculus - { - get - { -#if UNITY_5_5_OR_NEWER - return canSupportOculus && (VIUSettings.activateOculusVRModule || VIUSettings.activateUnityNativeVRModule) && OculusSDK.enabled; -#elif UNITY_5_4_OR_NEWER - return canSupportOculus && VIUSettings.activateOculusVRModule && OculusSDK.enabled; -#else - return canSupportOculus && VIUSettings.activateOculusVRModule && virtualRealitySupported; -#endif - } - set - { - if (supportOculus == value) { return; } - - VIUSettings.activateOculusVRModule = value; - -#if UNITY_5_5_OR_NEWER - OculusSDK.enabled = value; - VIUSettings.activateUnityNativeVRModule = value || supportOpenVR; -#elif UNITY_5_4_OR_NEWER - OculusSDK.enabled = value; -#else - virtualRealitySupported = value; -#endif - } - } - -#if UNITY_5_6_OR_NEWER - public static bool canSupportDaydream - { - get - { - return activeBuildTargetGroup == BuildTargetGroup.Android && VRModule.isGoogleVRPluginDetected; - } - } - - public static bool supportDaydream - { - get - { - if (!canSupportDaydream) { return false; } - if (!VIUSettings.activateGoogleVRModule) { return false; } - if (!DaydreamSDK.enabled) { return false; } - if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel24) { return false; } - if (PlayerSettings.colorSpace == ColorSpace.Linear && !GraphicsAPIContainsOnly(BuildTarget.Android, GraphicsDeviceType.OpenGLES3)) { return false; } - return true; - } - set - { - if (supportDaydream == value) { return; } - - if (value) - { - if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel24) - { - PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel24; - } - - if (PlayerSettings.colorSpace == ColorSpace.Linear) + if (ps.support && ps.isStandaloneVR) { - SetGraphicsAPI(BuildTarget.Android, GraphicsDeviceType.OpenGLES3); + return true; } - - supportWaveVR = false; - supportOculusGo = false; } - - DaydreamSDK.enabled = value; - VIUSettings.activateGoogleVRModule = value; + return false; } } -#else - public static bool canSupportDaydream { get { return false; } } - public static bool supportDaydream { get { return false; } set { } } -#endif - -#if UNITY_5_6_OR_NEWER && !UNITY_5_6_0 && !UNITY_5_6_1 && !UNITY_5_6_2 - public static bool canSupportWaveVR + public static bool supportAnyAndroidVR { get { - return activeBuildTargetGroup == BuildTargetGroup.Android && VRModule.isWaveVRPluginDetected; - } - } - - public static bool supportWaveVR - { - get - { - if (!canSupportWaveVR) { return false; } - if (!VIUSettings.activateWaveVRModule) { return false; } - if (virtualRealitySupported) { return false; } - if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel23) { return false; } - if (PlayerSettings.colorSpace == ColorSpace.Linear && !GraphicsAPIContainsOnly(BuildTarget.Android, GraphicsDeviceType.OpenGLES3)) { return false; } - return true; - } - set - { - if (supportWaveVR == value) { return; } - - if (value) + foreach (var ps in s_platformSettings) { - virtualRealitySupported = false; - - if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel23) + if (ps.support && ps.isAndroidVR) { - PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel23; + return true; } - - if (PlayerSettings.colorSpace == ColorSpace.Linear) - { - SetGraphicsAPI(BuildTarget.Android, GraphicsDeviceType.OpenGLES3); - } - - supportDaydream = false; - supportOculusGo = false; } - - VIUSettings.activateWaveVRModule = value; + return false; } } -#else - public static bool canSupportWaveVR { get { return false; } } - - public static bool supportWaveVR { get { return false; } set { } } -#endif -#if UNITY_5_6_OR_NEWER - public static bool canSupportOculusGo + public static bool supportAnyVR { get { - return activeBuildTargetGroup == BuildTargetGroup.Android && VRModule.isOculusVRPluginDetected; - } - } - - public static bool supportOculusGo - { - get - { - if (!canSupportOculusGo) { return false; } - if (!VIUSettings.activateOculusVRModule) { return false; } - if (!OculusSDK.enabled) { return false; } - if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel21) { return false; } - if (PlayerSettings.graphicsJobs) { return false; } - if ((PlayerSettings.colorSpace == ColorSpace.Linear || PlayerSettings.gpuSkinning) && !GraphicsAPIContainsOnly(BuildTarget.Android, GraphicsDeviceType.OpenGLES3)) { return false; } - return true; - } - set - { - if (supportOculusGo == value) { return; } - - if (value) + foreach (var ps in s_platformSettings) { - supportWaveVR = false; - supportDaydream = false; - - if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel21) - { - PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel21; - } - - PlayerSettings.graphicsJobs = false; - - if (PlayerSettings.colorSpace == ColorSpace.Linear || PlayerSettings.gpuSkinning) + if (ps.support && (ps.isAndroidVR || ps.isAndroidVR)) { - SetGraphicsAPI(BuildTarget.Android, GraphicsDeviceType.OpenGLES3); + return true; } } - - OculusSDK.enabled = value; - VIUSettings.activateOculusVRModule = value; + return false; } } -#else - public static bool canSupportOculusGo { get { return false; } } - - public static bool supportOculusGo { get { return false; } set { } } -#endif public static bool GraphicsAPIContainsOnly(BuildTarget buildTarget, params GraphicsDeviceType[] types) { @@ -691,10 +458,10 @@ private static void OnVIUPreferenceGUI() { s_labelStyle = new GUIStyle(EditorStyles.label); s_labelStyle.richText = true; - - Foldouter.Initialize(); } + Foldouter.Initialize(); + s_guiChanged = false; s_scrollValue = EditorGUILayout.BeginScrollView(s_scrollValue); @@ -712,364 +479,14 @@ private static void OnVIUPreferenceGUI() GUILayout.Space(10); EditorGUILayout.LabelField("Supporting Device", s_labelStyle); - GUILayout.Space(5); - - const string supportSimulatorTitle = "Simulator"; - if (canSupportSimulator) - { - supportSimulator = Foldouter.ShowFoldoutButtonOnToggleEnabled(Foldouter.Index.Simulator, new GUIContent(supportSimulatorTitle, "If checked, the simulator will activated automatically if no other valid VR devices found."), supportSimulator); - } - else - { - Foldouter.ShowFoldoutBlankWithDisbledToggle(new GUIContent(supportSimulatorTitle)); - } - - if (supportSimulator && Foldouter.IsExpended(Foldouter.Index.Simulator)) - { - if (supportSimulator) { EditorGUI.BeginChangeCheck(); } else { GUI.enabled = false; } - { - EditorGUI.indentLevel += 2; - VIUSettings.simulatorAutoTrackMainCamera = EditorGUILayout.ToggleLeft(new GUIContent("Enable Auto Camera Tracking", "Main camera only"), VIUSettings.simulatorAutoTrackMainCamera); - VIUSettings.enableSimulatorKeyboardMouseControl = EditorGUILayout.ToggleLeft(new GUIContent("Enable Keyboard-Mouse Control", "You can also control Simulator devices by handling VRModule.Simulator.onUpdateDeviceState event."), VIUSettings.enableSimulatorKeyboardMouseControl); - - if (!VIUSettings.enableSimulatorKeyboardMouseControl && supportSimulator) { GUI.enabled = false; } - { - EditorGUI.indentLevel++; - VIUSettings.simulateTrackpadTouch = EditorGUILayout.Toggle(new GUIContent("Simulate Trackpad Touch", VIUSettings.SIMULATE_TRACKPAD_TOUCH_TOOLTIP), VIUSettings.simulateTrackpadTouch); - VIUSettings.simulatorKeyMoveSpeed = EditorGUILayout.DelayedFloatField(new GUIContent("Keyboard Move Speed", VIUSettings.SIMULATOR_KEY_MOVE_SPEED_TOOLTIP), VIUSettings.simulatorKeyMoveSpeed); - VIUSettings.simulatorKeyRotateSpeed = EditorGUILayout.DelayedFloatField(new GUIContent("Keyboard Rotate Speed", VIUSettings.SIMULATOR_KEY_ROTATE_SPEED_TOOLTIP), VIUSettings.simulatorKeyRotateSpeed); - VIUSettings.simulatorMouseRotateSpeed = EditorGUILayout.DelayedFloatField(new GUIContent("Mouse Rotate Speed"), VIUSettings.simulatorMouseRotateSpeed); - EditorGUI.indentLevel--; - } - if (!VIUSettings.enableSimulatorKeyboardMouseControl && supportSimulator) { GUI.enabled = true; } - - EditorGUI.indentLevel -= 2; - } - if (supportSimulator) { s_guiChanged |= EditorGUI.EndChangeCheck(); } else { GUI.enabled = true; } - } GUILayout.Space(5); - const string supportOpenVRTitle = "VIVE (OpenVR compatible device)"; - if (canSupportOpenVR) + foreach (var ps in s_platformSettings) { - supportOpenVR = Foldouter.ShowFoldoutButtonOnToggleEnabled(Foldouter.Index.Vive, new GUIContent(supportOpenVRTitle), supportOpenVR); + ps.OnPreferenceGUI(); + GUILayout.Space(5f); } - else - { - GUILayout.BeginHorizontal(); - Foldouter.ShowFoldoutBlank(); - - if (activeBuildTargetGroup != BuildTargetGroup.Standalone) - { - GUI.enabled = false; - ShowToggle(new GUIContent(supportOpenVRTitle, "Standalone platform required."), false, GUILayout.Width(230f)); - GUI.enabled = true; - GUILayout.FlexibleSpace(); - ShowSwitchPlatformButton(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64); - } - else if (!VRModule.isSteamVRPluginDetected) - { - GUI.enabled = false; - ShowToggle(new GUIContent(supportOpenVRTitle, "SteamVR Plugin required."), false, GUILayout.Width(230f)); - GUI.enabled = true; - GUILayout.FlexibleSpace(); - ShowUrlLinkButton(URL_STEAM_VR_PLUGIN); - } - - GUILayout.EndHorizontal(); - } - - if (supportOpenVR && Foldouter.IsExpended(Foldouter.Index.Vive)) - { - if (supportOpenVR && VRModule.isSteamVRPluginDetected) { EditorGUI.BeginChangeCheck(); } else { GUI.enabled = false; } - { - EditorGUI.indentLevel += 2; - - VIUSettings.autoLoadExternalCameraConfigOnStart = EditorGUILayout.ToggleLeft(new GUIContent("Load Config and Enable External Camera on Start", "You can also load config by calling ExternalCameraHook.LoadConfigFromFile(path) in script."), VIUSettings.autoLoadExternalCameraConfigOnStart); - if (!VIUSettings.autoLoadExternalCameraConfigOnStart && supportOpenVR) { GUI.enabled = false; } - { - EditorGUI.indentLevel++; - - EditorGUI.BeginChangeCheck(); - VIUSettings.externalCameraConfigFilePath = EditorGUILayout.DelayedTextField(new GUIContent("Config Path"), VIUSettings.externalCameraConfigFilePath); - if (string.IsNullOrEmpty(VIUSettings.externalCameraConfigFilePath)) - { - VIUSettings.externalCameraConfigFilePath = VIUSettings.EXTERNAL_CAMERA_CONFIG_FILE_PATH_DEFAULT_VALUE; - EditorGUI.EndChangeCheck(); - } - else if (EditorGUI.EndChangeCheck() && VIUSettings.externalCameraConfigFilePath.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) - { - VIUSettings.externalCameraConfigFilePath = VIUSettings.EXTERNAL_CAMERA_CONFIG_FILE_PATH_DEFAULT_VALUE; - } - // Create button that writes default config file - if (VIUSettings.autoLoadExternalCameraConfigOnStart && supportOpenVR && !File.Exists(VIUSettings.externalCameraConfigFilePath)) - { - if (supportOpenVR && VRModule.isSteamVRPluginDetected) { s_guiChanged |= EditorGUI.EndChangeCheck(); } - ShowCreateExCamCfgButton(); - if (supportOpenVR && VRModule.isSteamVRPluginDetected) { EditorGUI.BeginChangeCheck(); } - } - - EditorGUI.indentLevel--; - } - if (!VIUSettings.autoLoadExternalCameraConfigOnStart && supportOpenVR) { GUI.enabled = true; } - - VIUSettings.enableExternalCameraSwitch = EditorGUILayout.ToggleLeft(new GUIContent("Enable External Camera Switch", VIUSettings.EX_CAM_UI_SWITCH_TOOLTIP), VIUSettings.enableExternalCameraSwitch); - if (!VIUSettings.enableExternalCameraSwitch && supportOpenVR) { GUI.enabled = false; } - { - EditorGUI.indentLevel++; - - VIUSettings.externalCameraSwitchKey = (KeyCode)EditorGUILayout.EnumPopup("Switch Key", VIUSettings.externalCameraSwitchKey); - VIUSettings.externalCameraSwitchKeyModifier = (KeyCode)EditorGUILayout.EnumPopup("Switch Key Modifier", VIUSettings.externalCameraSwitchKeyModifier); - - EditorGUI.indentLevel--; - } - if (!VIUSettings.enableExternalCameraSwitch && supportOpenVR) { GUI.enabled = true; } - - EditorGUI.indentLevel -= 2; - } - if (supportOpenVR && VRModule.isSteamVRPluginDetected) { s_guiChanged |= EditorGUI.EndChangeCheck(); } else { GUI.enabled = true; } - } - - if (supportOpenVR && !VRModule.isSteamVRPluginDetected) - { - EditorGUI.indentLevel += 2; - - GUILayout.BeginHorizontal(); - EditorGUILayout.HelpBox("External-Camera(Mix-Reality), animated controller model, VIVE Controller haptics(vibration)" + -#if UNITY_2017_1_OR_NEWER - ", VIVE Tracker USB/Pogo-pin input" + -#else - ", VIVE Tracker device" + -#endif - " NOT supported! Install SteamVR Plugin to get support.", MessageType.Warning); - - s_warningHeight = Mathf.Max(s_warningHeight, GUILayoutUtility.GetLastRect().height); - - if (!VRModule.isSteamVRPluginDetected) - { - GUILayout.BeginVertical(GUILayout.Height(s_warningHeight)); - GUILayout.FlexibleSpace(); - ShowUrlLinkButton(URL_STEAM_VR_PLUGIN); - GUILayout.FlexibleSpace(); - GUILayout.EndVertical(); - } - GUILayout.EndHorizontal(); - - EditorGUI.indentLevel -= 2; - } - - GUILayout.Space(5f); - - const string supportOculusVRTitle = "Oculus Rift & Touch"; - if (canSupportOculus) - { - supportOculus = Foldouter.ShowFoldoutBlankWithEnabledToggle(new GUIContent(supportOculusVRTitle), supportOculus); - } - else - { - GUILayout.BeginHorizontal(); - Foldouter.ShowFoldoutBlank(); - - if (activeBuildTargetGroup != BuildTargetGroup.Standalone) - { - GUI.enabled = false; - ShowToggle(new GUIContent(supportOculusVRTitle, "Standalone platform required."), false, GUILayout.Width(150f)); - GUI.enabled = true; - GUILayout.FlexibleSpace(); - ShowSwitchPlatformButton(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64); - } - else if (!VRModule.isOculusVRPluginDetected) - { - GUI.enabled = false; - ShowToggle(new GUIContent(supportOculusVRTitle, "Oculus VR Plugin required."), false, GUILayout.Width(150f)); - GUI.enabled = true; - GUILayout.FlexibleSpace(); - ShowUrlLinkButton(URL_OCULUS_VR_PLUGIN); - } - - GUILayout.EndHorizontal(); - } - - GUILayout.Space(5); - - const string supportDaydreamVRTitle = "Daydream"; - if (canSupportDaydream) - { - supportDaydream = Foldouter.ShowFoldoutButtonOnToggleEnabled(Foldouter.Index.Daydream, new GUIContent(supportDaydreamVRTitle), supportDaydream); - } - else - { - GUILayout.BeginHorizontal(); - Foldouter.ShowFoldoutBlank(); - - var tooltip = string.Empty; -#if UNITY_5_6_OR_NEWER - if (activeBuildTargetGroup != BuildTargetGroup.Android) - { - tooltip = "Android platform required."; - } - else if (!VRModule.isGoogleVRPluginDetected) - { - tooltip = "Google VR plugin required."; - } -#else - tooltip = "Unity 5.6 or later version required."; -#endif - GUI.enabled = false; - ShowToggle(new GUIContent(supportDaydreamVRTitle, tooltip), false, GUILayout.Width(80f)); - GUI.enabled = true; -#if UNITY_5_6_OR_NEWER - if (activeBuildTargetGroup != BuildTargetGroup.Android) - { - GUILayout.FlexibleSpace(); - ShowSwitchPlatformButton(BuildTargetGroup.Android, BuildTarget.Android); - } - else if (!VRModule.isGoogleVRPluginDetected) - { - GUILayout.FlexibleSpace(); - ShowUrlLinkButton(URL_GOOGLE_VR_PLUGIN); - } -#endif - GUILayout.EndHorizontal(); - } - - if (supportDaydream && Foldouter.IsExpended(Foldouter.Index.Daydream)) - { - if (supportDaydream) { EditorGUI.BeginChangeCheck(); } else { GUI.enabled = false; } - { - EditorGUI.indentLevel += 2; - - VIUSettings.daydreamSyncPadPressToTrigger = EditorGUILayout.ToggleLeft(new GUIContent("Sync Pad Press to Trigger", "Enable this option to handle the trigger button since the Daydream controller lacks one."), VIUSettings.daydreamSyncPadPressToTrigger); - - EditorGUI.indentLevel -= 2; - } - if (supportDaydream) { s_guiChanged |= EditorGUI.EndChangeCheck(); } else { GUI.enabled = true; } - } - - if (supportDaydream) - { - EditorGUI.indentLevel += 2; - - EditorGUILayout.HelpBox("VRDevice daydream not supported in Editor Mode. Please run on target device.", MessageType.Info); - - EditorGUI.indentLevel -= 2; - } - - GUILayout.Space(5); - - const string supportWaveVRTitle = "VIVE Focus (WaveVR compatible device)"; - if (canSupportWaveVR) - { - supportWaveVR = Foldouter.ShowFoldoutButtonOnToggleEnabled(Foldouter.Index.WaveVR, new GUIContent(supportWaveVRTitle), supportWaveVR); - } - else - { - const float wvrToggleWidth = 226f; - GUILayout.BeginHorizontal(); - Foldouter.ShowFoldoutBlank(); -#if UNITY_5_6_OR_NEWER && !UNITY_5_6_0 && !UNITY_5_6_1 && !UNITY_5_6_2 - if (activeBuildTargetGroup != BuildTargetGroup.Android) - { - GUI.enabled = false; - ShowToggle(new GUIContent(supportWaveVRTitle, "Android platform required."), false, GUILayout.Width(wvrToggleWidth)); - GUI.enabled = true; - GUILayout.FlexibleSpace(); - ShowSwitchPlatformButton(BuildTargetGroup.Android, BuildTarget.Android); - } - else if (!VRModule.isWaveVRPluginDetected) - { - GUI.enabled = false; - ShowToggle(new GUIContent(supportWaveVRTitle, "Wave VR plugin required."), false, GUILayout.Width(wvrToggleWidth)); - GUI.enabled = true; - GUILayout.FlexibleSpace(); - ShowUrlLinkButton(URL_WAVE_VR_PLUGIN); - } -#else - GUI.enabled = false; - ShowToggle(new GUIContent(supportWaveVRTitle, "Unity 5.6.3 or later version required."), false, GUILayout.Width(wvrToggleWidth)); - GUI.enabled = true; -#endif - GUILayout.EndHorizontal(); - } - - if (supportWaveVR && Foldouter.IsExpended(Foldouter.Index.WaveVR)) - { - if (supportWaveVR) { EditorGUI.BeginChangeCheck(); } else { GUI.enabled = false; } - { - EditorGUI.indentLevel += 2; - - VIUSettings.waveVRAddVirtualArmTo3DoFController = EditorGUILayout.ToggleLeft(new GUIContent("Add Virtual Arm for 3 Dof Controller"), VIUSettings.waveVRAddVirtualArmTo3DoFController); - if (!VIUSettings.waveVRAddVirtualArmTo3DoFController) { GUI.enabled = false; } - { - EditorGUI.indentLevel++; - - VIUSettings.waveVRVirtualNeckPosition = EditorGUILayout.Vector3Field("Neck", VIUSettings.waveVRVirtualNeckPosition); - VIUSettings.waveVRVirtualElbowRestPosition = EditorGUILayout.Vector3Field("Elbow", VIUSettings.waveVRVirtualElbowRestPosition); - VIUSettings.waveVRVirtualArmExtensionOffset = EditorGUILayout.Vector3Field("Arm", VIUSettings.waveVRVirtualArmExtensionOffset); - VIUSettings.waveVRVirtualWristRestPosition = EditorGUILayout.Vector3Field("Wrist", VIUSettings.waveVRVirtualWristRestPosition); - VIUSettings.waveVRVirtualHandRestPosition = EditorGUILayout.Vector3Field("Hand", VIUSettings.waveVRVirtualHandRestPosition); - - EditorGUI.indentLevel--; - } - if (!VIUSettings.waveVRAddVirtualArmTo3DoFController) { GUI.enabled = true; } - - EditorGUILayout.BeginHorizontal(); - VIUSettings.simulateWaveVR6DofController = EditorGUILayout.ToggleLeft(new GUIContent("Enable 6 Dof Simulator (Experimental)", "Connect HMD with Type-C keyboard to perform simulation"), VIUSettings.simulateWaveVR6DofController); - s_guiChanged |= EditorGUI.EndChangeCheck(); - ShowUrlLinkButton(URL_WAVE_VR_6DOF_SUMULATOR_USAGE_PAGE, "Usage"); - EditorGUI.BeginChangeCheck(); - EditorGUILayout.EndHorizontal(); - - if (!VIUSettings.enableSimulatorKeyboardMouseControl && supportSimulator) { GUI.enabled = true; } - - EditorGUI.indentLevel -= 2; - } - if (supportWaveVR) { s_guiChanged |= EditorGUI.EndChangeCheck(); } else { GUI.enabled = true; } - } - - if (supportWaveVR) - { - EditorGUI.indentLevel += 2; - - EditorGUILayout.HelpBox("WaveVR device not supported in Editor Mode. Please run on target device.", MessageType.Info); - - EditorGUI.indentLevel -= 2; - } - - GUILayout.Space(5); - - const string supportOculusGoTitle = "Oculus Go"; - if (canSupportOculusGo) - { - supportOculusGo = Foldouter.ShowFoldoutBlankWithEnabledToggle(new GUIContent(supportOculusGoTitle), supportOculusGo); - } - else - { - GUILayout.BeginHorizontal(); - Foldouter.ShowFoldoutBlank(); - - if (activeBuildTargetGroup != BuildTargetGroup.Android) - { - GUI.enabled = false; - ShowToggle(new GUIContent(supportOculusGoTitle, "Android platform required."), false, GUILayout.Width(150f)); - GUI.enabled = true; - GUILayout.FlexibleSpace(); - ShowSwitchPlatformButton(BuildTargetGroup.Android, BuildTarget.Android); - } - else if (!VRModule.isOculusVRPluginDetected) - { - GUI.enabled = false; - ShowToggle(new GUIContent(supportOculusGoTitle, "Oculus VR Plugin required."), false, GUILayout.Width(150f)); - GUI.enabled = true; - GUILayout.FlexibleSpace(); - ShowUrlLinkButton(URL_OCULUS_VR_PLUGIN); - } - - GUILayout.EndHorizontal(); - } - - GUILayout.Space(5); if (supportAnyAndroidVR) { @@ -1111,14 +528,14 @@ private static void OnVIUPreferenceGUI() if (supportAnyStandaloneVR) { - VIUSettings.autoLoadBindingConfigOnStart = Foldouter.ShowFoldoutButtonOnToggleEnabled(Foldouter.Index.AutoBinding, new GUIContent("Load Binding Config on Start"), VIUSettings.autoLoadBindingConfigOnStart); + VIUSettings.autoLoadBindingConfigOnStart = s_autoBindFoldouter.ShowFoldoutButtonOnToggleEnabled(new GUIContent("Load Binding Config on Start"), VIUSettings.autoLoadBindingConfigOnStart); } else { Foldouter.ShowFoldoutBlankWithDisbledToggle(new GUIContent("Load Binding Config on Start", "Role Binding only works on standalone device.")); } - if (supportAnyStandaloneVR && VIUSettings.autoLoadBindingConfigOnStart && Foldouter.IsExpended(Foldouter.Index.AutoBinding)) + if (supportAnyStandaloneVR && VIUSettings.autoLoadBindingConfigOnStart && s_autoBindFoldouter.isExpended) { if (supportAnyStandaloneVR && VIUSettings.autoLoadBindingConfigOnStart) { EditorGUI.BeginChangeCheck(); } else { GUI.enabled = false; } { @@ -1145,14 +562,14 @@ private static void OnVIUPreferenceGUI() if (supportAnyStandaloneVR) { - VIUSettings.enableBindingInterfaceSwitch = Foldouter.ShowFoldoutButtonOnToggleEnabled(Foldouter.Index.BindingUISwitch, new GUIContent("Enable Binding Interface Switch", VIUSettings.BIND_UI_SWITCH_TOOLTIP), VIUSettings.enableBindingInterfaceSwitch); + VIUSettings.enableBindingInterfaceSwitch = s_bindingUIFoldouter.ShowFoldoutButtonOnToggleEnabled(new GUIContent("Enable Binding Interface Switch", VIUSettings.BIND_UI_SWITCH_TOOLTIP), VIUSettings.enableBindingInterfaceSwitch); } else { Foldouter.ShowFoldoutBlankWithDisbledToggle(new GUIContent("Enable Binding Interface Switch", "Role Binding only works with Standalone device.")); } - if (supportAnyStandaloneVR && VIUSettings.enableBindingInterfaceSwitch && Foldouter.IsExpended(Foldouter.Index.BindingUISwitch)) + if (supportAnyStandaloneVR && VIUSettings.enableBindingInterfaceSwitch && s_bindingUIFoldouter.isExpended) { if (supportAnyStandaloneVR && VIUSettings.enableBindingInterfaceSwitch) { EditorGUI.BeginChangeCheck(); } else { GUI.enabled = false; } { diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings.meta b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings.meta new file mode 100644 index 00000000..1ac61a35 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: f1da019796a3356438367ea32e4c3531 +folderAsset: yes +timeCreated: 1548440785 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/DaydreamSettings.cs b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/DaydreamSettings.cs new file mode 100644 index 00000000..5a6ae4b7 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/DaydreamSettings.cs @@ -0,0 +1,152 @@ +//========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== + +using HTC.UnityPlugin.VRModuleManagement; +using UnityEditor; +using UnityEngine; +using UnityEngine.Rendering; + +namespace HTC.UnityPlugin.Vive +{ + public static partial class VIUSettingsEditor + { + public static bool canSupportDaydream + { + get { return DaydreamSettings.instance.canSupport; } + } + + public static bool supportDaydream + { + get { return DaydreamSettings.instance.support; } + set { DaydreamSettings.instance.support = value; } + } + + private class DaydreamSettings : VRPlatformSetting + { + private Foldouter m_foldouter = new Foldouter(); + + public static DaydreamSettings instance { get; private set; } + + public DaydreamSettings() { instance = this; } + + public override int order { get { return 101; } } + + protected override BuildTargetGroup requirdPlatform { get { return BuildTargetGroup.Android; } } + + public override bool canSupport + { +#if UNITY_5_6_OR_NEWER + get { return activeBuildTargetGroup == BuildTargetGroup.Android && VRModule.isGoogleVRPluginDetected; } +#else + get { return false; } +#endif + } + + public override bool support + { +#if UNITY_5_6_OR_NEWER + get + { + if (!canSupport) { return false; } + if (!VIUSettings.activateGoogleVRModule) { return false; } + if (!DaydreamSDK.enabled) { return false; } + if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel24) { return false; } + if (PlayerSettings.colorSpace == ColorSpace.Linear && !GraphicsAPIContainsOnly(BuildTarget.Android, GraphicsDeviceType.OpenGLES3)) { return false; } + return true; + } + set + { + if (support == value) { return; } + + if (value) + { + if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel24) + { + PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel24; + } + + if (PlayerSettings.colorSpace == ColorSpace.Linear) + { + SetGraphicsAPI(BuildTarget.Android, GraphicsDeviceType.OpenGLES3); + } + + supportWaveVR = false; + supportOculusGo = false; + } + + DaydreamSDK.enabled = value; + VIUSettings.activateGoogleVRModule = value; + } +#else + get { return false; } + set { } +#endif + } + + public override void OnPreferenceGUI() + { + const string title = "Daydream"; + if (canSupport) + { + support = m_foldouter.ShowFoldoutButtonOnToggleEnabled(new GUIContent(title), support); + } + else + { + GUILayout.BeginHorizontal(); + Foldouter.ShowFoldoutBlank(); + + var tooltip = string.Empty; +#if UNITY_5_6_OR_NEWER + if (activeBuildTargetGroup != BuildTargetGroup.Android) + { + tooltip = "Android platform required."; + } + else if (!VRModule.isGoogleVRPluginDetected) + { + tooltip = "Google VR plugin required."; + } +#else + tooltip = "Unity 5.6 or later version required."; +#endif + GUI.enabled = false; + ShowToggle(new GUIContent(title, tooltip), false, GUILayout.Width(80f)); + GUI.enabled = true; +#if UNITY_5_6_OR_NEWER + if (activeBuildTargetGroup != BuildTargetGroup.Android) + { + GUILayout.FlexibleSpace(); + ShowSwitchPlatformButton(BuildTargetGroup.Android, BuildTarget.Android); + } + else if (!VRModule.isGoogleVRPluginDetected) + { + GUILayout.FlexibleSpace(); + ShowUrlLinkButton(URL_GOOGLE_VR_PLUGIN); + } +#endif + GUILayout.EndHorizontal(); + } + + if (support && m_foldouter.isExpended) + { + if (support) { EditorGUI.BeginChangeCheck(); } else { GUI.enabled = false; } + { + EditorGUI.indentLevel += 2; + + VIUSettings.daydreamSyncPadPressToTrigger = EditorGUILayout.ToggleLeft(new GUIContent("Sync Pad Press to Trigger", "Enable this option to handle the trigger button since the Daydream controller lacks one."), VIUSettings.daydreamSyncPadPressToTrigger); + + EditorGUI.indentLevel -= 2; + } + if (support) { s_guiChanged |= EditorGUI.EndChangeCheck(); } else { GUI.enabled = true; } + } + + if (support) + { + EditorGUI.indentLevel += 2; + + EditorGUILayout.HelpBox("VRDevice daydream not supported in Editor Mode. Please run on target device.", MessageType.Info); + + EditorGUI.indentLevel -= 2; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/DaydreamSettings.cs.meta b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/DaydreamSettings.cs.meta new file mode 100644 index 00000000..a4b79db9 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/DaydreamSettings.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fb8c500e999ec3e4cb81bfeba5dcf30e +timeCreated: 1548535773 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusGoSettings.cs b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusGoSettings.cs new file mode 100644 index 00000000..66e849c1 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusGoSettings.cs @@ -0,0 +1,120 @@ +//========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== + +using HTC.UnityPlugin.VRModuleManagement; +using UnityEditor; +using UnityEngine; +using UnityEngine.Rendering; + +namespace HTC.UnityPlugin.Vive +{ + public static partial class VIUSettingsEditor + { + public static bool canSupportOculusGo + { + get { return OculusGoSettings.instance.canSupport; } + } + + public static bool supportOculusGo + { + get { return OculusGoSettings.instance.support; } + set { OculusGoSettings.instance.support = value; } + } + + private class OculusGoSettings : VRPlatformSetting + { + public static OculusGoSettings instance { get; private set; } + + public OculusGoSettings() { instance = this; } + + public override int order { get { return 103; } } + + protected override BuildTargetGroup requirdPlatform { get { return BuildTargetGroup.Android; } } + + public override bool canSupport + { +#if UNITY_5_6_OR_NEWER + get { return activeBuildTargetGroup == BuildTargetGroup.Android && VRModule.isOculusVRPluginDetected; } +#else + get { return false; } +#endif + } + + public override bool support + { +#if UNITY_5_6_OR_NEWER + get + { + if (!canSupport) { return false; } + if (!VIUSettings.activateOculusVRModule) { return false; } + if (!OculusSDK.enabled) { return false; } + if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel21) { return false; } + if (PlayerSettings.graphicsJobs) { return false; } + if ((PlayerSettings.colorSpace == ColorSpace.Linear || PlayerSettings.gpuSkinning) && !GraphicsAPIContainsOnly(BuildTarget.Android, GraphicsDeviceType.OpenGLES3)) { return false; } + return true; + } + set + { + if (support == value) { return; } + + if (value) + { + supportWaveVR = false; + supportDaydream = false; + + if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel21) + { + PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel21; + } + + PlayerSettings.graphicsJobs = false; + + if (PlayerSettings.colorSpace == ColorSpace.Linear || PlayerSettings.gpuSkinning) + { + SetGraphicsAPI(BuildTarget.Android, GraphicsDeviceType.OpenGLES3); + } + } + + OculusSDK.enabled = value; + VIUSettings.activateOculusVRModule = value; + } +#else + get { return false; } + set { } +#endif + } + + public override void OnPreferenceGUI() + { + const string title = "Oculus Go"; + if (canSupport) + { + support = Foldouter.ShowFoldoutBlankWithEnabledToggle(new GUIContent(title), support); + } + else + { + GUILayout.BeginHorizontal(); + Foldouter.ShowFoldoutBlank(); + + if (activeBuildTargetGroup != BuildTargetGroup.Android) + { + GUI.enabled = false; + ShowToggle(new GUIContent(title, "Android platform required."), false, GUILayout.Width(150f)); + GUI.enabled = true; + GUILayout.FlexibleSpace(); + ShowSwitchPlatformButton(BuildTargetGroup.Android, BuildTarget.Android); + } + else if (!VRModule.isOculusVRPluginDetected) + { + GUI.enabled = false; + ShowToggle(new GUIContent(title, "Oculus VR Plugin required."), false, GUILayout.Width(150f)); + GUI.enabled = true; + GUILayout.FlexibleSpace(); + ShowUrlLinkButton(URL_OCULUS_VR_PLUGIN); + } + + GUILayout.EndHorizontal(); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusGoSettings.cs.meta b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusGoSettings.cs.meta new file mode 100644 index 00000000..1eef4318 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusGoSettings.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d8e0130e4f596a54b8f2354b10c0347f +timeCreated: 1548535773 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusSettings.cs b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusSettings.cs new file mode 100644 index 00000000..cd6f3197 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusSettings.cs @@ -0,0 +1,108 @@ +//========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== + +using HTC.UnityPlugin.VRModuleManagement; +using UnityEditor; +using UnityEngine; + +namespace HTC.UnityPlugin.Vive +{ + public static partial class VIUSettingsEditor + { + public static bool canSupportOculus + { + get { return OculusSettings.instance.canSupport; } + } + + public static bool supportOculus + { + get { return OculusSettings.instance.support; } + set { OculusSettings.instance.support = value; } + } + + private class OculusSettings : VRPlatformSetting + { + public static OculusSettings instance { get; private set; } + + public OculusSettings() { instance = this; } + + public override int order { get { return 2; } } + + protected override BuildTargetGroup requirdPlatform { get { return BuildTargetGroup.Standalone; } } + + public override bool canSupport + { + get + { +#if UNITY_5_5_OR_NEWER && !UNITY_5_6_0 && !UNITY_5_6_1 && !UNITY_5_6_2 + return activeBuildTargetGroup == BuildTargetGroup.Standalone; +#else + return activeBuildTargetGroup == BuildTargetGroup.Standalone && VRModule.isOculusVRPluginDetected; +#endif + ; + } + } + + public override bool support + { + get + { +#if UNITY_5_5_OR_NEWER + return canSupport && (VIUSettings.activateOculusVRModule || VIUSettings.activateUnityNativeVRModule) && OculusSDK.enabled; +#elif UNITY_5_4_OR_NEWER + return canSupport && VIUSettings.activateOculusVRModule && OculusSDK.enabled; +#else + return canSupport && VIUSettings.activateOculusVRModule && virtualRealitySupported; +#endif + } + set + { + if (support == value) { return; } + + VIUSettings.activateOculusVRModule = value; + +#if UNITY_5_5_OR_NEWER + OculusSDK.enabled = value; + VIUSettings.activateUnityNativeVRModule = value || supportOpenVR; +#elif UNITY_5_4_OR_NEWER + OculusSDK.enabled = value; +#else + virtualRealitySupported = value; +#endif + } + } + + public override void OnPreferenceGUI() + { + const string title = "Oculus Rift & Touch"; + if (canSupport) + { + support = Foldouter.ShowFoldoutBlankWithEnabledToggle(new GUIContent(title), support); + } + else + { + GUILayout.BeginHorizontal(); + Foldouter.ShowFoldoutBlank(); + + if (activeBuildTargetGroup != BuildTargetGroup.Standalone) + { + GUI.enabled = false; + ShowToggle(new GUIContent(title, "Standalone platform required."), false, GUILayout.Width(150f)); + GUI.enabled = true; + GUILayout.FlexibleSpace(); + ShowSwitchPlatformButton(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64); + } + else if (!VRModule.isOculusVRPluginDetected) + { + GUI.enabled = false; + ShowToggle(new GUIContent(title, "Oculus VR Plugin required."), false, GUILayout.Width(150f)); + GUI.enabled = true; + GUILayout.FlexibleSpace(); + ShowUrlLinkButton(URL_OCULUS_VR_PLUGIN); + } + + GUILayout.EndHorizontal(); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusSettings.cs.meta b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusSettings.cs.meta new file mode 100644 index 00000000..7aebfe34 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OculusSettings.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 70f20a2d334c57a48b5e6b0ba4fdd6e0 +timeCreated: 1548535773 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OpenVRSettings.cs b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OpenVRSettings.cs new file mode 100644 index 00000000..eee77b20 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OpenVRSettings.cs @@ -0,0 +1,193 @@ +//========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== + +using HTC.UnityPlugin.VRModuleManagement; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace HTC.UnityPlugin.Vive +{ + public static partial class VIUSettingsEditor + { + public static bool canSupportOpenVR + { + get { return OpenVRSettings.instance.canSupport; } + } + + public static bool supportOpenVR + { + get { return OpenVRSettings.instance.support; } + set { OpenVRSettings.instance.support = value; } + } + + private class OpenVRSettings : VRPlatformSetting + { + private Foldouter m_foldouter = new Foldouter(); + + public static OpenVRSettings instance { get; private set; } + + public OpenVRSettings() { instance = this; } + + public override int order { get { return 1; } } + + protected override BuildTargetGroup requirdPlatform { get { return BuildTargetGroup.Standalone; } } + + public override bool canSupport + { + get + { +#if UNITY_5_5_OR_NEWER + return activeBuildTargetGroup == BuildTargetGroup.Standalone; +#else + return activeBuildTargetGroup == BuildTargetGroup.Standalone && VRModule.isSteamVRPluginDetected; +#endif + ; + } + } + + public override bool support + { + get + { +#if UNITY_5_5_OR_NEWER + return canSupport && (VIUSettings.activateSteamVRModule || VIUSettings.activateUnityNativeVRModule) && OpenVRSDK.enabled; +#elif UNITY_5_4_OR_NEWER + return canSupport && VIUSettings.activateSteamVRModule && OpenVRSDK.enabled; +#else + return canSupport && VIUSettings.activateSteamVRModule && !virtualRealitySupported; +#endif + } + set + { + if (support == value) { return; } + + VIUSettings.activateSteamVRModule = value; + +#if UNITY_5_5_OR_NEWER + OpenVRSDK.enabled = value; + VIUSettings.activateUnityNativeVRModule = value || supportOculus; +#elif UNITY_5_4_OR_NEWER + OpenVRSDK.enabled = value; +#else + if (value) + { + virtualRealitySupported = false; + } +#endif + } + } + + public override void OnPreferenceGUI() + { + const string title = "VIVE (OpenVR compatible device)"; + if (canSupport) + { + support = m_foldouter.ShowFoldoutButtonOnToggleEnabled(new GUIContent(title), support); + } + else + { + GUILayout.BeginHorizontal(); + Foldouter.ShowFoldoutBlank(); + + if (activeBuildTargetGroup != BuildTargetGroup.Standalone) + { + GUI.enabled = false; + ShowToggle(new GUIContent(title, "Standalone platform required."), false, GUILayout.Width(230f)); + GUI.enabled = true; + GUILayout.FlexibleSpace(); + ShowSwitchPlatformButton(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64); + } + else if (!VRModule.isSteamVRPluginDetected) + { + GUI.enabled = false; + ShowToggle(new GUIContent(title, "SteamVR Plugin required."), false, GUILayout.Width(230f)); + GUI.enabled = true; + GUILayout.FlexibleSpace(); + ShowUrlLinkButton(URL_STEAM_VR_PLUGIN); + } + + GUILayout.EndHorizontal(); + } + + if (support && m_foldouter.isExpended) + { + if (support && VRModule.isSteamVRPluginDetected) { EditorGUI.BeginChangeCheck(); } else { GUI.enabled = false; } + { + EditorGUI.indentLevel += 2; + + VIUSettings.autoLoadExternalCameraConfigOnStart = EditorGUILayout.ToggleLeft(new GUIContent("Load Config and Enable External Camera on Start", "You can also load config by calling ExternalCameraHook.LoadConfigFromFile(path) in script."), VIUSettings.autoLoadExternalCameraConfigOnStart); + if (!VIUSettings.autoLoadExternalCameraConfigOnStart && support) { GUI.enabled = false; } + { + EditorGUI.indentLevel++; + + EditorGUI.BeginChangeCheck(); + VIUSettings.externalCameraConfigFilePath = EditorGUILayout.DelayedTextField(new GUIContent("Config Path"), VIUSettings.externalCameraConfigFilePath); + if (string.IsNullOrEmpty(VIUSettings.externalCameraConfigFilePath)) + { + VIUSettings.externalCameraConfigFilePath = VIUSettings.EXTERNAL_CAMERA_CONFIG_FILE_PATH_DEFAULT_VALUE; + EditorGUI.EndChangeCheck(); + } + else if (EditorGUI.EndChangeCheck() && VIUSettings.externalCameraConfigFilePath.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) + { + VIUSettings.externalCameraConfigFilePath = VIUSettings.EXTERNAL_CAMERA_CONFIG_FILE_PATH_DEFAULT_VALUE; + } + // Create button that writes default config file + if (VIUSettings.autoLoadExternalCameraConfigOnStart && support && !File.Exists(VIUSettings.externalCameraConfigFilePath)) + { + if (support && VRModule.isSteamVRPluginDetected) { s_guiChanged |= EditorGUI.EndChangeCheck(); } + ShowCreateExCamCfgButton(); + if (support && VRModule.isSteamVRPluginDetected) { EditorGUI.BeginChangeCheck(); } + } + + EditorGUI.indentLevel--; + } + if (!VIUSettings.autoLoadExternalCameraConfigOnStart && support) { GUI.enabled = true; } + + VIUSettings.enableExternalCameraSwitch = EditorGUILayout.ToggleLeft(new GUIContent("Enable External Camera Switch", VIUSettings.EX_CAM_UI_SWITCH_TOOLTIP), VIUSettings.enableExternalCameraSwitch); + if (!VIUSettings.enableExternalCameraSwitch && support) { GUI.enabled = false; } + { + EditorGUI.indentLevel++; + + VIUSettings.externalCameraSwitchKey = (KeyCode)EditorGUILayout.EnumPopup("Switch Key", VIUSettings.externalCameraSwitchKey); + VIUSettings.externalCameraSwitchKeyModifier = (KeyCode)EditorGUILayout.EnumPopup("Switch Key Modifier", VIUSettings.externalCameraSwitchKeyModifier); + + EditorGUI.indentLevel--; + } + if (!VIUSettings.enableExternalCameraSwitch && support) { GUI.enabled = true; } + + EditorGUI.indentLevel -= 2; + } + if (support && VRModule.isSteamVRPluginDetected) { s_guiChanged |= EditorGUI.EndChangeCheck(); } else { GUI.enabled = true; } + } + + if (support && !VRModule.isSteamVRPluginDetected) + { + EditorGUI.indentLevel += 2; + + GUILayout.BeginHorizontal(); + EditorGUILayout.HelpBox("External-Camera(Mix-Reality), animated controller model, VIVE Controller haptics(vibration)" + +#if UNITY_2017_1_OR_NEWER + ", VIVE Tracker USB/Pogo-pin input" + +#else + ", VIVE Tracker device" + +#endif + " NOT supported! Install SteamVR Plugin to get support.", MessageType.Warning); + + s_warningHeight = Mathf.Max(s_warningHeight, GUILayoutUtility.GetLastRect().height); + + if (!VRModule.isSteamVRPluginDetected) + { + GUILayout.BeginVertical(GUILayout.Height(s_warningHeight)); + GUILayout.FlexibleSpace(); + ShowUrlLinkButton(URL_STEAM_VR_PLUGIN); + GUILayout.FlexibleSpace(); + GUILayout.EndVertical(); + } + GUILayout.EndHorizontal(); + + EditorGUI.indentLevel -= 2; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OpenVRSettings.cs.meta b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OpenVRSettings.cs.meta new file mode 100644 index 00000000..8a1ebcf8 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/OpenVRSettings.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1bbe202b3222ba04aa5789598af0d1c9 +timeCreated: 1548446171 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/SimulatorSettings.cs b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/SimulatorSettings.cs new file mode 100644 index 00000000..fbb6a078 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/SimulatorSettings.cs @@ -0,0 +1,82 @@ +//========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== + +using UnityEditor; +using UnityEngine; + +namespace HTC.UnityPlugin.Vive +{ + public static partial class VIUSettingsEditor + { + public static bool canSupportSimulator + { + get { return SimulatorSettings.instance.canSupport; } + } + + public static bool supportSimulator + { + get { return SimulatorSettings.instance.support; } + set { SimulatorSettings.instance.support = value; } + } + + private class SimulatorSettings : VRPlatformSetting + { + private Foldouter m_foldouter = new Foldouter(); + + public static SimulatorSettings instance { get; private set; } + + public SimulatorSettings() { instance = this; } + + public override int order { get { return 0; } } + + protected override BuildTargetGroup requirdPlatform { get { return BuildTargetGroup.Unknown; } } + + public override bool canSupport + { + get { return true; } + } + + public override bool support + { + get { return canSupport && VIUSettings.activateSimulatorModule; } + set { VIUSettings.activateSimulatorModule = value; } + } + + public override void OnPreferenceGUI() + { + const string title = "Simulator"; + if (canSupport) + { + support = m_foldouter.ShowFoldoutButtonOnToggleEnabled(new GUIContent(title, "If checked, the simulator will activated automatically if no other valid VR devices found."), support); + } + else + { + Foldouter.ShowFoldoutBlankWithDisbledToggle(new GUIContent(title)); + } + + if (support && m_foldouter.isExpended) + { + if (support) { EditorGUI.BeginChangeCheck(); } else { GUI.enabled = false; } + { + EditorGUI.indentLevel += 2; + VIUSettings.simulatorAutoTrackMainCamera = EditorGUILayout.ToggleLeft(new GUIContent("Enable Auto Camera Tracking", "Main camera only"), VIUSettings.simulatorAutoTrackMainCamera); + VIUSettings.enableSimulatorKeyboardMouseControl = EditorGUILayout.ToggleLeft(new GUIContent("Enable Keyboard-Mouse Control", "You can also control Simulator devices by handling VRModule.Simulator.onUpdateDeviceState event."), VIUSettings.enableSimulatorKeyboardMouseControl); + + if (!VIUSettings.enableSimulatorKeyboardMouseControl && support) { GUI.enabled = false; } + { + EditorGUI.indentLevel++; + VIUSettings.simulateTrackpadTouch = EditorGUILayout.Toggle(new GUIContent("Simulate Trackpad Touch", VIUSettings.SIMULATE_TRACKPAD_TOUCH_TOOLTIP), VIUSettings.simulateTrackpadTouch); + VIUSettings.simulatorKeyMoveSpeed = EditorGUILayout.DelayedFloatField(new GUIContent("Keyboard Move Speed", VIUSettings.SIMULATOR_KEY_MOVE_SPEED_TOOLTIP), VIUSettings.simulatorKeyMoveSpeed); + VIUSettings.simulatorKeyRotateSpeed = EditorGUILayout.DelayedFloatField(new GUIContent("Keyboard Rotate Speed", VIUSettings.SIMULATOR_KEY_ROTATE_SPEED_TOOLTIP), VIUSettings.simulatorKeyRotateSpeed); + VIUSettings.simulatorMouseRotateSpeed = EditorGUILayout.DelayedFloatField(new GUIContent("Mouse Rotate Speed"), VIUSettings.simulatorMouseRotateSpeed); + EditorGUI.indentLevel--; + } + if (!VIUSettings.enableSimulatorKeyboardMouseControl && support) { GUI.enabled = true; } + + EditorGUI.indentLevel -= 2; + } + if (support) { s_guiChanged |= EditorGUI.EndChangeCheck(); } else { GUI.enabled = true; } + } + } + } + } +} \ No newline at end of file diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/SimulatorSettings.cs.meta b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/SimulatorSettings.cs.meta new file mode 100644 index 00000000..9cb6e9f2 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/SimulatorSettings.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9d4ec763a3ed18d4db044da7874559d8 +timeCreated: 1548446171 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/WaveVRSettings.cs b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/WaveVRSettings.cs new file mode 100644 index 00000000..58db5e00 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/WaveVRSettings.cs @@ -0,0 +1,184 @@ +//========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== + +using HTC.UnityPlugin.VRModuleManagement; +using UnityEditor; +using UnityEngine; +using UnityEngine.Rendering; + +namespace HTC.UnityPlugin.Vive +{ + public static partial class VIUSettingsEditor + { + public static bool canSupportWaveVR + { + get { return WaveVRSettings.instance.canSupport; } + } + + public static bool supportWaveVR + { + get { return WaveVRSettings.instance.support; } + set { WaveVRSettings.instance.support = value; } + } + + private class WaveVRSettings : VRPlatformSetting + { + private Foldouter m_foldouter = new Foldouter(); + + public static WaveVRSettings instance { get; private set; } + + public WaveVRSettings() { instance = this; } + + public override int order { get { return 102; } } + + protected override BuildTargetGroup requirdPlatform { get { return BuildTargetGroup.Android; } } + + public override bool canSupport + { +#if UNITY_5_6_OR_NEWER && !UNITY_5_6_0 && !UNITY_5_6_1 && !UNITY_5_6_2 + get { return activeBuildTargetGroup == BuildTargetGroup.Android && VRModule.isWaveVRPluginDetected; } +#else + get { return false; } +#endif + } + + public override bool support + { +#if UNITY_5_6_OR_NEWER && !UNITY_5_6_0 && !UNITY_5_6_1 && !UNITY_5_6_2 + get + { + if (!canSupport) { return false; } + if (!VIUSettings.activateWaveVRModule) { return false; } + if (virtualRealitySupported) { return false; } + if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel23) { return false; } + if (PlayerSettings.colorSpace == ColorSpace.Linear && !GraphicsAPIContainsOnly(BuildTarget.Android, GraphicsDeviceType.OpenGLES3)) { return false; } + return true; + } + set + { + if (support == value) { return; } + + if (value) + { + virtualRealitySupported = false; + + if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel23) + { + PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel23; + } + + if (PlayerSettings.colorSpace == ColorSpace.Linear) + { + SetGraphicsAPI(BuildTarget.Android, GraphicsDeviceType.OpenGLES3); + } + + supportDaydream = false; + supportOculusGo = false; + } + + VIUSettings.activateWaveVRModule = value; + } +#else + get { return false; } + set { } +#endif + } + + public override void OnPreferenceGUI() + { + + const string title = "VIVE Focus (WaveVR compatible device)"; + if (canSupport) + { + support = m_foldouter.ShowFoldoutButtonOnToggleEnabled(new GUIContent(title), support); + } + else + { + const float wvrToggleWidth = 226f; + GUILayout.BeginHorizontal(); + Foldouter.ShowFoldoutBlank(); +#if UNITY_5_6_OR_NEWER && !UNITY_5_6_0 && !UNITY_5_6_1 && !UNITY_5_6_2 + if (activeBuildTargetGroup != BuildTargetGroup.Android) + { + GUI.enabled = false; + ShowToggle(new GUIContent(title, "Android platform required."), false, GUILayout.Width(wvrToggleWidth)); + GUI.enabled = true; + GUILayout.FlexibleSpace(); + ShowSwitchPlatformButton(BuildTargetGroup.Android, BuildTarget.Android); + } + else if (!VRModule.isWaveVRPluginDetected) + { + GUI.enabled = false; + ShowToggle(new GUIContent(title, "Wave VR plugin required."), false, GUILayout.Width(wvrToggleWidth)); + GUI.enabled = true; + GUILayout.FlexibleSpace(); + ShowUrlLinkButton(URL_WAVE_VR_PLUGIN); + } +#else + GUI.enabled = false; + ShowToggle(new GUIContent(title, "Unity 5.6.3 or later version required."), false, GUILayout.Width(wvrToggleWidth)); + GUI.enabled = true; +#endif + GUILayout.EndHorizontal(); + } + + if (support && m_foldouter.isExpended) + { + if (support) { EditorGUI.BeginChangeCheck(); } else { GUI.enabled = false; } + { + EditorGUI.indentLevel += 2; + + VIUSettings.waveVRAddVirtualArmTo3DoFController = EditorGUILayout.ToggleLeft(new GUIContent("Add Virtual Arm for 3 Dof Controller"), VIUSettings.waveVRAddVirtualArmTo3DoFController); + if (!VIUSettings.waveVRAddVirtualArmTo3DoFController) { GUI.enabled = false; } + { + EditorGUI.indentLevel++; + + VIUSettings.waveVRVirtualNeckPosition = EditorGUILayout.Vector3Field("Neck", VIUSettings.waveVRVirtualNeckPosition); + VIUSettings.waveVRVirtualElbowRestPosition = EditorGUILayout.Vector3Field("Elbow", VIUSettings.waveVRVirtualElbowRestPosition); + VIUSettings.waveVRVirtualArmExtensionOffset = EditorGUILayout.Vector3Field("Arm", VIUSettings.waveVRVirtualArmExtensionOffset); + VIUSettings.waveVRVirtualWristRestPosition = EditorGUILayout.Vector3Field("Wrist", VIUSettings.waveVRVirtualWristRestPosition); + VIUSettings.waveVRVirtualHandRestPosition = EditorGUILayout.Vector3Field("Hand", VIUSettings.waveVRVirtualHandRestPosition); + + EditorGUI.indentLevel--; + } + if (!VIUSettings.waveVRAddVirtualArmTo3DoFController) { GUI.enabled = true; } + + EditorGUILayout.BeginHorizontal(); + VIUSettings.simulateWaveVR6DofController = EditorGUILayout.ToggleLeft(new GUIContent("Enable 6 Dof Simulator (Experimental)", "Connect HMD with Type-C keyboard to perform simulation"), VIUSettings.simulateWaveVR6DofController); + s_guiChanged |= EditorGUI.EndChangeCheck(); + ShowUrlLinkButton(URL_WAVE_VR_6DOF_SUMULATOR_USAGE_PAGE, "Usage"); + EditorGUI.BeginChangeCheck(); + EditorGUILayout.EndHorizontal(); + + if (!VIUSettings.enableSimulatorKeyboardMouseControl && supportSimulator) { GUI.enabled = true; } + + EditorGUI.indentLevel -= 2; + } + if (support) { s_guiChanged |= EditorGUI.EndChangeCheck(); } else { GUI.enabled = true; } + } + + if (support) + { + EditorGUI.indentLevel += 2; + +#if VIU_WAVEVR_2_1_0_OR_NEWER + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.HelpBox("WaveVR Simulator will be activated in Editor Mode.", MessageType.Info); + + s_warningHeight = Mathf.Max(s_warningHeight, GUILayoutUtility.GetLastRect().height); + GUILayout.BeginVertical(GUILayout.Height(s_warningHeight)); + GUILayout.FlexibleSpace(); + ShowUrlLinkButton("https://hub.vive.com/storage/app/doc/en-us/Simulator.html", "Usage"); + GUILayout.FlexibleSpace(); + GUILayout.EndVertical(); + + EditorGUILayout.EndHorizontal(); +#else + EditorGUILayout.HelpBox("WaveVR device not supported in Editor Mode. Please run on target device.", MessageType.Info); +#endif + + EditorGUI.indentLevel -= 2; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/WaveVRSettings.cs.meta b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/WaveVRSettings.cs.meta new file mode 100644 index 00000000..a6225583 --- /dev/null +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/VRPlatformSettings/WaveVRSettings.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d682ce765c334a8489f92ce7a4a3aad9 +timeCreated: 1548535773 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Misc/RenderModelHook.cs b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Misc/RenderModelHook.cs index d14b5c81..a6a81fe6 100644 --- a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Misc/RenderModelHook.cs +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Misc/RenderModelHook.cs @@ -1,9 +1,11 @@ //========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== using HTC.UnityPlugin.Utility; -using HTC.UnityPlugin.Vive.SteamVRExtension; using HTC.UnityPlugin.VRModuleManagement; +using System; using System.Collections.Generic; +using System.Linq; +using System.Reflection; using UnityEngine; namespace HTC.UnityPlugin.Vive @@ -13,6 +15,93 @@ namespace HTC.UnityPlugin.Vive [AddComponentMenu("HTC/VIU/Hooks/Render Model Hook", 10)] public class RenderModelHook : MonoBehaviour, IViveRoleComponent { + [AttributeUsage(AttributeTargets.Class)] + public class CreatorPriorityAttirbute : Attribute + { + public int priority { get; set; } + public CreatorPriorityAttirbute(int priority = 0) { this.priority = priority; } + } + + public abstract class RenderModelCreator + { + public abstract bool shouldActive { get; } + protected RenderModelHook hook { get; private set; } + + public void Initialize(RenderModelHook hook) { this.hook = hook; } + public abstract void UpdateRenderModel(); + public abstract void CleanUpRenderModel(); + } + + [CreatorPriorityAttirbute(1)] + private class DefaultRenderModelCreator : RenderModelCreator + { + private VRModuleDeviceModel m_loadedModelEnum = (VRModuleDeviceModel)(-1); + private GameObject m_model; + + public override bool shouldActive { get { return true; } } + + public override void UpdateRenderModel() + { + var index = hook.GetModelDeviceIndex(); + + if (!VRModule.IsValidDeviceIndex(index)) + { + if (m_model != null) + { + m_model.SetActive(false); + } + } + else + { + var loadModelEnum = VRModuleDeviceModel.Unknown; + if (hook.m_overrideModel != OverrideModelEnum.DontOverride) + { + loadModelEnum = (VRModuleDeviceModel)hook.m_overrideModel; + } + else + { + loadModelEnum = VRModule.GetCurrentDeviceState(index).deviceModel; + } + + if (ChangeProp.Set(ref m_loadedModelEnum, loadModelEnum)) + { + CleanUpRenderModel(); + + var prefab = Resources.Load("Models/VIUModel" + m_loadedModelEnum.ToString()); + if (prefab != null) + { + m_model = Instantiate(prefab); + m_model.transform.SetParent(hook.transform, false); + m_model.gameObject.name = "VIUModel" + m_loadedModelEnum.ToString(); + + if (hook.m_overrideShader != null) + { + var renderer = m_model.GetComponentInChildren(); + if (renderer != null) + { + renderer.material.shader = hook.m_overrideShader; + } + } + } + } + + if (m_model != null) + { + m_model.SetActive(true); + } + } + } + + public override void CleanUpRenderModel() + { + if (m_model != null) + { + Destroy(m_model); + m_model = null; + } + } + } + public enum Mode { Disable, @@ -54,6 +143,8 @@ public enum OverrideModelEnum KnucklesRight = VRModuleDeviceModel.KnucklesRight, OculusGoController = VRModuleDeviceModel.OculusGoController, OculusGearVrController = VRModuleDeviceModel.OculusGearVrController, + WMRControllerLeft = VRModuleDeviceModel.WMRControllerLeft, + WMRControllerRight = VRModuleDeviceModel.WMRControllerRight, } [SerializeField] @@ -69,10 +160,10 @@ public enum OverrideModelEnum [SerializeField] private Shader m_overrideShader = null; - private uint m_currentDeviceIndex = VRModule.INVALID_DEVICE_INDEX; - private VRModuleDeviceModel m_currentLoadedStaticModel; - private OverrideModelEnum m_currentOverrideModel; - private GameObject m_modelObj; + private static readonly Type[] s_creatorTypes; + private RenderModelCreator[] m_creators; + private int m_activeCreatorIndex = -1; + private int m_defaultCreatorIndex = -1; private bool m_isQuiting; public ViveRoleProperty viveRole { get { return m_viveRole; } } @@ -85,6 +176,31 @@ public enum OverrideModelEnum public Shader overrideShader { get { return m_overrideShader; } set { m_overrideShader = value; } } + static RenderModelHook() + { + try + { + var creatorTypes = new List(); + foreach (var type in Assembly.GetAssembly(typeof(RenderModelCreator)).GetTypes().Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(RenderModelCreator)))) + { + creatorTypes.Add(type); + } + s_creatorTypes = creatorTypes.OrderBy(t => + { + foreach (var at in t.GetCustomAttributes(typeof(CreatorPriorityAttirbute), true)) + { + return ((CreatorPriorityAttirbute)at).priority; + } + return 0; + }).ToArray(); + } + catch (Exception e) + { + s_creatorTypes = new Type[0]; + Debug.LogError(e); + } + } + #if UNITY_EDITOR private void OnValidate() { @@ -94,10 +210,24 @@ private void OnValidate() } } #endif + private void Awake() + { + m_creators = new RenderModelCreator[s_creatorTypes.Length]; + for (int i = s_creatorTypes.Length - 1; i >= 0; --i) + { + m_creators[i] = (RenderModelCreator)Activator.CreateInstance(s_creatorTypes[i]); + m_creators[i].Initialize(this); + + if (s_creatorTypes[i] == typeof(DefaultRenderModelCreator)) + { + m_defaultCreatorIndex = i; + } + } + } protected virtual void OnEnable() { - VRModule.onActiveModuleChanged += UpdateModel; + VRModule.onActiveModuleChanged += OnActiveModuleChanged; m_viveRole.onDeviceIndexChanged += OnDeviceIndexChanged; UpdateModel(); @@ -105,18 +235,19 @@ protected virtual void OnEnable() protected virtual void OnDisable() { - VRModule.onActiveModuleChanged -= UpdateModel; + VRModule.onActiveModuleChanged -= OnActiveModuleChanged; m_viveRole.onDeviceIndexChanged -= OnDeviceIndexChanged; UpdateModel(); } - private void OnApplicationQuit() - { - m_isQuiting = true; - } + private void OnDeviceIndexChanged(uint deviceIndex) { UpdateModel(); } + + private void OnActiveModuleChanged(VRModuleActiveEnum module) { UpdateModel(); } - private uint GetCurrentDeviceIndex() + private void OnApplicationQuit() { m_isQuiting = true; } + + public uint GetModelDeviceIndex() { if (!enabled) { return VRModule.INVALID_DEVICE_INDEX; } @@ -137,305 +268,43 @@ private uint GetCurrentDeviceIndex() return result; } - private void OnDeviceIndexChanged(uint deviceIndex) - { - UpdateModel(); - } - - private void UpdateModel(VRModuleActiveEnum module) { UpdateModel(); } - private void UpdateModel() { if (m_isQuiting) { return; } - var overrideModelChanged = ChangeProp.Set(ref m_currentOverrideModel, m_overrideModel); - - if (m_currentOverrideModel == OverrideModelEnum.DontOverride) - { - switch (VRModule.activeModule) - { -#if VIU_STEAMVR - case VRModuleActiveEnum.SteamVR: - UpdateSteamVRModel(); - break; -#endif -#if VIU_WAVEVR - case VRModuleActiveEnum.WaveVR: - UpdateWaveVRModel(); - break; -#endif - case VRModuleActiveEnum.Uninitialized: - if (m_modelObj != null) - { - m_modelObj.SetActive(false); - } - break; - default: - UpdateDefaultModel(); - break; - } - } - else + var activeCreatorIndex = -1; + if (enabled) { - if (overrideModelChanged) - { - ReloadedStaticModel((VRModuleDeviceModel)m_currentOverrideModel); - } - - if (ChangeProp.Set(ref m_currentDeviceIndex, GetCurrentDeviceIndex()) && m_modelObj != null) + if (m_overrideModel == OverrideModelEnum.DontOverride) { - m_modelObj.SetActive(VRModule.IsValidDeviceIndex(m_currentDeviceIndex)); - } - } - } - - private VIUSteamVRRenderModel m_renderModel; - - private void UpdateSteamVRModel() - { - if (ChangeProp.Set(ref m_currentDeviceIndex, GetCurrentDeviceIndex())) - { - if (VRModule.IsValidDeviceIndex(m_currentDeviceIndex)) - { - if (m_modelObj != null && m_renderModel == null) - { - CleanUpModelObj(); - } - - if (m_modelObj == null) + for (int i = 0, imax = m_creators.Length; i < imax; ++i) { - // find SteamVR_RenderModel in child object - for (int i = 0, imax = transform.childCount; i < imax; ++i) + if (m_creators[i].shouldActive) { - if ((m_renderModel = GetComponentInChildren()) != null) - { - m_modelObj = m_renderModel.gameObject; - break; - } - } - // create SteamVR_RenderModel in child object if not found - if (m_renderModel == null) - { - m_modelObj = new GameObject("Model"); - m_modelObj.transform.SetParent(transform, false); - m_renderModel = m_modelObj.AddComponent(); - } - - if (m_overrideShader != null) - { - m_renderModel.shaderOverride = m_overrideShader; - } - } - - m_modelObj.SetActive(true); - m_renderModel.SetDeviceIndex(m_currentDeviceIndex); - } - else - { - if (m_modelObj != null) - { - m_modelObj.SetActive(false); - } - } - } - } - -#if VIU_WAVEVR - private bool m_waveVRModelLoaded; - private wvr.WVR_DeviceType m_currentWaveVRHandType; - - private void UpdateWaveVRModel() - { - if (!ChangeProp.Set(ref m_currentDeviceIndex, GetCurrentDeviceIndex())) { return; } - - var hasValidModel = false; - var handType = default(wvr.WVR_DeviceType); - if (VRModule.IsValidDeviceIndex(m_currentDeviceIndex)) - { - if (m_currentDeviceIndex == VRModule.GetRightControllerDeviceIndex()) - { - hasValidModel = true; - handType = wvr.WVR_DeviceType.WVR_DeviceType_Controller_Right; - } - else if (m_currentDeviceIndex == VRModule.GetLeftControllerDeviceIndex()) - { - hasValidModel = true; - handType = wvr.WVR_DeviceType.WVR_DeviceType_Controller_Left; - } - } - - // NOTE: load renderModel only if it hasen't been loaded or user changes handType - if (hasValidModel) - { - if (m_modelObj != null) - { - if (!m_waveVRModelLoaded) - { - // Clean up model that created by other module - CleanUpModelObj(); - } - else if (m_currentWaveVRHandType != handType) - { - // Clean up model if changed to different hand - CleanUpModelObj(); - } - } - - m_currentWaveVRHandType = handType; - - if (!m_waveVRModelLoaded) - { - // Create WaveVR_ControllerLoader silently (to avoid Start and OnEnable) - var loaderGO = new GameObject("Loader"); - loaderGO.transform.SetParent(transform, false); - loaderGO.SetActive(false); - var loader = loaderGO.AddComponent(); - loader.enabled = false; - loader.TrackPosition = false; - loader.TrackRotation = false; - loader.showIndicator = false; - loaderGO.SetActive(true); - // Call onLoadController to create model (chould be Finch/Link/Pico/QIYIVR) - switch (handType) - { - case wvr.WVR_DeviceType.WVR_DeviceType_Controller_Right: - loader.WhichHand = WaveVR_ControllerLoader.ControllerHand.Controller_Right; - loaderGO.SendMessage("onLoadController", wvr.WVR_DeviceType.WVR_DeviceType_Controller_Right); - break; - case wvr.WVR_DeviceType.WVR_DeviceType_Controller_Left: - loader.WhichHand = WaveVR_ControllerLoader.ControllerHand.Controller_Left; - loaderGO.SendMessage("onLoadController", wvr.WVR_DeviceType.WVR_DeviceType_Controller_Left); + activeCreatorIndex = i; break; - } - - // Find transform that only contains controller model (include animator, exclude PoseTracker/Beam/UIPointer) - // and remove other unnecessary objects - var ctrllerActions = FindWaveVRControllerActionsObjInChildren(); - if (ctrllerActions != null) - { - ctrllerActions.transform.SetParent(transform, false); - ctrllerActions.transform.SetAsFirstSibling(); - for (int i = transform.childCount - 1; i >= 1; --i) - { - Destroy(transform.GetChild(i).gameObject); } - ctrllerActions.gameObject.SetActive(true); - m_modelObj = ctrllerActions.gameObject; } - else - { - Debug.LogWarning("FindWaveVRControllerActionsObjInChildren failed"); - for (int i = transform.childCount - 1; i >= 0; --i) - { - Destroy(transform.GetChild(i).gameObject); - } - } - - m_waveVRModelLoaded = true; } else { - if (m_modelObj != null) - { - m_modelObj.SetActive(true); - } - } - } - else - { - if (m_modelObj != null) - { - m_modelObj.SetActive(false); + activeCreatorIndex = m_defaultCreatorIndex; } } - } - // FIXME: This is for finding Controller model with animator, is reliable? - private Transform FindWaveVRControllerActionsObjInChildren() - { - var nodes = new List(); - nodes.Add(transform); - for (int i = 0; i < nodes.Count; ++i) + if (m_activeCreatorIndex != activeCreatorIndex) { - var parent = nodes[i]; - for (int j = 0, jmax = parent.childCount; j < jmax; ++j) + // clean up model created from previous active creator + if (m_activeCreatorIndex >= 0) { - var child = parent.GetChild(j); - nodes.Add(child); - if (child.GetComponent() != null) { continue; } - if (child.GetComponent() != null) { continue; } - if (child.GetComponent() != null) { continue; } - if (child.GetComponent() != null) { continue; } - return child; + m_creators[activeCreatorIndex].CleanUpRenderModel(); } + m_activeCreatorIndex = activeCreatorIndex; } - return null; - } -#endif - - private void UpdateDefaultModel() - { - if (ChangeProp.Set(ref m_currentDeviceIndex, GetCurrentDeviceIndex())) + if (m_activeCreatorIndex >= 0) { - if (VRModule.IsValidDeviceIndex(m_currentDeviceIndex)) - { - if (ChangeProp.Set(ref m_currentLoadedStaticModel, VRModule.GetCurrentDeviceState(m_currentDeviceIndex).deviceModel)) - { - ReloadedStaticModel(m_currentLoadedStaticModel); - } - else - { - if (m_modelObj != null) - { - m_modelObj.SetActive(true); - } - } - } - else - { - if (m_modelObj != null) - { - m_modelObj.SetActive(false); - } - } - } - } - - private void ReloadedStaticModel(VRModuleDeviceModel model) - { - CleanUpModelObj(); - - var prefab = Resources.Load("Models/VIUModel" + model.ToString()); - if (prefab != null) - { - m_modelObj = Instantiate(prefab); - m_modelObj.transform.SetParent(transform, false); - m_modelObj.gameObject.name = "VIUModel" + model.ToString(); - - if (m_overrideShader != null) - { - var renderer = m_modelObj.GetComponentInChildren(); - if (renderer != null) - { - renderer.material.shader = m_overrideShader; - } - } - } - } - - public void CleanUpModelObj() - { - if (m_modelObj != null) - { -#if VIU_STEAMVR - m_renderModel = null; -#endif -#if VIU_WAVEVR - m_waveVRModelLoaded = false; -#endif - Destroy(m_modelObj); - m_modelObj = null; + m_creators[activeCreatorIndex].UpdateRenderModel(); } } } diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Misc/VRCameraHook.cs b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Misc/VRCameraHook.cs index e4754f80..879d4c61 100644 --- a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Misc/VRCameraHook.cs +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Misc/VRCameraHook.cs @@ -1,10 +1,11 @@ //========= Copyright 2016-2019, HTC Corporation. All rights reserved. =========== using HTC.UnityPlugin.VRModuleManagement; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; using UnityEngine; -#if VIU_STEAMVR_2_0_0_OR_NEWER -using Valve.VR; -#endif namespace HTC.UnityPlugin.Vive { @@ -14,8 +15,55 @@ namespace HTC.UnityPlugin.Vive [AddComponentMenu("HTC/VIU/Hooks/VR Camera Hook", 10)] public class VRCameraHook : MonoBehaviour { + [AttributeUsage(AttributeTargets.Class)] + public class CreatorPriorityAttirbute : Attribute + { + public int priority { get; set; } + public CreatorPriorityAttirbute(int priority = 0) { this.priority = priority; } + } + + public abstract class CameraCreator + { + public abstract bool shouldActive { get; } + public abstract void CreateCamera(VRCameraHook hook); + } + + private static readonly Type[] s_creatorTypes; + private CameraCreator[] m_creators; + + static VRCameraHook() + { + try + { + var creatorTypes = new List(); + foreach (var type in Assembly.GetAssembly(typeof(CameraCreator)).GetTypes().Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(CameraCreator)))) + { + creatorTypes.Add(type); + } + s_creatorTypes = creatorTypes.OrderBy(t => + { + foreach (var at in t.GetCustomAttributes(typeof(CreatorPriorityAttirbute), true)) + { + return ((CreatorPriorityAttirbute)at).priority; + } + return 0; + }).ToArray(); + } + catch (Exception e) + { + s_creatorTypes = new Type[0]; + Debug.LogError(e); + } + } + private void Awake() { + m_creators = new CameraCreator[s_creatorTypes.Length]; + for (int i = s_creatorTypes.Length - 1; i >= 0; --i) + { + m_creators[i] = (CameraCreator)Activator.CreateInstance(s_creatorTypes[i]); + } + if (VRModule.activeModule == VRModuleActiveEnum.Uninitialized) { VRModule.onActiveModuleChanged += OnModuleActivated; @@ -28,39 +76,13 @@ private void Awake() private void OnModuleActivated(VRModuleActiveEnum activatedModule) { - switch (activatedModule) + foreach (var creator in m_creators) { -#if VIU_STEAMVR - case VRModuleActiveEnum.SteamVR: - if (GetComponent() == null) - { - // FIXME: SteamVR_Camera 2.0 is removed - gameObject.AddComponent(); - } - break; -#endif -#if VIU_WAVEVR - case VRModuleActiveEnum.WaveVR: - if (GetComponent() == null) - { - gameObject.AddComponent(); - } - if (GetComponent() == null) - { - gameObject.AddComponent().viveRole.SetEx(DeviceRole.Hmd); - } - if (GetComponentsInChildren().Length > 1) - { - var listener = GetComponent(); - if (listener != null) - { - Destroy(listener); - } - } - break; -#endif - default: + if (creator.shouldActive) + { + creator.CreateCamera(this); break; + } } if (activatedModule != VRModuleActiveEnum.Uninitialized) diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/VIUVersion.cs b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/VIUVersion.cs index 888ada9a..f9a4190e 100644 --- a/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/VIUVersion.cs +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/VIUVersion.cs @@ -6,6 +6,6 @@ namespace HTC.UnityPlugin.Vive { public static class VIUVersion { - public static readonly Version current = new Version("1.10.2.0"); + public static readonly Version current = new Version("1.10.3.0"); } } \ No newline at end of file