Tanoda
HandStatistics.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using System.Linq;
4using GILES;
5using UnityEngine;
6#if !UNITY_WEBGL
7using ViveHandTracking;
8#endif
9
10public class HandStatistics : pb_MonoBehaviourSingleton<HandStatistics>
11{
12 private bool collectData = false;
13 readonly List<bool> data = new List<bool>();
14 private bool isEditor = false;
15
16 void Start()
17 {
18 isEditor = FindObjectOfType<StartStageOnLoad>() != null;
19#if !UNITY_WEBGL
20 StartCoroutine(DataCollector());
21#endif
22 }
23
24 public float GetPercent()
25 {
26 return (float)data.Count(x => x) / data.Count;
27 }
28
29 public void StopCollecting(bool purge = true)
30 {
31 collectData = false;
32 if (purge)
33 {
34 data.Clear();
35 }
36 }
37 public void StartCollecting(bool clear = true)
38 {
39 if (clear)
40 {
41 data.Clear();
42 }
43 collectData = true;
44 }
45
46#if !UNITY_WEBGL
47 IEnumerator DataCollector()
48 {
49 while (true)
50 {
51 while (!collectData || isEditor)
52 {
53 yield return new WaitForSecondsRealtime(0.1f);
54 }
55 GestureResult leftResult = GestureProvider.LeftHand;
56 GestureResult rightResult = GestureProvider.RightHand;
57 if (leftResult != null || rightResult != null)
58 {
59 data.Add(true);
60 }
61 else
62 {
63 data.Add(false);
64 }
65 yield return new WaitForSecondsRealtime(0.5f);
66 }
67 }
68#endif
69}
void StopCollecting(bool purge=true)
float GetPercent()
void StartCollecting(bool clear=true)