-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSphereDrawing.cs
65 lines (43 loc) · 2.17 KB
/
SphereDrawing.cs
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
60
61
62
63
64
65
using System;
using UniRx;
using UnityEngine;
using UnityEngine.Serialization;
public class SphereDrawing : MonoBehaviour
{
[SerializeField]
private OVRHand hand = default;
[SerializeField]
private Transform fingerTiplong = default;
// Start is called before the first frame update
private void Start()
{
bool IsIndexPinched() => hand.GetFingerIsPinching(OVRHand.HandFinger.Index); // I didnt know you could set a function like this or add things to a list via listnam[insert interger data].
var lastPinchStream =
Observable.EveryUpdate().Select(_ => IsIndexPinched());
var currentPinchStream =
Observable.EveryUpdate().Select(_ => (IsIndexPinched())).Skip(1);
var pinchStartStream =
Observable.Zip(lastPinchStream, currentPinchStream).Where(p => !p[0] && p[1]); // translation if its not the first last pinch but the first current pinch start the event
var allowedDelay = 1.0f;
var doublePinch = pinchStartStream.SelectMany(e => pinchStartStream.Buffer(TimeSpan.FromSeconds(allowedDelay), 1) //I got hung up on this put miliseconds instead
.Take(1)
.Where(b => b.Count >= 1)); //here is where define the double pinch - im fairly certian you could do this right off the double pinch code in the lesson with less implementation not sure why its reapeat or take 1 vs take 2 need to look back on thsi
//below the double pinch event leads us to subcribe to an observable event where while the isidex is pinched spheres are created at o.1 second rate
doublePinch.Take(1).Repeat().Subscribe(_ =>
{
Observable
.Interval(TimeSpan.FromSeconds(0.1))
.TakeWhile(x => IsIndexPinched())
.Subscribe(x =>
{
CreateSphereObject();
});
}).AddTo(this);
}
private void CreateSphereObject(float size = 0.02f)
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = fingerTiplong.transform.position;
sphere.transform.localScale = Vector3.one * size;
}
}