forked from homuler/MediaPipeUnityPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphSelectorController.cs
More file actions
59 lines (46 loc) · 1.86 KB
/
Copy pathGraphSelectorController.cs
File metadata and controls
59 lines (46 loc) · 1.86 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
53
54
55
56
57
58
59
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class GraphSelectorController : MonoBehaviour {
[SerializeField] GameObject faceDetectionGraph = null;
[SerializeField] GameObject faceMeshGraph = null;
[SerializeField] GameObject irisTrackingGraph = null;
[SerializeField] GameObject handTrackingGraph = null;
[SerializeField] GameObject poseTrackingGraph = null;
[SerializeField] GameObject hairSegmentationGraph = null;
[SerializeField] GameObject objectDetectionGraph = null;
private GameObject sceneDirector;
private Dictionary<string, GameObject> graphs;
void Start() {
sceneDirector = GameObject.Find("SceneDirector");
var graphSelector = GetComponent<Dropdown>();
graphSelector.onValueChanged.AddListener(delegate { OnValueChanged(graphSelector); });
InitializeOptions();
}
void InitializeOptions() {
graphs = new Dictionary<string, GameObject>();
AddGraph("Face Detection", faceDetectionGraph);
AddGraph("Face Mesh", faceMeshGraph);
AddGraph("Iris Tracking", irisTrackingGraph);
AddGraph("Hand Tracking", handTrackingGraph);
AddGraph("Pose Tracking", poseTrackingGraph);
AddGraph("Hair Segmentation", hairSegmentationGraph);
AddGraph("Object Detection", objectDetectionGraph);
var graphSelector = GetComponent<Dropdown>();
graphSelector.ClearOptions();
graphSelector.AddOptions(graphs.Select(pair => pair.Key).ToList());
OnValueChanged(graphSelector);
}
void AddGraph(string label, GameObject graph) {
if (graph != null) {
graphs.Add(label, graph);
}
}
void OnValueChanged(Dropdown dropdown) {
var option = dropdown.options[dropdown.value];
var graph = graphs[option.text];
Debug.Log($"Graph Changed: {option.text}");
sceneDirector.GetComponent<SceneDirector>().ChangeGraph(Instantiate(graph));
}
}