Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

774 lines
22 KiB

  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: Displays text and button hints on the controllers
  4. //
  5. //=============================================================================
  6. using UnityEngine;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using UnityEngine.UI;
  10. namespace Valve.VR.InteractionSystem
  11. {
  12. //-------------------------------------------------------------------------
  13. public class ControllerButtonHints : MonoBehaviour
  14. {
  15. public Material controllerMaterial;
  16. public Color flashColor = new Color( 1.0f, 0.557f, 0.0f );
  17. public GameObject textHintPrefab;
  18. [Header( "Debug" )]
  19. public bool debugHints = false;
  20. private SteamVR_RenderModel renderModel;
  21. private Player player;
  22. private List<MeshRenderer> renderers = new List<MeshRenderer>();
  23. private List<MeshRenderer> flashingRenderers = new List<MeshRenderer>();
  24. private float startTime;
  25. private float tickCount;
  26. private enum OffsetType
  27. {
  28. Up,
  29. Right,
  30. Forward,
  31. Back
  32. }
  33. //Info for each of the buttons
  34. private class ButtonHintInfo
  35. {
  36. public string componentName;
  37. public List<MeshRenderer> renderers;
  38. public Transform localTransform;
  39. //Text hint
  40. public GameObject textHintObject;
  41. public Transform textStartAnchor;
  42. public Transform textEndAnchor;
  43. public Vector3 textEndOffsetDir;
  44. public Transform canvasOffset;
  45. public Text text;
  46. public TextMesh textMesh;
  47. public Canvas textCanvas;
  48. public LineRenderer line;
  49. public float distanceFromCenter;
  50. public bool textHintActive = false;
  51. }
  52. private Dictionary<EVRButtonId, ButtonHintInfo> buttonHintInfos;
  53. private Transform textHintParent;
  54. private List<KeyValuePair<string, ulong>> componentButtonMasks = new List<KeyValuePair<string, ulong>>();
  55. private int colorID;
  56. public bool initialized { get; private set; }
  57. private Vector3 centerPosition = Vector3.zero;
  58. SteamVR_Events.Action renderModelLoadedAction;
  59. //-------------------------------------------------
  60. void Awake()
  61. {
  62. renderModelLoadedAction = SteamVR_Events.RenderModelLoadedAction( OnRenderModelLoaded );
  63. colorID = Shader.PropertyToID( "_Color" );
  64. }
  65. //-------------------------------------------------
  66. void Start()
  67. {
  68. player = Player.instance;
  69. }
  70. //-------------------------------------------------
  71. private void HintDebugLog( string msg )
  72. {
  73. if ( debugHints )
  74. {
  75. Debug.Log( "Hints: " + msg );
  76. }
  77. }
  78. //-------------------------------------------------
  79. void OnEnable()
  80. {
  81. renderModelLoadedAction.enabled = true;
  82. }
  83. //-------------------------------------------------
  84. void OnDisable()
  85. {
  86. renderModelLoadedAction.enabled = false;
  87. Clear();
  88. }
  89. //-------------------------------------------------
  90. private void OnParentHandInputFocusLost()
  91. {
  92. //Hide all the hints when the controller is no longer the primary attached object
  93. HideAllButtonHints();
  94. HideAllText();
  95. }
  96. //-------------------------------------------------
  97. // Gets called when the hand has been initialized and a render model has been set
  98. //-------------------------------------------------
  99. private void OnHandInitialized( int deviceIndex )
  100. {
  101. //Create a new render model for the controller hints
  102. renderModel = new GameObject( "SteamVR_RenderModel" ).AddComponent<SteamVR_RenderModel>();
  103. renderModel.transform.parent = transform;
  104. renderModel.transform.localPosition = Vector3.zero;
  105. renderModel.transform.localRotation = Quaternion.identity;
  106. renderModel.transform.localScale = Vector3.one;
  107. renderModel.SetDeviceIndex( deviceIndex );
  108. if ( !initialized )
  109. {
  110. //The controller hint render model needs to be active to get accurate transforms for all the individual components
  111. renderModel.gameObject.SetActive( true );
  112. }
  113. }
  114. //-------------------------------------------------
  115. void OnRenderModelLoaded( SteamVR_RenderModel renderModel, bool succeess )
  116. {
  117. //Only initialize when the render model for the controller hints has been loaded
  118. if ( renderModel == this.renderModel )
  119. {
  120. textHintParent = new GameObject( "Text Hints" ).transform;
  121. textHintParent.SetParent( this.transform );
  122. textHintParent.localPosition = Vector3.zero;
  123. textHintParent.localRotation = Quaternion.identity;
  124. textHintParent.localScale = Vector3.one;
  125. //Get the button mask for each component of the render model
  126. using ( var holder = new SteamVR_RenderModel.RenderModelInterfaceHolder() )
  127. {
  128. var renderModels = holder.instance;
  129. if ( renderModels != null )
  130. {
  131. string renderModelDebug = "Components for render model " + renderModel.index;
  132. foreach ( Transform child in renderModel.transform )
  133. {
  134. ulong buttonMask = renderModels.GetComponentButtonMask( renderModel.renderModelName, child.name );
  135. componentButtonMasks.Add( new KeyValuePair<string, ulong>( child.name, buttonMask ) );
  136. renderModelDebug += "\n\t" + child.name + ": " + buttonMask;
  137. }
  138. //Uncomment to show the button mask for each component of the render model
  139. HintDebugLog( renderModelDebug );
  140. }
  141. }
  142. buttonHintInfos = new Dictionary<EVRButtonId, ButtonHintInfo>();
  143. CreateAndAddButtonInfo( EVRButtonId.k_EButton_SteamVR_Trigger );
  144. CreateAndAddButtonInfo( EVRButtonId.k_EButton_ApplicationMenu );
  145. CreateAndAddButtonInfo( EVRButtonId.k_EButton_System );
  146. CreateAndAddButtonInfo( EVRButtonId.k_EButton_Grip );
  147. CreateAndAddButtonInfo( EVRButtonId.k_EButton_SteamVR_Touchpad );
  148. CreateAndAddButtonInfo( EVRButtonId.k_EButton_A );
  149. ComputeTextEndTransforms();
  150. initialized = true;
  151. //Set the controller hints render model to not active
  152. renderModel.gameObject.SetActive( false );
  153. }
  154. }
  155. //-------------------------------------------------
  156. private void CreateAndAddButtonInfo( EVRButtonId buttonID )
  157. {
  158. Transform buttonTransform = null;
  159. List<MeshRenderer> buttonRenderers = new List<MeshRenderer>();
  160. string buttonDebug = "Looking for button: " + buttonID;
  161. EVRButtonId searchButtonID = buttonID;
  162. if ( buttonID == EVRButtonId.k_EButton_Grip && SteamVR.instance.hmd_TrackingSystemName.ToLowerInvariant().Contains( "oculus" ) )
  163. {
  164. searchButtonID = EVRButtonId.k_EButton_Axis2;
  165. }
  166. ulong buttonMaskForID = ( 1ul << (int)searchButtonID );
  167. foreach ( KeyValuePair<string, ulong> componentButtonMask in componentButtonMasks )
  168. {
  169. if ( ( componentButtonMask.Value & buttonMaskForID ) == buttonMaskForID )
  170. {
  171. buttonDebug += "\nFound component: " + componentButtonMask.Key + " " + componentButtonMask.Value;
  172. Transform componentTransform = renderModel.FindComponent( componentButtonMask.Key );
  173. buttonTransform = componentTransform;
  174. buttonDebug += "\nFound componentTransform: " + componentTransform + " buttonTransform: " + buttonTransform;
  175. buttonRenderers.AddRange( componentTransform.GetComponentsInChildren<MeshRenderer>() );
  176. }
  177. }
  178. buttonDebug += "\nFound " + buttonRenderers.Count + " renderers for " + buttonID;
  179. foreach ( MeshRenderer renderer in buttonRenderers )
  180. {
  181. buttonDebug += "\n\t" + renderer.name;
  182. }
  183. HintDebugLog( buttonDebug );
  184. if ( buttonTransform == null )
  185. {
  186. HintDebugLog( "Couldn't find buttonTransform for " + buttonID );
  187. return;
  188. }
  189. ButtonHintInfo hintInfo = new ButtonHintInfo();
  190. buttonHintInfos.Add( buttonID, hintInfo );
  191. hintInfo.componentName = buttonTransform.name;
  192. hintInfo.renderers = buttonRenderers;
  193. //Get the local transform for the button
  194. hintInfo.localTransform = buttonTransform.Find( SteamVR_RenderModel.k_localTransformName );
  195. OffsetType offsetType = OffsetType.Right;
  196. switch ( buttonID )
  197. {
  198. case EVRButtonId.k_EButton_SteamVR_Trigger:
  199. {
  200. offsetType = OffsetType.Right;
  201. }
  202. break;
  203. case EVRButtonId.k_EButton_ApplicationMenu:
  204. {
  205. offsetType = OffsetType.Right;
  206. }
  207. break;
  208. case EVRButtonId.k_EButton_System:
  209. {
  210. offsetType = OffsetType.Right;
  211. }
  212. break;
  213. case Valve.VR.EVRButtonId.k_EButton_Grip:
  214. {
  215. offsetType = OffsetType.Forward;
  216. }
  217. break;
  218. case Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad:
  219. {
  220. offsetType = OffsetType.Up;
  221. }
  222. break;
  223. }
  224. //Offset for the text end transform
  225. switch ( offsetType )
  226. {
  227. case OffsetType.Forward:
  228. hintInfo.textEndOffsetDir = hintInfo.localTransform.forward;
  229. break;
  230. case OffsetType.Back:
  231. hintInfo.textEndOffsetDir = -hintInfo.localTransform.forward;
  232. break;
  233. case OffsetType.Right:
  234. hintInfo.textEndOffsetDir = hintInfo.localTransform.right;
  235. break;
  236. case OffsetType.Up:
  237. hintInfo.textEndOffsetDir = hintInfo.localTransform.up;
  238. break;
  239. }
  240. //Create the text hint object
  241. Vector3 hintStartPos = hintInfo.localTransform.position + ( hintInfo.localTransform.forward * 0.01f );
  242. hintInfo.textHintObject = GameObject.Instantiate( textHintPrefab, hintStartPos, Quaternion.identity ) as GameObject;
  243. hintInfo.textHintObject.name = "Hint_" + hintInfo.componentName + "_Start";
  244. hintInfo.textHintObject.transform.SetParent( textHintParent );
  245. hintInfo.textHintObject.layer = gameObject.layer;
  246. hintInfo.textHintObject.tag = gameObject.tag;
  247. //Get all the relevant child objects
  248. hintInfo.textStartAnchor = hintInfo.textHintObject.transform.Find( "Start" );
  249. hintInfo.textEndAnchor = hintInfo.textHintObject.transform.Find( "End" );
  250. hintInfo.canvasOffset = hintInfo.textHintObject.transform.Find( "CanvasOffset" );
  251. hintInfo.line = hintInfo.textHintObject.transform.Find( "Line" ).GetComponent<LineRenderer>();
  252. hintInfo.textCanvas = hintInfo.textHintObject.GetComponentInChildren<Canvas>();
  253. hintInfo.text = hintInfo.textCanvas.GetComponentInChildren<Text>();
  254. hintInfo.textMesh = hintInfo.textCanvas.GetComponentInChildren<TextMesh>();
  255. hintInfo.textHintObject.SetActive( false );
  256. hintInfo.textStartAnchor.position = hintStartPos;
  257. if ( hintInfo.text != null )
  258. {
  259. hintInfo.text.text = hintInfo.componentName;
  260. }
  261. if ( hintInfo.textMesh != null )
  262. {
  263. hintInfo.textMesh.text = hintInfo.componentName;
  264. }
  265. centerPosition += hintInfo.textStartAnchor.position;
  266. // Scale hint components to match player size
  267. hintInfo.textCanvas.transform.localScale = Vector3.Scale( hintInfo.textCanvas.transform.localScale, player.transform.localScale );
  268. hintInfo.textStartAnchor.transform.localScale = Vector3.Scale( hintInfo.textStartAnchor.transform.localScale, player.transform.localScale );
  269. hintInfo.textEndAnchor.transform.localScale = Vector3.Scale( hintInfo.textEndAnchor.transform.localScale, player.transform.localScale );
  270. hintInfo.line.transform.localScale = Vector3.Scale( hintInfo.line.transform.localScale, player.transform.localScale );
  271. }
  272. //-------------------------------------------------
  273. private void ComputeTextEndTransforms()
  274. {
  275. //This is done as a separate step after all the ButtonHintInfos have been initialized
  276. //to make the text hints fan out appropriately based on the button's position on the controller.
  277. centerPosition /= buttonHintInfos.Count;
  278. float maxDistanceFromCenter = 0.0f;
  279. foreach ( var hintInfo in buttonHintInfos )
  280. {
  281. hintInfo.Value.distanceFromCenter = Vector3.Distance( hintInfo.Value.textStartAnchor.position, centerPosition );
  282. if ( hintInfo.Value.distanceFromCenter > maxDistanceFromCenter )
  283. {
  284. maxDistanceFromCenter = hintInfo.Value.distanceFromCenter;
  285. }
  286. }
  287. foreach ( var hintInfo in buttonHintInfos )
  288. {
  289. Vector3 centerToButton = hintInfo.Value.textStartAnchor.position - centerPosition;
  290. centerToButton.Normalize();
  291. centerToButton = Vector3.Project( centerToButton, renderModel.transform.forward );
  292. //Spread out the text end positions based on the distance from the center
  293. float t = hintInfo.Value.distanceFromCenter / maxDistanceFromCenter;
  294. float scale = hintInfo.Value.distanceFromCenter * Mathf.Pow( 2, 10 * ( t - 1.0f ) ) * 20.0f;
  295. //Flip the direction of the end pos based on which hand this is
  296. float endPosOffset = 0.1f;
  297. Vector3 hintEndPos = hintInfo.Value.textStartAnchor.position + ( hintInfo.Value.textEndOffsetDir * endPosOffset ) + ( centerToButton * scale * 0.1f );
  298. hintInfo.Value.textEndAnchor.position = hintEndPos;
  299. hintInfo.Value.canvasOffset.position = hintEndPos;
  300. hintInfo.Value.canvasOffset.localRotation = Quaternion.identity;
  301. }
  302. }
  303. //-------------------------------------------------
  304. private void ShowButtonHint( params EVRButtonId[] buttons )
  305. {
  306. renderModel.gameObject.SetActive( true );
  307. renderModel.GetComponentsInChildren<MeshRenderer>( renderers );
  308. for ( int i = 0; i < renderers.Count; i++ )
  309. {
  310. Texture mainTexture = renderers[i].material.mainTexture;
  311. renderers[i].sharedMaterial = controllerMaterial;
  312. renderers[i].material.mainTexture = mainTexture;
  313. // This is to poke unity into setting the correct render queue for the model
  314. renderers[i].material.renderQueue = controllerMaterial.shader.renderQueue;
  315. }
  316. for ( int i = 0; i < buttons.Length; i++ )
  317. {
  318. if ( buttonHintInfos.ContainsKey( buttons[i] ) )
  319. {
  320. ButtonHintInfo hintInfo = buttonHintInfos[buttons[i]];
  321. foreach ( MeshRenderer renderer in hintInfo.renderers )
  322. {
  323. if ( !flashingRenderers.Contains( renderer ) )
  324. {
  325. flashingRenderers.Add( renderer );
  326. }
  327. }
  328. }
  329. }
  330. startTime = Time.realtimeSinceStartup;
  331. tickCount = 0.0f;
  332. }
  333. //-------------------------------------------------
  334. private void HideAllButtonHints()
  335. {
  336. Clear();
  337. renderModel.gameObject.SetActive( false );
  338. }
  339. //-------------------------------------------------
  340. private void HideButtonHint( params EVRButtonId[] buttons )
  341. {
  342. Color baseColor = controllerMaterial.GetColor( colorID );
  343. for ( int i = 0; i < buttons.Length; i++ )
  344. {
  345. if ( buttonHintInfos.ContainsKey( buttons[i] ) )
  346. {
  347. ButtonHintInfo hintInfo = buttonHintInfos[buttons[i]];
  348. foreach ( MeshRenderer renderer in hintInfo.renderers )
  349. {
  350. renderer.material.color = baseColor;
  351. flashingRenderers.Remove( renderer );
  352. }
  353. }
  354. }
  355. if ( flashingRenderers.Count == 0 )
  356. {
  357. renderModel.gameObject.SetActive( false );
  358. }
  359. }
  360. //-------------------------------------------------
  361. private bool IsButtonHintActive( EVRButtonId button )
  362. {
  363. if ( buttonHintInfos.ContainsKey( button ) )
  364. {
  365. ButtonHintInfo hintInfo = buttonHintInfos[button];
  366. foreach ( MeshRenderer buttonRenderer in hintInfo.renderers )
  367. {
  368. if ( flashingRenderers.Contains( buttonRenderer ) )
  369. {
  370. return true;
  371. }
  372. }
  373. }
  374. return false;
  375. }
  376. //-------------------------------------------------
  377. private IEnumerator TestButtonHints()
  378. {
  379. while ( true )
  380. {
  381. ShowButtonHint( EVRButtonId.k_EButton_SteamVR_Trigger );
  382. yield return new WaitForSeconds( 1.0f );
  383. ShowButtonHint( EVRButtonId.k_EButton_ApplicationMenu );
  384. yield return new WaitForSeconds( 1.0f );
  385. ShowButtonHint( EVRButtonId.k_EButton_System );
  386. yield return new WaitForSeconds( 1.0f );
  387. ShowButtonHint( EVRButtonId.k_EButton_Grip );
  388. yield return new WaitForSeconds( 1.0f );
  389. ShowButtonHint( EVRButtonId.k_EButton_SteamVR_Touchpad );
  390. yield return new WaitForSeconds( 1.0f );
  391. }
  392. }
  393. //-------------------------------------------------
  394. private IEnumerator TestTextHints()
  395. {
  396. while ( true )
  397. {
  398. ShowText( EVRButtonId.k_EButton_SteamVR_Trigger, "Trigger" );
  399. yield return new WaitForSeconds( 3.0f );
  400. ShowText( EVRButtonId.k_EButton_ApplicationMenu, "Application" );
  401. yield return new WaitForSeconds( 3.0f );
  402. ShowText( EVRButtonId.k_EButton_System, "System" );
  403. yield return new WaitForSeconds( 3.0f );
  404. ShowText( EVRButtonId.k_EButton_Grip, "Grip" );
  405. yield return new WaitForSeconds( 3.0f );
  406. ShowText( EVRButtonId.k_EButton_SteamVR_Touchpad, "Touchpad" );
  407. yield return new WaitForSeconds( 3.0f );
  408. HideAllText();
  409. yield return new WaitForSeconds( 3.0f );
  410. }
  411. }
  412. //-------------------------------------------------
  413. void Update()
  414. {
  415. if ( renderModel != null && renderModel.gameObject.activeInHierarchy && flashingRenderers.Count > 0 )
  416. {
  417. Color baseColor = controllerMaterial.GetColor( colorID );
  418. float flash = ( Time.realtimeSinceStartup - startTime ) * Mathf.PI * 2.0f;
  419. flash = Mathf.Cos( flash );
  420. flash = Util.RemapNumberClamped( flash, -1.0f, 1.0f, 0.0f, 1.0f );
  421. float ticks = ( Time.realtimeSinceStartup - startTime );
  422. if ( ticks - tickCount > 1.0f )
  423. {
  424. tickCount += 1.0f;
  425. SteamVR_Controller.Device device = SteamVR_Controller.Input( (int)renderModel.index );
  426. if ( device != null )
  427. {
  428. device.TriggerHapticPulse();
  429. }
  430. }
  431. for ( int i = 0; i < flashingRenderers.Count; i++ )
  432. {
  433. Renderer r = flashingRenderers[i];
  434. r.material.SetColor( colorID, Color.Lerp( baseColor, flashColor, flash ) );
  435. }
  436. if ( initialized )
  437. {
  438. foreach ( var hintInfo in buttonHintInfos )
  439. {
  440. if ( hintInfo.Value.textHintActive )
  441. {
  442. UpdateTextHint( hintInfo.Value );
  443. }
  444. }
  445. }
  446. }
  447. }
  448. //-------------------------------------------------
  449. private void UpdateTextHint( ButtonHintInfo hintInfo )
  450. {
  451. Transform playerTransform = player.hmdTransform;
  452. Vector3 vDir = playerTransform.position - hintInfo.canvasOffset.position;
  453. Quaternion standardLookat = Quaternion.LookRotation( vDir, Vector3.up );
  454. Quaternion upsideDownLookat = Quaternion.LookRotation( vDir, playerTransform.up );
  455. float flInterp;
  456. if ( playerTransform.forward.y > 0.0f )
  457. {
  458. flInterp = Util.RemapNumberClamped( playerTransform.forward.y, 0.6f, 0.4f, 1.0f, 0.0f );
  459. }
  460. else
  461. {
  462. flInterp = Util.RemapNumberClamped( playerTransform.forward.y, -0.8f, -0.6f, 1.0f, 0.0f );
  463. }
  464. hintInfo.canvasOffset.rotation = Quaternion.Slerp( standardLookat, upsideDownLookat, flInterp );
  465. Transform lineTransform = hintInfo.line.transform;
  466. hintInfo.line.useWorldSpace = false;
  467. hintInfo.line.SetPosition( 0, lineTransform.InverseTransformPoint( hintInfo.textStartAnchor.position ) );
  468. hintInfo.line.SetPosition( 1, lineTransform.InverseTransformPoint( hintInfo.textEndAnchor.position ) );
  469. }
  470. //-------------------------------------------------
  471. private void Clear()
  472. {
  473. renderers.Clear();
  474. flashingRenderers.Clear();
  475. }
  476. //-------------------------------------------------
  477. private void ShowText( EVRButtonId button, string text, bool highlightButton = true )
  478. {
  479. if ( buttonHintInfos.ContainsKey( button ) )
  480. {
  481. ButtonHintInfo hintInfo = buttonHintInfos[button];
  482. hintInfo.textHintObject.SetActive( true );
  483. hintInfo.textHintActive = true;
  484. if ( hintInfo.text != null )
  485. {
  486. hintInfo.text.text = text;
  487. }
  488. if ( hintInfo.textMesh != null )
  489. {
  490. hintInfo.textMesh.text = text;
  491. }
  492. UpdateTextHint( hintInfo );
  493. if ( highlightButton )
  494. {
  495. ShowButtonHint( button );
  496. }
  497. renderModel.gameObject.SetActive( true );
  498. }
  499. }
  500. //-------------------------------------------------
  501. private void HideText( EVRButtonId button )
  502. {
  503. if ( buttonHintInfos.ContainsKey( button ) )
  504. {
  505. ButtonHintInfo hintInfo = buttonHintInfos[button];
  506. hintInfo.textHintObject.SetActive( false );
  507. hintInfo.textHintActive = false;
  508. HideButtonHint( button );
  509. }
  510. }
  511. //-------------------------------------------------
  512. private void HideAllText()
  513. {
  514. foreach ( var hintInfo in buttonHintInfos )
  515. {
  516. hintInfo.Value.textHintObject.SetActive( false );
  517. hintInfo.Value.textHintActive = false;
  518. }
  519. HideAllButtonHints();
  520. }
  521. //-------------------------------------------------
  522. private string GetActiveHintText( EVRButtonId button )
  523. {
  524. if ( buttonHintInfos.ContainsKey( button ) )
  525. {
  526. ButtonHintInfo hintInfo = buttonHintInfos[button];
  527. if ( hintInfo.textHintActive )
  528. {
  529. return hintInfo.text.text;
  530. }
  531. }
  532. return string.Empty;
  533. }
  534. //-------------------------------------------------
  535. // These are the static functions which are used to show/hide the hints
  536. //-------------------------------------------------
  537. //-------------------------------------------------
  538. private static ControllerButtonHints GetControllerButtonHints( Hand hand )
  539. {
  540. if ( hand != null )
  541. {
  542. ControllerButtonHints hints = hand.GetComponentInChildren<ControllerButtonHints>();
  543. if ( hints != null && hints.initialized )
  544. {
  545. return hints;
  546. }
  547. }
  548. return null;
  549. }
  550. //-------------------------------------------------
  551. public static void ShowButtonHint( Hand hand, params EVRButtonId[] buttons )
  552. {
  553. ControllerButtonHints hints = GetControllerButtonHints( hand );
  554. if ( hints != null )
  555. {
  556. hints.ShowButtonHint( buttons );
  557. }
  558. }
  559. //-------------------------------------------------
  560. public static void HideButtonHint( Hand hand, params EVRButtonId[] buttons )
  561. {
  562. ControllerButtonHints hints = GetControllerButtonHints( hand );
  563. if ( hints != null )
  564. {
  565. hints.HideButtonHint( buttons );
  566. }
  567. }
  568. //-------------------------------------------------
  569. public static void HideAllButtonHints( Hand hand )
  570. {
  571. ControllerButtonHints hints = GetControllerButtonHints( hand );
  572. if ( hints != null )
  573. {
  574. hints.HideAllButtonHints();
  575. }
  576. }
  577. //-------------------------------------------------
  578. public static bool IsButtonHintActive( Hand hand, EVRButtonId button )
  579. {
  580. ControllerButtonHints hints = GetControllerButtonHints( hand );
  581. if ( hints != null )
  582. {
  583. return hints.IsButtonHintActive( button );
  584. }
  585. return false;
  586. }
  587. //-------------------------------------------------
  588. public static void ShowTextHint( Hand hand, EVRButtonId button, string text, bool highlightButton = true )
  589. {
  590. ControllerButtonHints hints = GetControllerButtonHints( hand );
  591. if ( hints != null )
  592. {
  593. hints.ShowText( button, text, highlightButton );
  594. }
  595. }
  596. //-------------------------------------------------
  597. public static void HideTextHint( Hand hand, EVRButtonId button )
  598. {
  599. ControllerButtonHints hints = GetControllerButtonHints( hand );
  600. if ( hints != null )
  601. {
  602. hints.HideText( button );
  603. }
  604. }
  605. //-------------------------------------------------
  606. public static void HideAllTextHints( Hand hand )
  607. {
  608. ControllerButtonHints hints = GetControllerButtonHints( hand );
  609. if ( hints != null )
  610. {
  611. hints.HideAllText();
  612. }
  613. }
  614. //-------------------------------------------------
  615. public static string GetActiveHintText( Hand hand, EVRButtonId button )
  616. {
  617. ControllerButtonHints hints = GetControllerButtonHints( hand );
  618. if ( hints != null )
  619. {
  620. return hints.GetActiveHintText( button );
  621. }
  622. return string.Empty;
  623. }
  624. }
  625. }