// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) VRMADA, All rights reserved. // // -------------------------------------------------------------------------------------------------------------------- using UltimateXR.Core; using UnityEditor; using UnityEngine; #if ULTIMATEXR_USE_STEAMVR_SDK using Valve.VR; #endif namespace UltimateXR.Editor.Sdks.InputTracking { #if ULTIMATEXR_USE_STEAMVR_SDK #endif /// /// SDK Locator for the SteamVR SDK. /// public sealed class UxrSdkLocatorSteamVR : UxrSdkLocator { #region Public Overrides UxrSdkLocator /// public override SupportType Support => SupportType.InputTracking; /// public override string Name => UxrConstants.SdkSteamVR; /// public override string MinimumUnityVersion => "2021.1"; /// public override string[] AvailableSymbols { get { if (CurrentState == State.Available) { if (CurrentVersion == 0) { return new[] { "ULTIMATEXR_USE_STEAMVR_SDK" }; } } return new string[0]; } } /// public override string[] AllSymbols { get { return new[] { "ULTIMATEXR_USE_STEAMVR_SDK" }; } } /// public override bool CanBeUpdated => true; /// public override void TryLocate() { #if UNITY_5_6_OR_NEWER if (EditorUserBuildSettings.activeBuildTarget is BuildTarget.StandaloneWindows or BuildTarget.StandaloneWindows64) { CurrentState = State.NotInstalled; if (IsTypeInAssemblies("Valve.VR.SteamVR_Events")) { CurrentVersion = 0; CurrentState = State.Available; } } else { CurrentState = State.CurrentTargetNotSupported; } #else CurrentState = State.NeedsHigherUnityVersion #endif } /// public override void TryGet() { Application.OpenURL("https://assetstore.unity.com/packages/templates/systems/steamvr-plugin-32647"); } /// public override void TryUpdate() { TryGet(); } #endregion #region Public Methods /// /// Auto-registers the locator each time Unity is launched or the project folder is updated. /// [InitializeOnLoadMethod] public static void RegisterLocator() { UxrSdkManager.RegisterLocator(new UxrSdkLocatorSteamVR()); } #endregion #region Unity /// public override void OnInspectorGUI() { #if ULTIMATEXR_USE_STEAMVR_SDK if (SteamVR_Input.DoesActionsFileExist()) { if (SteamVR_Input.actionFile != null && SteamVR_Input.actionFile.action_sets != null) { bool needsSetup = SteamVRActionsExporter.NeedsActionsSetup(); if (!needsSetup) { EditorGUILayout.LabelField("Found UltimateXR actions. Input is available."); } else { EditorGUILayout.HelpBox("UltimateXR actions need to be set up to use SteamVR input", MessageType.Warning); } bool guiEnabled = GUI.enabled; GUI.enabled = guiEnabled && needsSetup; if (UxrEditorUtils.CenteredButton(new GUIContent("Create Actions"))) { SteamVRActionsExporter.TrySetupActions(); } GUI.enabled = guiEnabled && !needsSetup; if (UxrEditorUtils.CenteredButton(new GUIContent("Delete Actions"))) { SteamVRActionsExporter.TryRemoveActions(); } GUI.enabled = guiEnabled; } else { if (SteamVR_Input.actionFile == null) { SteamVR_Input.InitializeFile(false, false); } } } else { EditorGUILayout.HelpBox("SteamVR actions have not been set up and need to be created first.\nNavigate to Unity's top menu Window->SteamVR Input to generate the actions. When finished continue setup here.", MessageType.Warning); } #endif } #endregion #region Private Methods /// /// Allows to remove dependencies from the project in case the user removed SDK folders manually. /// [MenuItem(UxrConstants.Editor.MenuPathSdksInputTracking + "Remove Symbols for SteamVR", priority = UxrConstants.Editor.PriorityMenuPathSdksInputTracking)] private static void RemoveSymbols() { UxrSdkManager.RemoveSymbols(new UxrSdkLocatorSteamVR()); } #endregion } }