// INITIALIZE METHODS: --------------------------------------------------------------------

        private void Awake()
        {
            DialogueUI.Instance = this;
            EventSystemManager.Instance.Wakeup();

            if (this.wrapLogs != null)
            {
                this.wrapLogs.SetActive(false);
            }
            if (this.wrapGraphic != null)
            {
                this.wrapGraphic.SetActive(false);
            }
            if (this.wrapMessage != null)
            {
                this.wrapMessage.SetActive(false);
            }
            if (this.wrapChoices != null)
            {
                this.wrapChoices.SetActive(false);
            }
            if (this.wrapTimer != null)
            {
                this.wrapTimer.SetActive(false);
            }
        }
Example #2
0
        public override IDialogueItem[] GetNextItem()
        {
            if (!this.hasChoicesAvailable)
            {
                return(null);
            }
            if (this.timedChoice && !this.hasMadeChoice)
            {
                switch (this.timeoutBehavior)
                {
                case TIMEOUT_BEHAVIOR.FirstChoice:
                    this.hasMadeChoice = true;
                    this.choiceIndex   = 0;
                    break;

                case TIMEOUT_BEHAVIOR.RandomChoice:
                    this.hasMadeChoice = true;
                    this.choiceIndex   = Random.Range(0, this.children.Count);
                    break;
                }
            }

            if (!this.hasMadeChoice)
            {
                return(null);
            }
            if (this.choiceIndex >= this.children.Count)
            {
                Debug.LogError("Not enough answers");
                return(null);
            }

            DialogueUI.CompleteChoice(this.children[this.choiceIndex]);
            return(new IDialogueItem[] { this.children[this.choiceIndex] });
        }
Example #3
0
        // INITIALIZE METHODS: --------------------------------------------------------------------

        private void Awake()
        {
            DialogueUI.Instance = this;
            DontDestroyOnLoad(gameObject);

            this.wrapMessage.SetActive(false);
            this.wrapChoices.SetActive(false);
            this.wrapTimer.SetActive(false);
        }
        public static bool StartChoices(DialogueItemChoiceGroup item, DatabaseDialogue.ConfigData config)
        {
            DialogueUI.RequireInstance(config);
            DialogueUI.Instance.wrapChoices.SetActive(true);

            bool choicesAvailable = DialogueUI.Instance.SetupChoices(item, config);

            if (choicesAvailable && item.timedChoice)
            {
                DialogueUI.Instance.StartTimer(item.timeout.GetValue(item.gameObject));
            }

            return(choicesAvailable);
        }
Example #5
0
        // OVERRIDE METHODS: ----------------------------------------------------------------------

        protected override IEnumerator RunItem()
        {
            yield return(this.RunShowText());

            if (this.voice != null)
            {
                AudioManager.Instance.StopVoice(this.voice);
            }

            DialogueUI.CompleteLine(this);
            DialogueUI.HideText();

            yield break;
        }
Example #6
0
        // PUBLIC METHODS: ------------------------------------------------------------------------

        public static void ShowText(IDialogueItem item, DatabaseDialogue.ConfigData config)
        {
            DialogueUI.RequireInstance(config);

            DialogueUI.Instance.currentMessage         = (item.content != null ? item.content.GetText() : "");
            DialogueUI.Instance.typewritterEnabled     = config.enableTypewritterEffect;
            DialogueUI.Instance.typewritterCharsPerSec = config.charactersPerSecond;
            DialogueUI.Instance.typewritterStartTime   = Time.time;

            string msg = (config.enableTypewritterEffect ? "" : DialogueUI.Instance.currentMessage);

            DialogueUI.Instance.textMessage.text = msg;
            DialogueUI.Instance.wrapMessage.SetActive(true);
        }
