示例#1
0
        private void Start()
        {
            faceMesh = faceSkin.sharedMesh;

            blendShapeValueBuffer = new float[faceMesh.blendShapeCount];

            previousFace = defaultFace;
        }
示例#2
0
        private void Trigger(FacialExpressionPreset face)
        {
            if (animating)
            {
                return;
            }

            StartCoroutine(ChangeFaceTo(face));
        }
示例#3
0
        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;
        }