Ejemplo n.º 1
0
        private void SetupOptions(Dialogue.DialogueSnippet snippet)
        {
            int i          = 0;
            int replyCount = snippet.playerReplies.Length;

            if (replyCount == 0)
            {
                //hide all options.
                for (; i < options.Length; i++)
                {
                    options[i].gameObject.SetActive(false);
                }

                //Wait for a short delay, then wait for player input
                StartCoroutine(WaitForKeyPress());
                IEnumerator WaitForKeyPress()
                {
                    yield return(new WaitForSeconds(2f));

                    yield return(new WaitUntil(() => Input.anyKeyDown));

                    Continue();
                }

                return;
            }
            //the total spread of the options in degrees.
            float spread = ((float)replyCount - 1f) * angleOffset;
            //start at half the negative spread.
            float angle = spread * -0.5f;

            for (; i < replyCount; i++)
            {
                options[i].gameObject.SetActive(true);
                options[i].SetText(snippet.playerReplies[i]);

                //place the option.
                Vector2 baseOffset    = new Vector2(distance, 0);
                Vector2 rotatedOffset = Quaternion.AngleAxis(angle, Vector3.forward) * baseOffset;

                options[i].GetComponent <RectTransform>().anchoredPosition = rotatedOffset;

                //increment the angle.
                angle += angleOffset;
            }
            for (; i < options.Length; i++)
            {
                options[i].gameObject.SetActive(false);
            }
            optionsGroup.interactable = true;
        }
Ejemplo n.º 2
0
        private void ShowDialogue(Dialogue.DialogueSnippet snippet)
        {
            //clear the npc chat box.
            npcText.text = "";
            //create the sequence.
            var sequence = DOTween.Sequence();

            //1. Fade out all the options.
            sequence.Append(optionsGroup.DOFade(endValue: 0.0f, duration: 0.5f).OnStart(() => optionsGroup.interactable = false)); //.OnComplete(() => source.Play())
            sequence.Append(npcGroup.DOFade(1.0f, 0.5f).OnComplete(() => npcAudioSource.PlayOneShot(npcVoiceClip)));
            //2. show the new text, then set up the options.
            float textDuration = (float)snippet.npcText.Length / textSpeed;

            sequence.Append(DOTween.To(() => npcText.text, x => npcText.text = x, snippet.npcText, textDuration).OnComplete(() => SetupOptions(snippet)));
            //3. fade the options back in if necessary
            if (snippet.playerReplies.Length > 0)
            {
                sequence.Append(optionsGroup.DOFade(endValue: 1.0f, duration: 0.5f).SetDelay(0.5f));
            }
            //4. start the sequence.
            sequence.PlayForward();
        }