OVRModeParms.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /************************************************************************************
  2. Copyright : Copyright 2017 Oculus VR, LLC. All Rights reserved.
  3. Licensed under the Oculus VR Rift SDK License Version 3.4.1 (the "License");
  4. you may not use the Oculus VR Rift SDK except in compliance with the License,
  5. which is provided at the time of installation or download, or which
  6. otherwise accompanies this software in either electronic or hard copy form.
  7. You may obtain a copy of the License at
  8. https://developer.oculus.com/licenses/sdk-3.4.1
  9. Unless required by applicable law or agreed to in writing, the Oculus VR SDK
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ************************************************************************************/
  15. using UnityEngine;
  16. /// <summary>
  17. /// Logs when the application enters power save mode and allows you to a low-power CPU/GPU level with a button press.
  18. /// </summary>
  19. public class OVRModeParms : MonoBehaviour
  20. {
  21. #region Member Variables
  22. /// <summary>
  23. /// The gamepad button that will switch the application to CPU level 0 and GPU level 1.
  24. /// </summary>
  25. public OVRInput.RawButton resetButton = OVRInput.RawButton.X;
  26. #endregion
  27. /// <summary>
  28. /// Invoke power state mode test.
  29. /// </summary>
  30. void Start()
  31. {
  32. if (!OVRManager.isHmdPresent)
  33. {
  34. enabled = false;
  35. return;
  36. }
  37. // Call TestPowerLevelState after 10 seconds
  38. // and repeats every 10 seconds.
  39. InvokeRepeating ( "TestPowerStateMode", 10, 10.0f );
  40. }
  41. /// <summary>
  42. /// Change default vr mode parms dynamically.
  43. /// </summary>
  44. void Update()
  45. {
  46. // NOTE: some of the buttons defined in OVRInput.RawButton are not available on the Android game pad controller
  47. if ( OVRInput.GetDown(resetButton))
  48. {
  49. //*************************
  50. // Dynamically change VrModeParms cpu and gpu level.
  51. // NOTE: Reset will cause 1 frame of flicker as it leaves
  52. // and re-enters Vr mode.
  53. //*************************
  54. OVRPlugin.cpuLevel = 0;
  55. OVRPlugin.gpuLevel = 1;
  56. }
  57. }
  58. /// <summary>
  59. /// Check current power state mode.
  60. /// </summary>
  61. void TestPowerStateMode()
  62. {
  63. //*************************
  64. // Check power-level state mode
  65. //*************************
  66. if (OVRPlugin.powerSaving)
  67. {
  68. // The device has been throttled
  69. Debug.Log("POWER SAVE MODE ACTIVATED");
  70. }
  71. }
  72. }