private void Start() { faceMesh = faceSkin.sharedMesh; blendShapeValueBuffer = new float[faceMesh.blendShapeCount]; previousFace = defaultFace; }
private void Trigger(FacialExpressionPreset face) { if (animating) { return; } StartCoroutine(ChangeFaceTo(face)); }
IEnumerator ChangeFaceTo(FacialExpressionPreset currentFace) { animating = true; float t = 0; while (t < changeTime) { float fraction = t / changeTime; Zero(); // Previous float weight = 1 - fraction; previousFace.targetBlendshapePairs.ForEach(blendShapeIndexPair => { blendShapeValueBuffer[blendShapeIndexPair.Index] += blendShapeIndexPair.MaxValue * weight; }); // Current weight = fraction; currentFace.targetBlendshapePairs.ForEach(blendShapeIndexPair => { blendShapeValueBuffer[blendShapeIndexPair.Index] += blendShapeIndexPair.MaxValue * weight; }); t += Time.deltaTime; yield return(null); } animating = false; previousFace = currentFace; }