예제 #1
0
        /// <summary>
        /// USED FROM A DIALOG ANSWER HANDLER
        /// Display the selected Dialog Line and procede to the next dialog set
        /// </summary>
        /// <param name="_line">The line to display</param>
        public IEnumerator DisplayDialogueLine(DialogueLine _line)
        {
            // Call the event
            OnDialogLineRead?.Invoke(_line.Key);
            // Change the color of the font if needed
            if (!DialoguesSettingsManager.DialogsSettings.OverrideCharacterColor)
            {
                if (DialoguesSettingsManager.DialogsSettings.CharactersColor.Any(c => c.CharacterIdentifier == _line.CharacterIdentifier))
                {
                    m_textDisplayer.color = DialoguesSettingsManager.DialogsSettings.CharactersColor.Where(c => c.CharacterIdentifier == _line.CharacterIdentifier).Select(c => c.CharacterColor).FirstOrDefault();
                }
                else
                {
                    m_textDisplayer.color = m_fontColor;
                }
            }
            else
            {
                m_textDisplayer.color = m_fontColor;
            }
            // Change the text of the text displayer
            m_textDisplayer.text = GetDialogueLineContent(_line.Key, DialoguesSettingsManager.DialogsSettings.CurrentLocalisationKey);
            // If there is an audiosource and the AudioClip Exists in the DialogsAssetsManager, play the audioclip in OneShot
            if (m_audioSource != null && DialogueAssetsManager.DialogLinesAudioClips.ContainsKey(_line.Key + "_" + DialoguesSettingsManager.DialogsSettings.CurrentAudioLocalisationKey))
            {
                m_audioSource.PlayOneShot(DialogueAssetsManager.DialogLinesAudioClips[_line.Key + "_" + DialoguesSettingsManager.DialogsSettings.CurrentAudioLocalisationKey]);
            }
            yield return(new WaitForSeconds(_line.InitialWaitingTime));

            // Go to the next set
            DialogueSet _nextSet = m_dialog.GetNextSet(_line.LinkedToken);

            DisplayDialogueSet(_nextSet);
        }
예제 #2
0
        /// <summary>
        /// Instanciate the loaded asset <see cref="m_dialogAnswerHandler"/> and Initialise it using the dialog <paramref name="_set"/>
        /// </summary>
        /// <param name="_set">Displayed Set</param>
        private void DisplayAnswerDialogueSet(DialogueSet _set)
        {
            m_onMouseClicked = null;
            Transform _canvas = FindObjectOfType <Canvas>().transform;

            Instantiate(DialogueAssetsManager.DialogAnswerHandler, _canvas).GetComponent <DialogueAnswerHandler>().InitHandler(this, _set.DialogLines);
        }
예제 #3
0
 /// <summary>
 /// Remove the set
 /// </summary>
 /// <param name="_set">Set to remove</param>
 private void RemoveSet(DialogueSet _set)
 {
     if (m_dialogSets.Contains(_set))
     {
         m_dialogSets.Remove(_set);
     }
 }
예제 #4
0
        /// <summary>
        /// Display the whole dialog
        /// </summary>
        /// <returns></returns>
        public void StartDisplayingDialogue(DialogStarterEnum _starter)
        {
            if (m_dialog == null)
            {
                Debug.Log("Dialog is null");
                return;
            }
            m_onStartReading?.Invoke();
            // Get the Starting Dialog Set //
            DialogueSet _set = m_dialog.GetFirstSet(_starter);

            DisplayDialogueSet(_set);
        }
예제 #5
0
 /// <summary>
 /// Process the events of the Dialog
 /// </summary>
 /// <param name="_e">Current Event</param>
 /// <returns></returns>
 public bool ProcessEvent(Event _e)
 {
     if (m_dialogSets.Any(p => p.IsSelected) && _e.keyCode == KeyCode.Delete)
     {
         DialogueSet _selectedPart = m_dialogSets.Where(p => p.IsSelected).FirstOrDefault();
         m_dialogSets.Remove(_selectedPart);
         return(true);
     }
     if (m_dialogConditions.Any(c => c.IsSelected) && _e.keyCode == KeyCode.Delete)
     {
         DialogueCondition _selectedCondition = m_dialogConditions.Where(c => c.IsSelected).FirstOrDefault();
         m_dialogConditions.Remove(_selectedCondition);
         return(true);
     }
     if (_e.type == EventType.KeyDown && _e.control && _e.keyCode == KeyCode.S)
     {
         SaveDialog();
     }
     return(false);
 }