Example #7
0
        // OVERRIDE METHODS: ----------------------------------------------------------------------

        protected override IEnumerator RunItem()
        {
            if (this.conditionsList != null && !this.conditionsList.Check())
            {
                yield break;
            }
            if (this.children.Count <= 0)
            {
                yield break;
            }

            if (!string.IsNullOrEmpty(this.GetContent()))
            {
                yield return(this.RunShowText());
            }

            this.hasMadeChoice = false;
            this.choiceIndex   = -1;
            this.startTime     = Time.time;

            DatabaseDialogue.ConfigData configData = this.GetConfigData();
            this.hasChoicesAvailable = DialogueUI.StartChoices(this, configData);

            WaitUntil waitUntil = new WaitUntil(() =>
            {
                if (!this.hasChoicesAvailable)
                {
                    return(true);
                }
                if (this.timedChoice && Time.time > this.startTime + this.timeout.GetValue(gameObject))
                {
                    return(true);
                }

                return(this.hasMadeChoice);
            });

            yield return(waitUntil);

            if (this.voice != null)
            {
                AudioManager.Instance.StopVoice(this.voice);
            }

            DialogueUI.CompleteLine(this);
            DialogueUI.HideText();
            DialogueUI.HideChoices();
        }
Example #8
0
        protected override IEnumerator RunItem()
        {
            this.continueSubitems = true;
            if (this.conditionsList != null && !this.conditionsList.Check())
            {
                this.continueSubitems = false;
                yield break;
            }

            yield return(this.RunShowText());

            if (this.voice != null)
            {
                AudioManager.Instance.StopVoice(this.voice);
            }
            DialogueUI.HideText();
            yield break;
        }
        protected IEnumerator RunShowText()
        {
            DatabaseDialogue.ConfigData configData = this.GetConfigData();
            DialogueUI.StartLine(this, configData);

            if (this.voice != null)
            {
                AudioManager.Instance.PlayVoice(this.voice, 0f);
            }
            float textInitTime = Time.time;

            WaitForSeconds waitForSeconds = new WaitForSeconds(TIME_SAFE_OFFSET);

            yield return(waitForSeconds);

            yield return(new WaitUntil(() => {
                if (this.dialogue.IsStoppingDialogue())
                {
                    return true;
                }

                if (Input.GetKeyUp(configData.skipKey))
                {
                    if (configData.enableTypewriterEffect && DialogueUI.IsTypeWriting())
                    {
                        DialogueUI.CompleteTypeWriting();
                        return false;
                    }

                    return true;
                }

                bool timeout = Time.time - textInitTime > this.autoPlayTime;
                if (this.autoPlay && timeout)
                {
                    return true;
                }

                return false;
            }));
        }
