コード例 #1
0
        // PROTECTED METHODS: ---------------------------------------------------------------------

        protected DatabaseDialogue.ConfigData GetConfigData()
        {
            DatabaseDialogue.ConfigData defaultConfig = DatabaseDialogue.Load().defaultConfig;
            DatabaseDialogue.ConfigData result        = new DatabaseDialogue.ConfigData(defaultConfig);

            if (this.dialogue.overrideConfig)
            {
                if (this.dialogue.config.dialogueSkin != null)
                {
                    result.dialogueSkin = this.dialogue.config.dialogueSkin;
                }

                result.skipKey = this.dialogue.config.skipKey;
                result.revisitChoiceOpacity = this.dialogue.config.revisitChoiceOpacity;

                result.enableTypewriterEffect = this.dialogue.config.enableTypewriterEffect;
                result.charactersPerSecond    = this.dialogue.config.charactersPerSecond;
            }

            if (this.overrideDefaultConfig)
            {
                if (this.config.dialogueSkin != null)
                {
                    result.dialogueSkin = this.config.dialogueSkin;
                }

                result.skipKey = this.config.skipKey;
                result.revisitChoiceOpacity = this.config.revisitChoiceOpacity;

                result.enableTypewriterEffect = this.config.enableTypewriterEffect;
                result.charactersPerSecond    = this.config.charactersPerSecond;
            }

            return(result);
        }
コード例 #2
0
        protected bool SetupChoices(DialogueItemChoiceGroup item, DatabaseDialogue.ConfigData config)
        {
            this.CleanChoices();
            int choicesSetup = 0;

            for (int i = 0; i < item.children.Count; ++i)
            {
                DialogueItemChoice choice = item.children[i] as DialogueItemChoice;
                if (!choice || (choice.showOnce && choice.IsRevisit()))
                {
                    continue;
                }

                bool conditions = choice.CheckConditions();
                if (!conditions && choice.onFailChoice == DialogueItemChoice.FailChoiceCondition.HideChoice)
                {
                    continue;
                }

                GameObject choiceInstance = Instantiate <GameObject>(this.prefabChoice);
                choiceInstance.GetComponent <RectTransform>().SetParent(this.choiceContainer, false);

                DialogueChoiceUI choiceUI = choiceInstance.GetComponent <DialogueChoiceUI>();
                bool             disabled = (
                    !conditions &&
                    choice.onFailChoice == DialogueItemChoice.FailChoiceCondition.DisableChoice
                    );

                if (choiceUI != null)
                {
                    choiceUI.Setup(config, item, i, disabled);
                }
                choicesSetup++;
            }

            if (item.shuffleChoices)
            {
                this.ShuffleChoices();
            }

            if (this.choiceContainer.childCount > 0)
            {
                EventSystem.current.SetSelectedGameObject(null);

                if (DatabaseDialogue.Load().autoFocusFirstChoice)
                {
                    Transform selection = this.choiceContainer.GetChild(0);
                    EventSystem.current.SetSelectedGameObject(selection.gameObject);
                }
            }

            return(choicesSetup != 0);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: DialogueUI.cs プロジェクト: ISanchezV/ProjetMaster
        // 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);
        }
コード例 #5
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();
        }
コード例 #6
0
        // PROTECTED METHODS: ---------------------------------------------------------------------

        protected DatabaseDialogue.ConfigData GetConfigData()
        {
            DatabaseDialogue.ConfigData defaultConfig = DatabaseDialogue.Load().defaultConfig;
            DatabaseDialogue.ConfigData result        = defaultConfig;
            if (this.overrideDefaultConfig)
            {
                if (this.config.dialogueSkin != null)
                {
                    result.dialogueSkin = this.config.dialogueSkin;
                }
                result.enableTypewritterEffect = this.config.enableTypewritterEffect;
                result.charactersPerSecond     = this.config.charactersPerSecond;
            }

            return(result);
        }
コード例 #7
0
        // PROTECTED STATIC METHODS: ----------------------------------------------------------------

        protected static void RequireInstance(DatabaseDialogue.ConfigData config)
        {
            if (config.dialogueSkin == null)
            {
                Debug.LogError(ERR_NO_DIALOGUE_UI);
            }
            if (DialogueUI.Instance != null)
            {
                if (config.dialogueSkin.GetInstanceID() == PREFAB_INSTANCE_ID)
                {
                    return;
                }
                Destroy(DialogueUI.Instance.gameObject);
            }

            PREFAB_INSTANCE_ID = config.dialogueSkin.GetInstanceID();
            Instantiate(config.dialogueSkin, Vector3.zero, Quaternion.identity);
        }
コード例 #8
0
        // INITIALIZERS: --------------------------------------------------------------------------

        public void Setup(DatabaseDialogue.ConfigData config, DialogueItemChoiceGroup item,
                          int i, bool disabled)
        {
            this.text.text           = item.children[i].GetContent();
            this.button.interactable = !disabled;

            this.AssignButtonChoice(item, i);

            if (item.children[i].IsRevisit())
            {
                this.color.color = new Color(
                    this.color.color.r,
                    this.color.color.g,
                    this.color.color.b,
                    this.color.color.a * config.revisitChoiceOpacity
                    );
            }
        }
コード例 #9
0
        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;
            }));
        }
コード例 #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;
                }));
            }
        }
コード例 #11
0
        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
                    );
            }
        }