2
0

SteamVR_ExternalCamera_LegacyManager.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: Used to render an external camera of vr player (split front/back).
  4. //
  5. //=============================================================================
  6. using UnityEngine;
  7. using System.Collections;
  8. namespace Valve.VR
  9. {
  10. public class SteamVR_ExternalCamera_LegacyManager
  11. {
  12. public static bool hasCamera { get { return cameraIndex != -1; } }
  13. public static int cameraIndex = -1;
  14. private static SteamVR_Events.Action newPosesAction = null;
  15. public static void SubscribeToNewPoses()
  16. {
  17. if (newPosesAction == null)
  18. newPosesAction = SteamVR_Events.NewPosesAction(OnNewPoses);
  19. newPosesAction.enabled = true;
  20. }
  21. private static void OnNewPoses(TrackedDevicePose_t[] poses)
  22. {
  23. if (cameraIndex != -1)
  24. return;
  25. int controllercount = 0;
  26. for (int index = 0; index < poses.Length; index++)
  27. {
  28. if (poses[index].bDeviceIsConnected)
  29. {
  30. ETrackedDeviceClass deviceClass = OpenVR.System.GetTrackedDeviceClass((uint)index);
  31. if (deviceClass == ETrackedDeviceClass.Controller || deviceClass == ETrackedDeviceClass.GenericTracker)
  32. {
  33. controllercount++;
  34. if (controllercount >= 3)
  35. {
  36. cameraIndex = index;
  37. break;
  38. }
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }