Ejemplo n.º 1
0
    IEnumerator ResetMouthRoutine(PlayerNPCInput npc)
    {
        float startBlend = npc.GetPlayer().GetSkinnedMeshRenderer().GetBlendShapeWeight(0);
        float endBlend   = 0f;

        float timer = 0f;

        while (timer < _resetMouthTime)
        {
            timer += Time.deltaTime;

            float mouthBlendWeight = Mathf.Lerp(startBlend, endBlend, timer / _resetMouthTime);

            if (npc.GetPlayer().GetSkinnedMeshRenderer())
            {
                npc.GetPlayer().GetSkinnedMeshRenderer().SetBlendShapeWeight(npc.GetPlayer().GetMouthBlendIndex(), mouthBlendWeight);
            }

            yield return(null);
        }

        _resetMouthRoutine = null;
    }
Ejemplo n.º 2
0
    IEnumerator ReadChunkRoutine(DialogueChunk dialogueChunk, PlayerNPCInput npc, GameSound voiceEventOverride)
    {
        bool hasNPC = (npc != null);

        if (_showWidgetRoutine != null)
        {
            StopCoroutine(_showWidgetRoutine);
        }

        _showWidgetRoutine = StartCoroutine(ShowWidgetRoutine(true));
        yield return(_showWidgetRoutine);

        if (dialogueChunk.chunkType == DialogueChunk.ChunkType.Choice)
        {
            _optionLayout.SetActive(true);

            for (int i = 0; i < dialogueChunk.responses.Length; i++)
            {
                _optionButtons[i].gameObject.SetActive(true);
                GetOptionTexts()[i].color = GetOptionTexts()[i].color.SetA(0f);
                GetOptionTexts()[i].text  = dialogueChunk.responses[i].response;
            }
        }

        string dialogueText = LocUtils.Translate(dialogueChunk.dialogueTerm);

        foreach (KeyValuePair <string, string> kvp in _locDynamicText)
        {
            if (dialogueText.Contains(kvp.Key))
            {
                dialogueText = dialogueText.Replace(kvp.Key, LocUtils.Translate(kvp.Value));
            }
        }

        if (_textSpeed > Mathf.Epsilon)
        {
            _lineText.text = dialogueText;

            if (_resetMouthRoutine != null)
            {
                StopCoroutine(_resetMouthRoutine);
                _resetMouthRoutine = null;
            }

            GameSound dialogueSound = voiceEventOverride;
            if (dialogueSound == GameSound.NONE)
            {
                string soundName = "SFX_UI_Dialogue_" + dialogueChunk.character.ToString();
                if (Enum.IsDefined(typeof(GameSound), soundName))
                {
                    dialogueSound = (GameSound)Enum.Parse(typeof(GameSound), soundName);
                }
            }

            GameSounds.PostEvent2D(dialogueSound);

            float lineStartTime = Time.time;
            for (int i = 0; i < dialogueText.Length; i++)
            {
                // Skip rich text
                if (dialogueText[i] == '<')
                {
                    while (dialogueText[i] != '>')
                    {
                        i++;
                    }

                    i++;
                }

                _lineText.ScaleCharacter(i);

                float timer = 0;
                while (timer < _textSpeed)
                {
                    if (hasNPC && npc.GetPlayer().HasMouthBlend())
                    {
                        float timeSinceLineState = Time.time - lineStartTime;
                        float mouthBlendWeight   = (Mathf.Sin(timeSinceLineState * _mouthFlapSpeed * Mathf.PI) * 0.5f + 0.5f) * 100f;

                        if (npc.GetPlayer().GetSkinnedMeshRenderer())
                        {
                            npc.GetPlayer().GetSkinnedMeshRenderer().SetBlendShapeWeight(npc.GetPlayer().GetMouthBlendIndex(), mouthBlendWeight);
                        }
                    }

                    if (!GameManager.GSM.IsStateActive(GameStateType.PauseMenu) && InputManager.ActiveDevice.AnyButtonWasPressed)
                    {
                        _lineText.ForceAllScaled();
                        goto lineFinished;
                    }

                    timer += Time.deltaTime;
                    yield return(null);
                }
            }

lineFinished:

            if (hasNPC && npc.GetPlayer().HasMouthBlend())
            {
                _resetMouthRoutine = StartCoroutine(ResetMouthRoutine(npc));
            }

            if (dialogueSound != GameSound.NONE)
            {
                GameSounds.PostEvent2D(dialogueSound, EventAction.StopSound);
            }
        }
        else
        {
            _lineText.text = dialogueText;
        }

        if (dialogueChunk.chunkType == DialogueChunk.ChunkType.Default)
        {
            _continuePrompt.SetActive(true);

            yield return(null);

            while (!InputManager.ActiveDevice.AnyButtonWasPressed)
            {
                yield return(null);
            }

            if (_continuePrompt != null)
            {
                _continuePrompt.SetActive(false);
            }
        }
        else
        {
            yield return(StartCoroutine(DialogueOptionsRoutine(dialogueChunk)));
        }

        _lineText.text = string.Empty;

        if (_showWidgetRoutine != null)
        {
            StopCoroutine(_showWidgetRoutine);
        }

        _showWidgetRoutine = StartCoroutine(ShowWidgetRoutine(false));
        yield return(_showWidgetRoutine);

        _readChunkRoutine = null;
    }
