forked from homuler/MediaPipeUnityPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebCamDeviceSelectorController.cs
More file actions
35 lines (26 loc) · 1.09 KB
/
Copy pathWebCamDeviceSelectorController.cs
File metadata and controls
35 lines (26 loc) · 1.09 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
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class WebCamDeviceSelectorController : MonoBehaviour {
private GameObject sceneDirector;
private WebCamDevice[] devices;
void Start() {
sceneDirector = GameObject.Find("SceneDirector");
var webCamDeviceSelector = GetComponent<Dropdown>();
webCamDeviceSelector.onValueChanged.AddListener(delegate { OnValueChanged(webCamDeviceSelector); });
ResetOptions(WebCamTexture.devices);
}
void ResetOptions(WebCamDevice[] devices) {
this.devices = devices;
var webCamDeviceSelector = GetComponent<Dropdown>();
webCamDeviceSelector.ClearOptions();
webCamDeviceSelector.AddOptions(devices.Select(device => device.name).ToList());
// Now webCamDeviceSelector.value equals 0
OnValueChanged(webCamDeviceSelector);
}
void OnValueChanged(Dropdown dropdown) {
WebCamDevice? device = dropdown.value < devices.Length ? (WebCamDevice?)devices[dropdown.value] : null;
Debug.Log("WebCamDevice Changed: " + device?.name);
sceneDirector.GetComponent<SceneDirector>().ChangeWebCamDevice(device);
}
}