Created
July 10, 2018 22:57
-
-
Save cabbibo/854dfd00bafe32f9acfb2d4037da70fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.XR.iOS; | |
public class BlendShapeEventSystem : MonoBehaviour { | |
bool shapeEnabled = false; | |
Dictionary<string, float> currentBlendShapes; | |
Dictionary<string, float> oldBlendShapes; | |
private List<FaceEvent> faceEvents = new List<FaceEvent>(); | |
// Use this for initialization | |
void Start () { | |
UnityARSessionNativeInterface.ARFaceAnchorAddedEvent += FaceAdded; | |
UnityARSessionNativeInterface.ARFaceAnchorUpdatedEvent += FaceUpdated; | |
UnityARSessionNativeInterface.ARFaceAnchorRemovedEvent += FaceRemoved; | |
} | |
void OnGUI() | |
{ | |
} | |
void FaceAdded (ARFaceAnchor anchorData) | |
{ | |
shapeEnabled = true; | |
currentBlendShapes = anchorData.blendShapes; | |
oldBlendShapes = currentBlendShapes; | |
} | |
void FaceUpdated (ARFaceAnchor anchorData) | |
{ | |
oldBlendShapes = currentBlendShapes; | |
currentBlendShapes = anchorData.blendShapes; | |
for( int i = 0; i < faceEvents.Count; i++ ){ | |
FaceEvent faceEvent = faceEvents[i]; | |
float oldVal = oldBlendShapes[faceEvent.type]; | |
float newVal = currentBlendShapes[faceEvent.type]; | |
print((oldVal-newVal)*10000); | |
if( faceEvent.triggerDirection == 1 ){ | |
//print("y1"); | |
if( oldVal < faceEvent.triggerValue && newVal >= faceEvent.triggerValue ){ | |
print("Y"); | |
faceEvent.FaceFire(); | |
} | |
} | |
if( faceEvent.triggerDirection == -1 ){ | |
if( oldVal >= faceEvent.triggerValue && newVal < faceEvent.triggerValue ){ | |
print("Y2"); | |
faceEvent.FaceFire(); | |
} | |
} | |
} | |
} | |
public void AddFaceEvent( FaceEvent faceEvent ){ | |
Debug.Log("ADDED"); | |
faceEvents.Add( faceEvent ); | |
} | |
public void RemoveFaceEvent( FaceEvent faceEvent ){ | |
Debug.Log("REMOVED"); | |
faceEvents.Remove( faceEvent ); | |
} | |
void FaceRemoved (ARFaceAnchor anchorData) | |
{ | |
shapeEnabled = false; | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment