-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlendShapeGUI.cs
75 lines (64 loc) · 2.22 KB
/
BlendShapeGUI.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
66
67
68
69
70
71
72
73
74
75
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.iOS;
public class BlendShapeGUI : MonoBehaviour
{
bool shapeEnabled = false;
Dictionary<string, float> currentBlendShapes; //dictionary object of string - coefficient pairs
// Use this for initialization
void Start()
{
/* This code subscribes our methods FaceAdded, FaceUpdated, & FaceRemoved to
* ARKit's Events, meaning our functions will be called when these events occur. */
UnityARSessionNativeInterface.ARFaceAnchorAddedEvent += FaceAdded;
UnityARSessionNativeInterface.ARFaceAnchorUpdatedEvent += FaceUpdated;
UnityARSessionNativeInterface.ARFaceAnchorRemovedEvent += FaceRemoved;
}
void OnGUI()
{
if (shapeEnabled)
{
//formats and then places the blendshape values into the top left UI box
string blendshapes = "";
string shapeNames = "";
string valueNames = "";
foreach (KeyValuePair<string, float> kvp in currentBlendShapes)
{
blendshapes += " [";
blendshapes += kvp.Key.ToString();
blendshapes += ":";
blendshapes += kvp.Value.ToString();
blendshapes += "]\n";
shapeNames += "\"";
shapeNames += kvp.Key.ToString();
shapeNames += "\",\n";
valueNames += kvp.Value.ToString();
valueNames += "\n";
}
GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true));
GUILayout.Box(blendshapes);
GUILayout.EndHorizontal();
Debug.Log(shapeNames);
Debug.Log(valueNames);
}
}
void FaceAdded(ARFaceAnchor anchorData)
{
shapeEnabled = true;
currentBlendShapes = anchorData.blendShapes;
}
void FaceUpdated(ARFaceAnchor anchorData)
{
//on update, we update the old dictionary of values with the current one
currentBlendShapes = anchorData.blendShapes;
}
void FaceRemoved(ARFaceAnchor anchorData)
{
shapeEnabled = false;
}
// Update is called once per frame
void Update()
{
}
}