Ejemplo n.º 3
0
    IEnumerator ReadDialogueRoutine(DialogueData dialogueData)
    {
        List <Player> players = PlayerManager.GetSpawnedPlayers();

        for (int i = 0; i < players.Count; i++)
        {
            players[i].GetInput().bottomControlLens.AddRequest(new LensHandle <bool>(this, false));
        }

        for (_chunkIndex = 0; _chunkIndex < dialogueData.dialogue.Length; _chunkIndex++)
        {
            if (_chunkIndex < 0)
            {
                _chunkIndex = 0;
            }

            Vector3   faceDirection  = Vector3.zero;
            Transform prevLookTarget = null;

            bool                  hasNPC      = false;
            PlayerNPCInput        npc         = null;
            List <PlayerNPCInput> spawnedNPCs = PlayerManager.GetNPCs();
            for (int j = 0; j < spawnedNPCs.Count; j++)
            {
                if (spawnedNPCs[j].gameObject.activeInHierarchy && spawnedNPCs[j].GetPlayer().GetInfo().character == dialogueData.dialogue[_chunkIndex].character)
                {
                    hasNPC = true;
                    npc    = spawnedNPCs[j];

                    faceDirection = npc.transform.forward.SetY(0f);
                    if (dialogueData.facingMode != FacingMode.Stay)
                    {
                        faceDirection = (PlayerManager.GetLeadPlayer().transform.position - npc.transform.position).SetY(0f);
                        if (dialogueData.facingMode != FacingMode.FaceForward)
                        {
                            npc.TweenLookDirection(faceDirection);
                        }
                    }

                    prevLookTarget = npc.GetPlayer().GetPhysics().GetBody().lookTarget;
                    npc.GetPlayer().GetPhysics().GetBody().lookTarget = dialogueData.lookTarget ?? CameraManager.instance.transform;

                    break;
                }
            }

            string pattern  = @"\{(.*?)\}";
            string dialogue = LocUtils.Translate(dialogueData.dialogue[_chunkIndex].dialogueTerm);

            #region Dialogue Commands
            // LOOK FOR COMMANDS IN DIALOGUE
            // OH LORD WE BEGIN OUR DESCENT INTO MADNESS
            MatchCollection matchCollection = Regex.Matches(dialogue, pattern);
            foreach (Match m in matchCollection)
            {
                dialogue = dialogue.Replace(m.Value, "");

                string value = m.Value.Remove(0, 1);
                value = value.Remove(value.Length - 1, 1);

                string[] sections = value.Split(',');
                if (sections[0] == "SetHat")
                {
                    if (hasNPC && sections.Length == 2)
                    {
                        if (Enum.IsDefined(typeof(HatType), sections[1]))
                        {
                            HatType hatType = (HatType)Enum.Parse(typeof(HatType), sections[1]);
                            npc.GetPlayer().SetHat(hatType);

                            if (hatType != HatType.None)
                            {
                                Tweakables.VFX.bubblePop.Spawn(ObjectPool.instance.transform, npc.GetPlayer().GetActiveHats()[0].transform.position);
                            }
                        }
                    }
                    else if (sections.Length == 3)
                    {
                        if (Enum.IsDefined(typeof(CharacterType), sections[1]))
                        {
                            CharacterType character = (CharacterType)Enum.Parse(typeof(CharacterType), sections[1]);
                            for (int j = 0; j < spawnedNPCs.Count; j++)
                            {
                                if (spawnedNPCs[j].GetPlayer().GetInfo().character == character)
                                {
                                    if (Enum.IsDefined(typeof(HatType), sections[2]))
                                    {
                                        HatType hatType = (HatType)Enum.Parse(typeof(HatType), sections[2]);
                                        spawnedNPCs[j].GetPlayer().SetHat(hatType);

                                        if (hatType != HatType.None)
                                        {
                                            Tweakables.VFX.bubblePop.Spawn(ObjectPool.instance.transform, spawnedNPCs[j].GetPlayer().GetActiveHats()[0].transform.position);
                                        }
                                    }

                                    break;
                                }
                            }
                        }
                    }
                }
                else if (sections[0] == "SetSkin")
                {
                    if (hasNPC && sections.Length == 2)
                    {
                        if (Enum.IsDefined(typeof(SkinType), sections[1]))
                        {
                            SkinType skinType = (SkinType)Enum.Parse(typeof(SkinType), sections[1]);
                            npc.GetPlayer().SetSkin(skinType);
                        }
                    }
                    else if (sections.Length == 3)
                    {
                        if (Enum.IsDefined(typeof(CharacterType), sections[1]))
                        {
                            CharacterType character = (CharacterType)Enum.Parse(typeof(CharacterType), sections[1]);
                            for (int j = 0; j < spawnedNPCs.Count; j++)
                            {
                                if (spawnedNPCs[j].GetPlayer().GetInfo().character == character)
                                {
                                    if (Enum.IsDefined(typeof(SkinType), sections[2]))
                                    {
                                        SkinType skinType = (SkinType)Enum.Parse(typeof(SkinType), sections[2]);
                                        spawnedNPCs[j].GetPlayer().SetSkin(skinType);
                                    }

                                    break;
                                }
                            }
                        }
                    }
                }
            }

            dialogueData.dialogue[_chunkIndex].dialogue = dialogue;
            #endregion

            SetCharacter(dialogueData.dialogue[_chunkIndex].character);

            // Stem Target
            Transform stemTarget = dialogueData.target;
            if (!stemTarget && hasNPC)
            {
                stemTarget = npc.GetPlayer().GetPhysics().GetSausage().transform;
            }

            SetTarget(stemTarget);

            // Camera Target
            Vector3   camOffset = dialogueData.offset;
            Transform camTarget = dialogueData.target;
            if (camTarget)
            {
                faceDirection = camTarget.forward;
            }
            else if (hasNPC)
            {
                camTarget = npc.transform.GetBoneTagInChildren(BoneLocation.SpineMiddle).transform;
                camOffset = Vector3.up * 0.5f;
            }

            Quaternion targetLookRot = Quaternion.identity;
            if (camTarget)
            {
                if (dialogueData.facingMode == FacingMode.FaceForward && PlayerManager.GetLeadPlayer())
                {
                    faceDirection = (PlayerManager.GetLeadPlayer().transform.position - camTarget.transform.position).SetY(0f);
                }

                if (faceDirection != Vector3.zero)
                {
                    targetLookRot = Quaternion.LookRotation(faceDirection, Vector3.up);
                }

                CameraManager.RegisterFollowTarget(camTarget, camOffset, dialogueData.camWeight);
            }

            CameraManager.SetOverrideSettings(dialogueData.camSettings, targetLookRot.eulerAngles.y);

            // Jump camera to end position, calculate where bubble will be and then jump it back
            Vector3    prevCamPos = CameraManager.instance.transform.position;
            Quaternion prevCamRot = CameraManager.instance.transform.rotation;

            _snapBubbleToAlonePoint = true;

            CameraManager.SimpleSnapToTarget();

            UpdateBubblePos();

            if (_chunkIndex == 0 && dialogueData.snap)
            {
                CameraManager.SnapToTarget();
            }

            if (!dialogueData.snap)
            {
                CameraManager.instance.transform.position = prevCamPos;
                CameraManager.instance.transform.rotation = prevCamRot;
            }

            // Do emote stuff
            if (hasNPC)
            {
                if (dialogueData.dialogue[_chunkIndex].emote != EmoteType.None)
                {
                    EmoteTag emoteTag = npc.GetPayload().GetEmote(dialogueData.dialogue[_chunkIndex].emote);
                    emoteTag.Play(dialogueData.dialogue[_chunkIndex].loopEmote);

                    npc.headSwingScaleLens.AddRequest(
                        new LensHandle <float>(this, npc.GetPayload().GetEmote(dialogueData.dialogue[_chunkIndex].emote).GetShakeForce()));

                    if (emoteTag.GetUseEyeBlend())
                    {
                        npc.GetPlayer().eyeBlendLens.AddRequest(new LensHandle <float>(this, emoteTag.GetEyeBlend()));
                    }
                }
                else
                {
                    npc.headSwingScaleLens.AddRequest(new LensHandle <float>(this, 0.3f));
                }
            }

            int prevIndex = _chunkIndex;             // Hack to go back to page backwards for debug

            _readChunkRoutine = StartCoroutine(ReadChunkRoutine(dialogueData.dialogue[_chunkIndex], npc, dialogueData.voiceEvent));
            while (_readChunkRoutine != null)
            {
                yield return(null);
            }

            if (!gameObject.activeSelf || npc == null)
            {
                yield break;
            }

            _optionLayout.SetActive(false);

            foreach (var optionButton in _optionButtons)
            {
                optionButton.gameObject.SetActive(false);
            }

            if (dialogueData.dialogue[prevIndex].chunkType == DialogueChunk.ChunkType.Choice)
            {
                dialogueData.dialogue[prevIndex].SaveResponse();
            }

            if (hasNPC)
            {
                if (dialogueData.dialogue[prevIndex].emote != EmoteType.None && dialogueData.dialogue[prevIndex].loopEmote)
                {
                    npc.GetPayload().GetEmote(dialogueData.dialogue[prevIndex].emote).Stop();
                }

                npc.GetPlayer().eyeBlendLens.RemoveRequestsWithContext(this);
                npc.GetPlayer().GetPhysics().GetBody().lookTarget = prevLookTarget;

                npc.headSwingScaleLens.RemoveRequestsWithContext(this);
            }

            CameraManager.SetOverrideSettings(null, null);

            if (camTarget)
            {
                CameraManager.DeregisterFollowTarget(camTarget);
            }

            if ((prevIndex == dialogueData.dialogue.Length - 1) && dialogueData.snapBack)
            {
                CameraManager.SnapToTarget();
            }
        }

        for (int i = 0; i < players.Count; i++)
        {
            if (players[i])
            {
                players[i].GetInput().bottomControlLens.RemoveRequestsWithContext(this);
            }
        }
    }