diff --git a/Assets/SteamVR/Input/SteamVR_ActionSet_Manager.cs b/Assets/SteamVR/Input/SteamVR_ActionSet_Manager.cs index 900688a8..96a9087b 100644 --- a/Assets/SteamVR/Input/SteamVR_ActionSet_Manager.cs +++ b/Assets/SteamVR/Input/SteamVR_ActionSet_Manager.cs @@ -74,12 +74,20 @@ public static void SetChanged() changed = true; } + private static Dictionary pool; + private static VRActiveActionSet_t[] activeActionSetsArray; + private static void UpdateActionSetsArray() { - List activeActionSetsList = new List(); - + var activeActionSetsCount = 0; SteamVR_Input_Sources[] sources = SteamVR_Input_Source.GetAllSources(); + if (pool == null) + { + pool = new Dictionary(); + activeActionSetsArray = new VRActiveActionSet_t[SteamVR_Input.actionSets.Length * sources.Length]; + } + for (int actionSetIndex = 0; actionSetIndex < SteamVR_Input.actionSets.Length; actionSetIndex++) { SteamVR_ActionSet set = SteamVR_Input.actionSets[actionSetIndex]; @@ -95,20 +103,44 @@ private static void UpdateActionSetsArray() activeSet.nPriority = set.ReadRawSetPriority(source); activeSet.ulRestrictedToDevice = SteamVR_Input_Source.GetHandle(source); - int insertionIndex = 0; - for (insertionIndex = 0; insertionIndex < activeActionSetsList.Count; insertionIndex++) + int insertionIndex; + for (insertionIndex = 0; insertionIndex < activeActionSetsCount; insertionIndex++) { - if (activeActionSetsList[insertionIndex].nPriority > activeSet.nPriority) + if (activeActionSetsArray[insertionIndex].nPriority > activeSet.nPriority) break; } - activeActionSetsList.Insert(insertionIndex, activeSet); + + for (int i = activeActionSetsCount; i > insertionIndex; i--) + { + activeActionSetsArray[i] = activeActionSetsArray[i - 1]; + } + activeActionSetsArray[insertionIndex] = activeSet; + activeActionSetsCount++; } } } + if (rawActiveActionSetArray != null && rawActiveActionSetArray.Length != activeActionSetsCount) + { + pool[rawActiveActionSetArray.Length] = rawActiveActionSetArray; + rawActiveActionSetArray = null; + } + + if (rawActiveActionSetArray == null) + { + if (!pool.ContainsKey(activeActionSetsCount)) + { + rawActiveActionSetArray = new VRActiveActionSet_t[activeActionSetsCount]; + pool[activeActionSetsCount] = rawActiveActionSetArray; + } + else + rawActiveActionSetArray = pool[activeActionSetsCount]; + } + changed = false; - rawActiveActionSetArray = activeActionSetsList.ToArray(); + for (int i = 0; i < activeActionSetsCount; i++) + rawActiveActionSetArray[i] = activeActionSetsArray[i]; if (Application.isEditor || updateDebugTextInBuilds) UpdateDebugText(); diff --git a/Assets/SteamVR/Scripts/SteamVR.cs b/Assets/SteamVR/Scripts/SteamVR.cs index f80dc407..b6d5e7bd 100644 --- a/Assets/SteamVR/Scripts/SteamVR.cs +++ b/Assets/SteamVR/Scripts/SteamVR.cs @@ -26,12 +26,14 @@ public class SteamVR : System.IDisposable // Set this to false to keep from auto-initializing when calling SteamVR.instance. private static bool _enabled = true; + private static readonly string[] SupportedDevices = XRSettings.supportedDevices; + public static bool enabled { get { #if UNITY_2020_1_OR_NEWER || OPENVR_XR_API - if (XRSettings.supportedDevices.Length == 0) + if (SupportedDevices.Length == 0) enabled = false; #else if (!XRSettings.enabled) @@ -127,11 +129,11 @@ private static void ReportGeneralErrors() if (XRSettings.enabled == false) errorLog += "VR may be disabled in player settings. Go to player settings in the editor and check the 'Virtual Reality Supported' checkbox'. "; - if (XRSettings.supportedDevices != null && XRSettings.supportedDevices.Length > 0) + if (SupportedDevices != null && SupportedDevices.Length > 0) { - if (XRSettings.supportedDevices.Contains("OpenVR") == false) + if (SupportedDevices.Contains("OpenVR") == false) errorLog += "OpenVR is not in your list of supported virtual reality SDKs. Add it to the list in player settings. "; - else if (XRSettings.supportedDevices.First().Contains("OpenVR") == false) + else if (SupportedDevices.First().Contains("OpenVR") == false) errorLog += "OpenVR is not first in your list of supported virtual reality SDKs. This is okay, but if you have an Oculus device plugged in, and Oculus above OpenVR in this list, it will try and use the Oculus SDK instead of OpenVR. "; } else