예제 #6
0
        /// <summary>
        /// Display the dialog set according to its type
        /// </summary>
        /// <param name="_set"></param>
        /// <param name="_index"></param>
        private void DisplayDialogueSet(DialogueSet _set, int _index = 0)
        {
            if (_set == null)
            {
                m_onEndReading?.Invoke();
                m_textDisplayer.text = string.Empty;
                return;
            }
            switch (_set.Type)
            {
            case DialogSetType.BasicType:
                if (_set.PlayRandomly)
                {
                    _index = _set.GetNextRandomIndex();
                }
                StartCoroutine(DisplayDialogueLineAtIndex(_set, _index));
                break;

            case DialogSetType.PlayerAnswer:
                DisplayAnswerDialogueSet(_set);
                break;
            }
        }
예제 #7
0
        /// <summary>
        /// Wait <paramref name="_waitingTime"/> seconds.
        /// Then Display the dialog line at the <paramref name="_index"/> Index of the <paramref name="_set"/>
        /// </summary>
        /// <param name="_set">Next set to display</param>
        /// <param name="_index">Index of the dialog line to display</param>
        /// <param name="_waitingTime">Time to wait before displaying</param>
        /// <returns></returns>
        private IEnumerator WaitBeforeDisplayDialogueSet(DialogueSet _set, int _index, float _waitingTime)
        {
            yield return(new WaitForSeconds(_waitingTime));

            DisplayDialogueSet(_set, _index);
        }
예제 #8
0
        /// <summary>
        /// Display the dialog line of the dialog set at the selected index
        /// </summary>
        /// <param name="_set">Displayed Dialog Set</param>
        /// <returns></returns>
        private IEnumerator DisplayDialogueLineAtIndex(DialogueSet _set, int _index = 0)
        {
            m_onMouseClicked = null;
            // Get the dialog line at the _index in the _set
            DialogueLine _line = _set.DialogLines[_index];

            // Call the event
            OnDialogLineRead?.Invoke(_line.Key);
            // Change the color of the font if needed
            if (!DialoguesSettingsManager.DialogsSettings.OverrideCharacterColor)
            {
                if (DialoguesSettingsManager.DialogsSettings.CharactersColor.Any(c => c.CharacterIdentifier == _line.CharacterIdentifier))
                {
                    m_textDisplayer.color = DialoguesSettingsManager.DialogsSettings.CharactersColor.Where(c => c.CharacterIdentifier == _line.CharacterIdentifier).Select(c => c.CharacterColor).FirstOrDefault();
                }
                else
                {
                    m_textDisplayer.color = m_fontColor;
                }
            }
            else
            {
                m_textDisplayer.color = m_fontColor;
            }
            // Change the text of the text displayer
            m_textDisplayer.text = GetDialogueLineContent(_line.Key, DialoguesSettingsManager.DialogsSettings.CurrentLocalisationKey);
            // If there is an audiosource and the AudioClip Exists in the DialogsAssetsManager, play the audioclip in OneShot
            if (m_audioSource != null && DialogueAssetsManager.DialogLinesAudioClips.ContainsKey(_line.Key + "_" + DialoguesSettingsManager.DialogsSettings.CurrentAudioLocalisationKey))
            {
                AudioClip _c = DialogueAssetsManager.DialogLinesAudioClips[_line.Key + "_" + DialoguesSettingsManager.DialogsSettings.CurrentAudioLocalisationKey];

                m_audioSource.PlayOneShot(_c);
                yield return(new WaitForSeconds(_c.length + .05f));
            }
            else
            {
                yield return(new WaitForSeconds(_line.InitialWaitingTime));
            }

            // Increase Index
            _index++;
            //Check if we reach the end of the set and go to the next set
            if (_set.DialogLines.Count == _index && !_set.PlayRandomly)
            {
                _set   = m_dialog.GetNextSet(_line.LinkedToken);
                _index = 0;
            }
            else if (_set.PlayOnlyOneLine || (_set.PlayRandomly && _set.RemainingIndexesCount == 0))
            {
                _set   = m_dialog.GetNextSet(_set.DialogLines.Last().LinkedToken);
                _index = 0;
            }

            switch (_line.WaitingType)
            {
            case WaitingType.None:
                DisplayDialogueSet(_set, _index);
                break;

            case WaitingType.WaitForClick:
                m_onMouseClicked += () => DisplayDialogueSet(_set, _index);
                break;

            case WaitingType.WaitForTime:
                StartCoroutine(WaitBeforeDisplayDialogueSet(_set, _index, _line.ExtraWaitingTime));
                break;

            default:
                break;
            }
        }