// Use this for initialization
 void Start()
 {
     currentEmotions        = new EmotionStruct();
     currentFACS            = new FACSStruct();
     emotionWindow          = new ArrayList();
     emotionWindow.Capacity = 10;
 }
    // Update is called once per frame
    void Update()
    {
        // Pull in the most recent emotional state for each of the modalities
        if (useFacialEmotion)
        {
            currentFacialEmotion  = facialAnalyzer.getCurrentEmotions();
            currentFacialEmotion2 = facialAnalyzer2.getCurrentEmotions();
            currentFACS           = facialAnalyzer.getCurrentFACS();
            currentFACS2          = facialAnalyzer2.getCurrentFACS();
            // Debug.Log("got facial emotion struct");
        }

        if (useWordSentimentEmotion)
        {
            currentWordSentimentEmotion = wordAnalyzer.getCurrentEmotions();
        }

        if (useVocalToneEmotion)
        {
            currentVocalEmotion = vocalAnalyzer.getVocalToneResults();
        }

        //Set mood tracker attributes
        CalculateMoodTrackerGeometry();
    }
    private IEnumerator RequestEmotionUpdate()
    {
        // Debug.Log("Entered REQUEST EMOTION UPDATE COROUTINE.");
        while (true)
        {
            yield return(new WaitForSeconds(colorUpdateTime));

            if (gameManagerScript.useFacialEmotion)
            {
                EmotionStruct currentEmotions  = gameManagerScript.getCurrentFacialEmotion();
                EmotionStruct currentEmotions2 = gameManagerScript.getCurrentFacialEmotion2();
                FACSStruct    currentFACS      = gameManagerScript.getCurrentFACS();
                FACSStruct    currentFACS2     = gameManagerScript.getCurrentFACS2();
                FacialEmotionText.text = "Joy: " + currentEmotions.joy + "\nAnger: " + currentEmotions.anger + "\nFear: " + currentEmotions.fear + "\nDisgust: " + currentEmotions.disgust + "\nSadness: " + currentEmotions.sadness + "\nContempt: " + currentEmotions.contempt + "\nValence: " + currentEmotions.valence + "\nEngagement: " + currentEmotions.engagement;
                FACSText.text          = "Attention: " + currentFACS.Attention + "\nBrowFurrow: " + currentFACS.BrowFurrow + "\nBrowRaise: " + currentFACS.BrowRaise + "\nChinRaise: " + currentFACS.ChinRaiser + "\nEyeClose: " + currentFACS.EyeClosure + "\nInnerEyebrowRaise: " + currentFACS.InnerEyeBrowRaise + "\nLipCornerDepress: " + currentFACS.LipCornerDepressor + "\nLipPress: " + currentFACS.LipPress + "\nLipPucker: " + currentFACS.LipPucker + "\nLipSuck: " + currentFACS.LipSuck + "\nMouthOpen: " + currentFACS.MouthOpen + "\nNoseWrinkle: " + currentFACS.NoseWrinkler + "\nSmile: " + currentFACS.Smile + "\nSmirk: " + currentFACS.Smirk + "\nUpperLipRaise" + currentFACS.UpperLipRaiser;
                // Update facial emotion colors
                if (gameManagerScript.useAugmentedBasicEmotions)
                {
                    currentValue      = (currentEmotions.valence + 175f) / 300f;
                    currentHueDist    = gameManagerScript.calculateEmotionHueDist(currentEmotions);
                    currentSaturation = sum(currentHueDist) / 100f;
                    currentHue        = getStrongestHue(currentHueDist);
                }
                else if (gameManagerScript.useBasicEmotions)
                {
                }
                else
                {
                    currentValue      = (currentEmotions.valence + 175f) / 300f;
                    currentSaturation = currentEmotions.engagement / 100f;
                    currentHue        = (currentValue + currentSaturation) / 2;
                }
                string currentStrongestEmotion  = getStrongestEmotion(currentHueDist);
                string currentStrongestEmotion2 = getStrongestEmotion2(currentEmotions2);
                int    threshidx = 0;
                if (getStrongestEmotionVal(currentHueDist) >= 50.0f)
                {
                    threshidx = 1;
                }
                currentEmotionEmoji  = facialEmojiDict [currentStrongestEmotion] [threshidx];
                currentEmotionEmoji2 = facialEmojiDict [currentStrongestEmotion2] [threshidx];
                if (currentStrongestEmotion == "joy")
                {
                    rotationX = 0f;
                }
                else
                {
                    rotationX = -90.0f;
                }
                if (currentStrongestEmotion2 == "joy")
                {
                    rotationX2 = 0f;
                }
                else
                {
                    rotationX2 = -90.0f;
                }
                previousFacialEmotionColor = currentFacialEmotionColor;
                currentFacialEmotionColor  = gameManagerScript.calculateEmotionColor(gameManagerScript.getCurrentFacialEmotion());

                // Update the emotion bars
                previousFacialEmotionBarWidth = currentFacialEmotionBarWidth;
                currentFacialEmotionBarWidth  = gameManagerScript.getValueOfStrongestEmotion(gameManagerScript.getCurrentFacialEmotion()) * 2;
            }

            if (gameManagerScript.useWordSentimentEmotion)
            {
                // Update word sentiment emotion colors
                previousWordSentimentEmotionColor = currentWordSentimentEmotionColor;
                currentWordSentimentEmotionColor  = gameManagerScript.calculateEmotionColor(gameManagerScript.getCurrentWordSentimentEmotion());

                EmotionStruct currentEmotions = gameManagerScript.getCurrentWordSentimentEmotion();

                SentimentEmotionText.text = "Joy: " + currentEmotions.joy + "\nAnger: " + currentEmotions.anger + "\nFear: " + currentEmotions.fear + "\nDisgust: " + currentEmotions.disgust + "\nSadness: " + currentEmotions.sadness;

                previousWordSentimentEmotionBarWidth = currentWordSentimentEmotionBarWidth;
                currentWordSentimentEmotionBarWidth  = gameManagerScript.getValueOfStrongestEmotion(gameManagerScript.getCurrentWordSentimentEmotion()) * 2;
            }
            if (gameManagerScript.useVocalToneEmotion)
            {
                if (gameManagerScript.useFacialEmotion)
                {
                    currentSaturation += vocalToneResults.ArousalVal / 100f;
                    currentValue      += vocalToneResults.ValenceVal / 100f;
                    currentSaturation /= 2f;
                    currentValue      /= 2f;
                }
                else
                {
                    currentSaturation = vocalToneResults.ArousalVal / 100f;
                    currentValue      = vocalToneResults.ValenceVal / 100f;
                }
            }

            currentBackground = Color.HSVToRGB(currentHue, currentSaturation, currentValue);
            StartCoroutine(UpdateBackgroundColor());
        }
    }