Beispiel #1
0
    // Use this for initialization
    void Awake()
    {
        commsNavigation  = FindObjectOfType <CommsNavigation>();
        commsDisplay     = GetComponent <Text>();
        responseText     = this.transform.Find("ResponseText").GetComponent <Text>();
        responseTextCopy = this.transform.Find("ResponseTextCopy").GetComponent <Text>();
        commsImg         = this.transform.parent.GetComponent <RawImage>();
        panels           = bgdPanels.GetComponent <PanelsBottom>();
        dateScreen       = FindObjectOfType <DatingScreen>();
        camMaster        = FindObjectOfType <CameraMaster>();
        musicBox         = FindObjectOfType <MusicPlayer>();
        scanner          = FindObjectOfType <InfoScan>();
        actCoord         = FindObjectOfType <ActionSceneCoordinator>();

        rightEye = FindObjectOfType <TeddyRightEye>();
        bCam     = FindObjectOfType <BodyCam>();

        commsDisplay.enabled     = false;
        commsImg.enabled         = false;
        responseText.enabled     = false;
        responseTextCopy.enabled = false;           // responseTextCopy is only used for determining the line count of individual responses; it is never displayed
        panels.HideInfoBgdPanel();

        textActivated = false;
        textActive    = false;

        commsDisplay.supportRichText     = true;
        responseText.supportRichText     = true;
        responseTextCopy.supportRichText = true;

        currentText           = "";
        currentResponseText   = "";
        listOfResponses       = "";
        responseTextCopy.text = "";

        currentResponseNumber = 0;
        readyForSelection     = false;

        portrait.enabled      = false;
        portraitFrame.enabled = false;

        unravellingText             = false;
        unravellingResponseText     = false;
        showingLoadingText          = false;
        isUnravelled                = false;
        unravellingTextStartTimeSet = false;

        char[] tempChars = loadingString.ToCharArray();
        for (int i = 0; i < tempChars.Length; i++)
        {
            loadingChars.Add(tempChars[i]);
        }

        skipUnravelling                = false;
        canSkipUnravelling             = false;
        unravellingTextCharIndex       = 0;
        loadingStringCharIndex         = 0;
        unravellingTextTimeRef         = 0;
        unravellingResponseTextTimeRef = 0;
        loadingTextTimeRef             = 0;

        closeEnoughToCommunicate = false;

        isUsingStardater = false;
        isInDatingChat   = false;
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (textActive)
        {
            scanner.HideReticleAndText(true);

            if ((transmissionSpeech != null && closeEnoughToCommunicate && !currentLine.continues) || (startingPrompt != null && talkingToFakeTed) || (transmissionSpeech != null && isInDatingChat))
            {
                panels.ShowInfoBgdPanel(commsDisplay.cachedTextGenerator.lineCount, responseText.cachedTextGenerator.lineCount);
            }
            //else if (transmissionID.GetType() == typeof(IDDate))    { panels.shoinfo}
            else
            {
                panels.ShowInfoBgdPanelPromptOnly(commsDisplay.cachedTextGenerator.lineCount);
            }
            commsDisplay.text = unravellingPromptText;
            responseText.text = unravellingResponseTransitionText;

            if (textIsUnravelled)
            {
                if (unravellingText)
                {
                    if (!skipUnravelling)
                    {
                        if (!unravellingTextStartTimeSet)
                        {
                            unravellingTextStartTime    = Time.time;
                            unravellingTextStartTimeSet = true;
                        }

                        canSkipUnravelling = true;

                        if (Time.time - unravellingTextTimeRef > unravellingTextTimePerChar)
                        {
                            string charString      = "";
                            int    numOfCharsToAdd = Mathf.Min(unravellingChars.Count - unravellingTextCharIndex, numOfCharsToUnravelPerInterval);
                            for (int i = 0; i < numOfCharsToAdd; i++)
                            {
                                charString = string.Concat(charString, unravellingChars[unravellingTextCharIndex + i].ToString());
                            }
                            unravellingPromptText = string.Concat(unravellingPromptText, charString);
                            if (unravellingTextCharIndex < unravellingChars.Count - 1)
                            {
                                unravellingTextCharIndex = unravellingTextCharIndex + numOfCharsToUnravelPerInterval;
                                unravellingTextTimeRef   = Time.time;
                            }
                            else
                            {
                                StopUnravellingText();
                                unravellingTextTimeRef = Time.time;

                                string hexPromptColor = ColorUtility.ToHtmlStringRGB(promptColor);
                                unravellingPromptText = "<color=#" + hexPromptColor + ">" + unravellingPromptText + "</color>";

                                // Can click through to next line if the current one is a continuation--no loading text or response text needed
                                if (currentLine.continues)
                                {
                                    readyForSelection = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        canSkipUnravelling = false;

                        StopUnravellingText();
                        unravellingTextTimeRef = Time.time;

                        string hexPromptColor = ColorUtility.ToHtmlStringRGB(promptColor);
                        unravellingPromptText = "<color=#" + hexPromptColor + ">" + unravellingPromptText + "</color>";

                        if (currentLine.continues)
                        {
                            readyForSelection = true;
                        }

                        skipUnravelling = false;
                    }

                    //if (unravelingRandomChar) {
                    //    int rand;
                    //    if (unravelingTextCharIndex < unravelingChars.Count - 1) { rand = Random.Range(unravelingTextCharIndex, unravelingChars.Count); } else { rand = unravelingTextCharIndex; }

                    //    if (Time.time - unravelingTextTimeRefForRandChar > unravelingTextTimePerChar) {
                    //        //unravelingPromptText = string.Concat(unravelingPromptText, unravelingChars[rand].ToString());
                    //        unravelingPromptText = string.Concat(unravelingPromptText, "-");
                    //        unravelingRandomChar = false;
                    //        unravelingTextTimeRef = Time.time;
                    //    }
                    //} else {
                    //    if (Time.time - unravelingTextTimeRef > unravelingTextTimePerChar) {
                    //        unravelingPromptText = string.Concat(unravelingPromptText.Substring(0, unravelingPromptText.Length - 1),
                    //                unravelingChars[unravelingTextCharIndex].ToString());
                    //        if (unravelingTextCharIndex < unravelingChars.Count - 1) {
                    //            unravelingTextCharIndex++;
                    //            unravelingRandomChar = true;
                    //            unravelingTextTimeRefForRandChar = Time.time;
                    //        } else {
                    //            StopUnravellingText();
                    //        }
                    //    }
                    //}
                }

                if ((transmissionSpeech != null && closeEnoughToCommunicate) || (startingPrompt != null && talkingToFakeTed) || transmissionSpeech != null && isInDatingChat)
                {
                    // Show loading text for responses--responses load once the current prompt text is shown completely
                    // Loading text (and subsequent response text) does not show if the current prompt continues
                    if (showingLoadingText && !currentLine.continues && (Time.time - unravellingTextStartTime > delayBeforeShowingLoadingString))
                    {
                        if (Time.time - loadingTextTimeRef > loadingTextTimePerChar)
                        {
                            string charLoadingString = "";

                            for (int i = 0; i < loadingStringCharIndex; i++)
                            {
                                charLoadingString = string.Concat(charLoadingString, loadingChars[i]);
                            }

                            if (loadingStringCharIndex < loadingChars.Count - 1)
                            {
                                loadingStringCharIndex++;
                            }
                            else
                            {
                                loadingStringCharIndex = 0;
                            }

                            unravellingResponseTransitionText = charLoadingString;

                            loadingTextTimeRef = Time.time;
                        }

                        if (Time.time - unravellingTextTimeRef > totalLoadingTime)
                        {
                            showingLoadingText     = false;
                            loadingStringCharIndex = 0;
                            panels.ChooseAResponse();
                            currentResponseNumber = 0;
                            panels.MoveSelectionBar(lineCountsOfResponses[currentResponseNumber].pixelCountDistanceFromDefaultBottomPosition, lineCountsOfResponses[currentResponseNumber].lineCount);
                            readyForSelection = true;
                        }
                    }
                    if (!showingLoadingText)
                    {
                        if (responseTextIsUnravelled)
                        {
                            if (unravellingResponseText)
                            {
                                if (Time.time - unravellingResponseTextTimeRef > unravellingResponseTextTimePerChar)
                                {
                                    string charString      = "";
                                    int    numOfCharsToAdd = Mathf.Min(unravellingResponseChars.Count - unravellingResponseTextCharIndex, numOfResponseCharsToUnravelPerInterval);
                                    for (int i = 0; i < numOfCharsToAdd; i++)
                                    {
                                        charString = string.Concat(charString, unravellingResponseChars[unravellingResponseTextCharIndex + i].ToString());
                                    }
                                    unravellingResponseTransitionText = string.Concat(unravellingResponseTransitionText, charString);
                                    if (unravellingResponseTextCharIndex < unravellingResponseChars.Count - 1)
                                    {
                                        unravellingResponseTextCharIndex = unravellingResponseTextCharIndex + numOfResponseCharsToUnravelPerInterval;
                                        unravellingResponseTextTimeRef   = Time.time;
                                    }
                                    else
                                    {
                                        StopUnravellingResponseText();
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (responses.Count > 0)
                            {
                                unravellingResponseTransitionText = listOfResponses;
                            }
                        }
                    }
                }
            }
        }

        // NOTE: textActivated is toggled by player button press -- see Camera Master
        // Only makes one pass before switching to !textActivated & textActive
        if (textActivated && !textActive)
        {
            //scanner.reticle.enabled = false;
            scanner.HideReticleAndText(true);

            ClearConversationLogs();
            panels.NoSelection();

            // Shouldn't need anything here if in dating chat--everything initialized in StartDatingChat(), including rejogging the this loop by setting textActive = false
            if (isUsingStardater)
            {
                if (isInDatingChat)
                {
                }
                else
                {
                    dateScreen.EnableScreen(true);
                    transmissionSpeech = null;
                    currentLine        = stardaterTedPrompt;
                }
            }
            else
            {
                if (rightEye.RightEyeTargetID() != null)
                {
                    transmissionID = rightEye.RightEyeTargetID();

                    //if (transmissionID.transform.parent.GetComponent<Collider>() != null) {
                    //    Collider col = transmissionID.transform.parent.GetComponent<Collider>();
                    //    distance = Vector3.Distance(col.ClosestPoint(bCam.transform.position), bCam.transform.position);
                    //}
                    //else {
                    //    distance = Vector3.Distance(transmissionID.transform.parent.position, bCam.transform.position);
                    //}

                    if (transmissionID.GetDistanceToActiveIDCollider(bCam.transform.position) < transmissionID.maxDistanceToActivate)
                    {
                        closeEnoughToCommunicate = true;

                        if (transmissionID.GetType() == typeof(IDDate))
                        {
                            dateScreen.EnableScreen(true);
                            startingPrompt = stardaterTedPrompt;
                            //camMaster.OverrideReticle(true);
                        }
                        else if (transmissionID.GetType() == typeof(IDCharacter))
                        {
                            IDCharacter idChar = (IDCharacter)transmissionID;
                            if (idChar.portrait != null)
                            {
                                portrait.texture      = idChar.portrait;
                                portraitFrame.enabled = true;
                                portrait.enabled      = true;
                            }
                        }
                    }
                }

                if (rightEye.RightEyeTargetSpeech() != null)
                {
                    transmissionSpeech = rightEye.RightEyeTargetSpeech();

                    if (closeEnoughToCommunicate)
                    {
                        startingPrompt       = transmissionSpeech.openingTextLine;
                        responseText.enabled = true;
                    }
                    else
                    {
                        startingPrompt       = null;
                        responseText.enabled = false;
                    }
                }

                if (rightEye.RightEyeTargetAI() != null)
                {
                    transmissionAI = rightEye.RightEyeTargetAI();
                }

                if (rightEye.RightEyeTargetAudio() != null)
                {
                    transmissionAudio = rightEye.RightEyeTargetAudio();
                }

                if (startingPrompt != null)
                {
                    currentLine = startingPrompt;
                }
                else
                {
                    currentLine = noTargetPrompt;
                }
            }

            AssembleAndDisplayCommsText();

            commsDisplay.enabled = true;

            textActive = true;

            //textInput.ActivateInputField();

            //textInput.GetComponent<Image>().enabled = true;
            //textInput.textComponent.enabled = true;
            //panels.ShowInfoBgdPanel(commsDisplay.cachedTextGenerator.lineCount);
        }
        else if (textActive && !textActivated)
        {
            portrait.enabled      = false;
            portraitFrame.enabled = false;
            dateScreen.EnableScreen(false);
            //camMaster.OverrideReticle(false);
            //scanner.reticle.enabled = true;
            scanner.HideReticleAndText(false);
            isUsingStardater = false;
            isInDatingChat   = false;

            transmissionID     = null;
            transmissionSpeech = null;
            transmissionAI     = null;
            transmissionAudio  = null;

            panels.ShowInfoBgdPanelPromptOnly(1);
            panels.HideInfoBgdPanel();
            panels.NoSelection();
            commsDisplay.enabled = false;
            responseText.enabled = false;

            textActive = false;
            StopUnravellingText();
            StopUnravellingResponseText();

            ClearConversationLogs();
            startingPrompt = null;
            unravellingTextStartTimeSet = false;

            closeEnoughToCommunicate = false;
            talkingToFakeTed         = false;

            //textInput.DeactivateInputField();
            //textInput.GetComponent<Image>().enabled = false;
            //textInput.GetComponent<Image>().enabled = false;
            //textInput.textComponent.enabled = false;
        }
    }