Beispiel #1
0
    public void PositionDialogue(DialogueGroup group)
    {
        RectTransform rect = (RectTransform)group.transform;

        rect.SetParent(transform);
        rect.anchorMin          = new Vector2(0.5f, 1);
        rect.anchorMax          = new Vector2(0.5f, 1);
        rect.anchoredPosition3D = Vector3.zero;
        rect.localScale         = Vector3.one;
    }
Beispiel #2
0
    public void Exit(System.Action onComplete)
    {
        // Check if we're a parent of a dialogue group - if so, unattach
        DialogueGroup group = GetComponentInChildren <DialogueGroup>();

        if (group != null)
        {
            group.transform.SetParent(MainSingleton.Instance.dialogueRunner.transform.root);
        }
        StartCoroutine(RunExit(onComplete));
    }
    public void StartDialogue(DialogueGroup dialogue)
    {
        dialogueAnim.SetBool("IsOpen", true);
        nameText.text = dialogue.name;
        sentences.Clear();
        foreach (string sentence in dialogue.sentences)
        {
            sentences.Enqueue(sentence);
        }

        DisplayNextSentence();
    }
Beispiel #4
0
    public void PositionDialogue(DialogueGroup group, string c)
    {
        CharacterName character = ParseChar(c);

        characterUiDictionary[character].PositionDialogue(group);
#if UNITY_EDITOR
        if (!characterUiDictionary.ContainsKey(character))
        {
            Debug.LogError($"Asking to position dialogue above {character.ToString()} but they're not being shown in scene {gameObject.scene.name}");
            return;
        }
#endif
    }
Beispiel #5
0
    public void SetCurrentDialogue(DialogueType type, string name = null)
    {
        DialogueGroup dialogueGroup = dialogueDictionary[type];

        if (dialogueGroup && dialogueGroup != currentDialogue)
        {
            currentDialogue?.TurnOff();
            dialogueGroup.TurnOn(this);
            currentDialogue = dialogueGroup;
        }
        // If dialogue is said by NPC, and we explicitly said who the NPC is, position above the NPC
        if (type == DialogueType.NPC && !string.IsNullOrEmpty(name))
        {
            MainSingleton.Instance.CharacterManager.PositionDialogue(dialogueGroup, name);
        }
    }
Beispiel #6
0
        public async Task SetPhase1GameOver(int type)
        {
            Data.StoryPhase = -1;
            var dialog = new DialogueGroup();

            if (type == 1)
            {
                dialog = JsonMapper.ToObject <DialogueGroup>(Resources.Load <TextAsset>("DayEvents/GameOver/Phase1_Human").text);
            }
            else
            {
                dialog = JsonMapper.ToObject <DialogueGroup>(Resources.Load <TextAsset>("DayEvents/GameOver/Phase1_Pig").text);
            }
            await RunDayDialogue(dialog, false, true);

            LoadRandomGameoverBag();
        }
        /// <summary>
        /// Initializes the dialogue groups cache by clearing it and then loading all elements from the database into it.
        /// </summary>
        /// <returns></returns>
        public static async Task InitializeCacheAsync()
        {
            try
            {
                _dialogueGroupsCache.Clear();

                using (SQLiteConnection connection = ConnectionProvider.GetConnection())
                {
                    await connection.OpenAsync();

                    using (SQLiteCommand command = new SQLiteCommand("", connection))
                    {
                        command.CommandText = string.Format("SELECT * FROM `{0}`", _tableName);

                        using (SQLiteDataReader reader = (SQLiteDataReader)await command.ExecuteReaderAsync())
                        {
                            if (reader.HasRows)
                            {
                                while (await reader.ReadAsync())
                                {
                                    DialogueGroup group = new DialogueGroup
                                    {
                                        Elements = (reader["Elements"] as string).Deserialize <List <string> >(),
                                        ID       = reader["ID"] as string
                                    };

                                    if (!_dialogueGroupsCache.TryAdd(group.ID, group))
                                    {
                                        throw new Exception("There was an error while attempting to load a group into the cache.");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Beispiel #8
0
        public async Task <bool> RunDayDialogue(DialogueGroup dialogGroup, bool playAppear, bool playDisappear, bool writeLog = true)
        {
            int mynum = MasterGameNum;

            if (playAppear)
            {
                await DialogAnimation.Appear();
            }
            bool selectRes = false;

            for (int i = 0; i < dialogGroup.Length; i++)
            {
                if (mynum != MasterGameNum)
                {
                    return(false);
                }
                var dialog = dialogGroup[i];
                if (dialog.Type == 0)
                {
                    await DialogueManager.Instance.ShowDialogue(dialog.Talker, dialog.Context, dialog.Unskippable);
                }
                else if (dialog.Type == 1) // 대전제: 선택은 한 차례만 한다.
                {
                    var res = await DialogueManager.Instance.ShowInteraction(new[] { dialog.Selects[0].Context, dialog.Selects[1].Context });

                    selectRes = dialog.Selects[res].IsTrigger;
                    for (int j = 0; j < Data.Variables.Length; j++)
                    {
                        if (j < 2)
                        {
                            Data.Variables[j] += (int)(dialog.Selects[res].VariableDelta[j] * 1.5f);
                        }
                        else
                        {
                            Data.Variables[j] += dialog.Selects[res].VariableDelta[j];
                        }
                        if (Data.Variables[j] > 100)
                        {
                            Data.Variables[j] = 100;
                        }
                        if (Data.Variables[j] < 0)
                        {
                            Data.Variables[j] = 0;
                        }

                        // 예외 케이스
                        if (dialog.Selects[res].VariableDelta[0] == 6 && dialog.Selects[res].VariableDelta[1] == 6)
                        {
                            Data.Variables[0] = 50;
                            Data.Variables[1] = 50;
                        }
                    }
                    if (writeLog)
                    {
                        Data.DayLog.Add(new SelectionLog(Data.CurrentStoryType, Data.DayCount, dialog.Selects[res].Context, dialog.Selects[res].VariableDelta));
                    }
                    for (int j = 0; j < dialog.Selects[res].Length; j++)
                    {
                        var afterDialog = dialog.Selects[res][j];
                        if (afterDialog.Type == 0)
                        {
                            await DialogueManager.Instance.ShowDialogue(afterDialog.Talker, afterDialog.Context, afterDialog.Unskippable);
                        }
                        else if (afterDialog.Type == 2)
                        {
                            DialogueManager.Instance.ShowImage(afterDialog.ImageKey);
                        }
                        else if (afterDialog.Type == 3)
                        {
                            SoundManager.Instance.PlayBgm(afterDialog.BgmKey);
                        }
                        else if (afterDialog.Type == 4)
                        {
                            SoundManager.Instance.PlaySe(afterDialog.SEKey);
                        }
                    }
                }
                else if (dialog.Type == 2)
                {
                    DialogueManager.Instance.ShowImage(dialog.ImageKey);
                }
                else if (dialog.Type == 3)
                {
                    SoundManager.Instance.PlayBgm(dialog.BgmKey);
                }
                else if (dialog.Type == 4)
                {
                    SoundManager.Instance.PlaySe(dialog.SEKey);
                }
            }
            DialogueManager.Instance.CleanDialogue();
            if (playDisappear)
            {
                await DialogAnimation.Disappear();
            }
            return(selectRes);
        }
Beispiel #9
0
 public bool TryGetConversation(string conversationName, out DialogueGroup conversation)
 {
     return(allConversations.TryGetValue(conversationName, out conversation));
 }