/*
     * Start
     */
    void Start()
    {
        // Set starting to either given startEmotion or default to the first in the list
        bool givenStartEmotionExists = false;

        for (int i = 0; i < goToEmotionList.Count; i++)
        {
            if (goToEmotionList[i].name.Equals(startEmotion))
            {
                givenStartEmotionExists = true;
            }
        }

        if (!givenStartEmotionExists)
        {
            Debug.LogError("Given starting emotion does not exist.");
            //currentlyPlaying = emotionObjects[goToEmotionList[0].indexInEmotionObjects].name;  // If not given, assume some default value
            IFAClip startingClip = new IFAClip(playablesDict, mixerEmotionPlayable, emotionObjects[goToEmotionList[0].indexInEmotionObjects].name + "0", true);
            startingClip.setWeight(1.0f);
            currentlyPlayingClips.Add(startingClip);
        }
        else
        {
            //currentlyPlaying = startEmotion;
            IFAClip startingClip = new IFAClip(playablesDict, mixerEmotionPlayable, startEmotion + "0", true);
            startingClip.setWeight(1.0f);
            currentlyPlayingClips.Add(startingClip);
        }

        // Plays the Playables Graph, i.e. starts playing animations
        playableGraph.Play();
    }
 private void playMain()
 {
     if ((transitionClip.getDuration() - transitionClip.getTime()) < 0.05f)
     {
         //currentlyPlaying = transitionEmotion;
         fPlayMainAfterTransition = false;
         transitionClip.setWeight(0.0f);
         newMainClip.reset();
         newMainClip.setWeight(1.0f);
         //normalize = true;
         blendingDone = true;
     }
 }
    // Function that handles the actual blending. Called each frame in update
    private void playTransition()
    {
        // Initialize Transition when it begins
        if (fInitTransition)
        {
            newMainClip.reset();  // TODO: Might need to comment this back in if auto-main-loop doesnt work

            fInitTransition = false;
        }

        // LERP Transition and currently playing emotion
        // Interpolation website: http://paulbourke.net/miscellaneous/interpolation/
        currentTime += Time.deltaTime;
        float mu = currentTime / blendDuration;
        //float t;
        float upcomingBlendWeight = 0;
        float pStart = 0f;
        float pEnd   = 1f;

        switch (interpolationMode)
        {
        case "Linear":
            upcomingBlendWeight = IFALerp.linear(pStart, pEnd, mu);
            break;

        case "Cubic":
            upcomingBlendWeight = IFALerp.cubic(pStart, pEnd, mu);
            break;

        case "Bezier":
            upcomingBlendWeight = IFALerp.bezier(pStart, pEnd, mu, pBezierP1, pBezierP2);
            break;

        default:
            break;
        }

        // Draw for display purposes
        if (drawGraphOnImage)
        {
            drawGraphOnImage.drawPoint(0, pStart, Color.red);
            drawGraphOnImage.drawPoint(1, pEnd, Color.green);
            drawGraphOnImage.drawPoint(mu, upcomingBlendWeight, Color.black);
        }



        // Set Blend Weights
        if (oldMainClips != null)
        {
            for (int i = 0; i < oldMainClips.Count; i++)
            {
                oldMainClips[i].setWeight((1f - upcomingBlendWeight) * oldMainClipsInitialWeight[i]);
            }
        }
        newMainClip.setWeight(upcomingBlendWeight);

        // TODO: Update Clips?
        foreach (IFAClip clip in allClips)
        {
            clip.update();
        }


        // End Transition CleanUp, Prepare playing Main
        if (currentTime >= blendDuration)
        {
            blendingDone = true;
        }
    }
    // Function that handles the actual blending. Called each frame in update
    private void playTransition()
    {
        // Initialize Transition when it begins
        if (fInitTransition)
        {
            transitionClip.reset();

            fInitTransition          = false;
            fPlayMainAfterTransition = false;   // In case a new transition starts while a transitionIn animation is still playing
        }

        // LERP Transition and currently playing emotion
        // Interpolation website: http://paulbourke.net/miscellaneous/interpolation/
        currentTime += Time.deltaTime;
        float mu = currentTime / blendDuration;
        //float t;
        float upcomingBlendWeight = 0;
        float pStart = 0f;
        float pEnd   = 1f;

        switch (interpolationMode)
        {
        case "Linear":
            upcomingBlendWeight = IFALerp.linear(pStart, pEnd, mu);
            break;

        case "Cubic":
            upcomingBlendWeight = IFALerp.cubic(pStart, pEnd, mu);
            break;

        case "Bezier":
            upcomingBlendWeight = IFALerp.bezier(pStart, pEnd, mu, pBezierP1, pBezierP2);
            break;

        default:
            break;
        }

        // Draw for display purposes
        if (drawGraphOnImage)
        {
            drawGraphOnImage.drawPoint(0, pStart, Color.red);
            drawGraphOnImage.drawPoint(1, pEnd, Color.green);
            drawGraphOnImage.drawPoint(mu, upcomingBlendWeight, Color.black);
        }


        // Set Blend Weights
        if (oldMainClips != null)
        {
            for (int i = 0; i < oldMainClips.Count; i++)
            {
                oldMainClips[i].setWeight((1f - upcomingBlendWeight) * oldMainClipsInitialWeight[i]);
            }
        }
        transitionClip.setWeight(upcomingBlendWeight);

        // Update Clips?
        foreach (IFAClip clip in allClips)
        {
            clip.update();
        }


        // End Transition CleanUp, Prepare playing Main
        if (currentTime >= blendDuration)
        {
            fPlayMainAfterTransition = true;
            fInitTransition          = true;
            currentTime = 0;
            //previousEmotionNumber = emotionNumber;
            transitionDone = true;
        }
        //normalize = true;
    }