Beispiel #1
0
    /// <summary>Coroutine to smoothly change the shape of the mesh</summary>
    /// <param name="onFinishMeshChange">Function to call once the mesh has finished changing</param>
    private IEnumerator ChangeMeshCoroutine(ShapeData.ShapeType shapeType, FinishChange onFinishMeshChange)
    {
        changeMeshCoroutFin = false;

        // Get the initial values for each of the blend shapes
        float[] startBlendShapes = new float[BLEND_SHAPE_AMOUNT];
        for (int i = 0; i < BLEND_SHAPE_AMOUNT; ++i)
        {
            startBlendShapes[i] = targetRenderers[0].GetBlendShapeWeight(i);
        }
        // Get index of the target blend shape
        int targetBlendIndex = GetBlendIndexFromShape(shapeType);

        // The amount of lerps that will be done
        float t = 0;

        while (t < 1)
        {
            // Lerp it
            LerpRenderers(targetBlendIndex, startBlendShapes, t);
            // Step
            t += changeSpeed * Time.deltaTime;

            yield return(null);
        }
        // Set the variables without lerping now that we are done
        LerpRenderers(targetBlendIndex, startBlendShapes, 1);

        changeMeshCoroutFin = true;
        // Call the specified functionality after changing meshes
        onFinishMeshChange?.Invoke();

        yield return(null);
    }
Beispiel #2
0
    /// <summary>Starts smoothly changing the shape given</summary>
    /// <param name="onFinishMeshChange">Function to call once the mesh has finished changing</param>
    public void StartChangeShape(ShapeData.ShapeType shapeType, FinishChange onFinishMeshChange = null)
    {
        currentShapeType = shapeType;

        // If there is an ongoing coroutine, stop it
        if (!changeMeshCoroutFin)
        {
            StopCoroutine(changeMeshCorout);
        }
        // Start a new coroutine
        changeMeshCorout = StartCoroutine(ChangeMeshCoroutine(shapeType, onFinishMeshChange));
    }