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