Example #10
0
        protected IEnumerator RunShowText()
        {
            DatabaseDialogue.ConfigData configData = this.GetConfigData();
            DialogueUI.ShowText(this, configData);

            if (this.voice != null)
            {
                AudioManager.Instance.PlayVoice(this.voice);
            }

            if (this.autoPlay)
            {
                WaitForSeconds waitForSeconds = new WaitForSeconds(this.autoPlayTime);
                yield return(waitForSeconds);
            }
            else
            {
                WaitForSeconds waitForSeconds = new WaitForSeconds(TIME_SAFE_OFFSET);
                yield return(waitForSeconds);

                yield return(new WaitUntil(() => {
                    if (Input.anyKeyDown)
                    {
                        if (configData.enableTypewritterEffect && DialogueUI.IsTypeWritting())
                        {
                            DialogueUI.CompleteTypeWritting();
                            return false;
                        }
                        else
                        {
                            return true;
                        }
                    }

                    return false;
                }));
            }
        }
        public static void StartLine(IDialogueItem item, DatabaseDialogue.ConfigData config)
        {
            DialogueUI.RequireInstance(config);
            DialogueUI dialogue = DialogueUI.Instance;

            dialogue.currentMessage        = item.GetContent();
            dialogue.typewriterEnabled     = config.enableTypewriterEffect;
            dialogue.typewriterCharsPerSec = config.charactersPerSecond;
            dialogue.typewriterStartTime   = Time.time;
            dialogue.gibberish             = null;

            string msg = (config.enableTypewriterEffect ? "" : dialogue.currentMessage);

            dialogue.textMessage.text = msg;

            if (dialogue.wrapLogs != null)
            {
                dialogue.wrapLogs.SetActive(true);
            }
            if (dialogue.wrapGraphic != null)
            {
                dialogue.wrapGraphic.SetActive(true);
            }
            if (dialogue.wrapMessage != null)
            {
                dialogue.wrapMessage.SetActive(true);
            }

            if (dialogue.textTitle != null)
            {
                dialogue.textTitle.gameObject.SetActive(false);
            }
            if (dialogue.actorColor != null)
            {
                dialogue.actorColor.gameObject.SetActive(false);
            }
            if (dialogue.actorImage != null)
            {
                dialogue.actorImage.gameObject.SetActive(false);
            }
            if (dialogue.actorRawImage != null)
            {
                dialogue.actorRawImage.gameObject.SetActive(false);
            }
            if (dialogue.actorPrefabContainer != null)
            {
                dialogue.actorPrefabContainer.gameObject.SetActive(false);
            }

            if (item.actor != null)
            {
                if (dialogue.textTitle != null)
                {
                    dialogue.textTitle.gameObject.SetActive(true);
                    dialogue.textTitle.text = item.actor.GetName();
                }

                if (dialogue.actorColor != null)
                {
                    dialogue.actorColor.gameObject.SetActive(true);
                    dialogue.actorColor.color = item.actor.color;
                }

                if (item.actorSpriteIndex < item.actor.actorSprites.data.Length)
                {
                    ActorSprites.Data spriteData = item.actor.actorSprites.data[item.actorSpriteIndex];
                    switch (spriteData.type)
                    {
                    case ActorSprites.DataType.Sprite:
                        if (dialogue.actorImage != null)
                        {
                            dialogue.actorImage.gameObject.SetActive(true);
                            dialogue.actorImage.sprite = spriteData.sprite;
                        }
                        break;

                    case ActorSprites.DataType.Texture:
                        if (dialogue.actorRawImage != null)
                        {
                            dialogue.actorRawImage.gameObject.SetActive(true);
                            dialogue.actorRawImage.texture = spriteData.texture;
                        }
                        break;

                    case ActorSprites.DataType.Prefab:
                        if (dialogue.actorPrefabContainer != null)
                        {
                            dialogue.actorPrefabContainer.gameObject.SetActive(true);
                            for (int i = dialogue.actorPrefabContainer.childCount - 1; i >= 0; --i)
                            {
                                Destroy(dialogue.actorPrefabContainer.GetChild(i).gameObject);
                            }

                            GameObject instance = Instantiate(
                                spriteData.prefab,
                                dialogue.actorPrefabContainer
                                );
                            instance.transform.localScale = Vector3.one;
                        }
                        break;
                    }
                }

                if (item.actor.useGibberish)
                {
                    dialogue.gibberish = new GibberishEffect(
                        item.actor.gibberishAudio,
                        item.actor.gibberishPitch,
                        item.actor.gibberishVariation
                        );
                }
            }

            if (config.enableTypewriterEffect)
            {
                DialogueUI.Instance.typewriter = new TypeWriterEffect(
                    DialogueUI.Instance.currentMessage
                    );
            }
        }
Example #12
0
        // PUBLIC METHODS: ------------------------------------------------------------------------

        public IEnumerator Run()
        {
            this.stopDialogue = false;

            Stack <IDialogueItem> stackItems = new Stack <IDialogueItem>();

            stackItems.Push(this.dialogue);

            DialogueUI.BeginDialogue();

            while (!this.stopDialogue && stackItems.Count > 0)
            {
                IDialogueItem item = stackItems.Pop();
                if (!item.CheckConditions())
                {
                    continue;
                }

                yield return(item.Run());

                if (this.stopDialogue || item.afterRun == IDialogueItem.AfterRunBehaviour.Exit)
                {
                    stackItems.Clear();
                    DialogueUI.EndDialogue();

                    yield break;
                }
                else if (item.afterRun == IDialogueItem.AfterRunBehaviour.Jump && item.jumpTo != null)
                {
                    stackItems.Clear();

                    int jumpToID = item.jumpTo.GetInstanceID();
                    List <IDialogueItem> parentChildren = item.jumpTo.parent.children;
                    int parentChildrenCount             = parentChildren.Count;

                    for (int i = parentChildrenCount - 1; i >= 0; --i)
                    {
                        if (parentChildren[i] == null)
                        {
                            continue;
                        }
                        stackItems.Push(parentChildren[i]);
                        if (parentChildren[i].GetInstanceID() == jumpToID)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    IDialogueItem[] childItems = item.GetNextItem();
                    if (childItems != null)
                    {
                        int numChildItems = childItems.Length;
                        for (int i = numChildItems - 1; i >= 0; --i)
                        {
                            if (childItems[i] == null)
                            {
                                continue;
                            }
                            stackItems.Push(childItems[i]);
                        }
                    }
                }
            }

            DialogueUI.EndDialogue();
        }