SteamVR_ActivateActionSetOnLoad.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. using UnityEngine;
  3. using System.Collections;
  4. namespace Valve.VR
  5. {
  6. /// <summary>
  7. /// Automatically activates an action set on Start() and deactivates the set on OnDestroy(). Optionally deactivating all other sets as well.
  8. /// </summary>
  9. public class SteamVR_ActivateActionSetOnLoad : MonoBehaviour
  10. {
  11. public SteamVR_ActionSet actionSet = SteamVR_Input.GetActionSet("default");
  12. public SteamVR_Input_Sources forSources = SteamVR_Input_Sources.Any;
  13. public bool disableAllOtherActionSets = false;
  14. public bool activateOnStart = true;
  15. public bool deactivateOnDestroy = true;
  16. public int initialPriority = 0;
  17. private void Start()
  18. {
  19. if (actionSet != null && activateOnStart)
  20. {
  21. //Debug.Log(string.Format("[SteamVR] Activating {0} action set.", actionSet.fullPath));
  22. actionSet.Activate(forSources, initialPriority, disableAllOtherActionSets);
  23. }
  24. }
  25. private void OnDestroy()
  26. {
  27. if (actionSet != null && deactivateOnDestroy)
  28. {
  29. //Debug.Log(string.Format("[SteamVR] Deactivating {0} action set.", actionSet.fullPath));
  30. actionSet.Deactivate(forSources);
  31. }
  32. }
  33. }
  34. }