Пример #1
0
 public void PlayDialogue(DialogueElement dialogueElement)
 {
     dialogueElement.SetImportance();
     if (_currentDialogueElement == null)
     {
         //Debug.Log("FIRST DIALOGUE " + dialogueElement + " is playing");
         QueueDialogueElement(dialogueElement);
     }
     else if (_currentDialogueElement.CanBeInterrupted == false && dialogueElement.important)
     {
         //Debug.Log("Important sound is already playing, new important sound: " + dialogueElement + " has been queued");
         QueueDialogueElementTopAndRemoveNonImportant(dialogueElement);
     }
     else if (_currentDialogueElement.CanBeInterrupted == false && dialogueElement.important == false)
     {
         //Debug.Log("Important sound is playing, non important VO " + dialogueElement + " has been queued");
         QueueDialogueElement(dialogueElement);
     }
     else if (_currentDialogueElement.CanBeInterrupted)
     {
         if (dialogueElement.CanInterrupt)
         {
             //Debug.Log("Important VO: " + dialogueElement + " has interrupted non important VO: " + _currentDialogueElement);
             audioManager.StopIfPlaying(_currentDialogueElement.voFile);
             StopCoroutine(_currentCoroutine);
             _queueIsRunning = false;
             QueueDialogueElementTopAndRemoveNonImportant(dialogueElement);
         }
         else if (dialogueElement.CanInterrupt == false)
         {
             //Debug.Log("Non important VO: " + dialogueElement + " has been queued after non important");
             QueueDialogueElement(dialogueElement);
         }
     }
 }
Пример #2
0
    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.tag == "NPC")
        {
            if ((Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.E) || Input.GetMouseButtonDown(0)))
            {
                dialogueElement = other.gameObject.GetComponent <DialogueElement>();
                if (!talkingToNPC)
                {
                    talkingToNPC = true;
                    StartDialogue();
                }
                else
                {
                    DisplayNextSentence();
                }

                if (!Data.npcsInTown.Contains(dialogueElement.CharacterPrefab))
                {
                    //Data.npcsInTown.Add(dialogueElement.CharacterPrefab);
                    Data.npcsInTown.Add(dialogueElement.CharacterPrefab);
                    //Resources.Load(this.gameObject.name);
                }
            }
        }
    }
Пример #3
0
 public void Display(DialogueElement element)
 {
     textBoxChar.text     = element.charInfo.speakingName;
     textBoxChar.color    = element.charInfo.color;
     charImg.sprite       = element.charInfo.sprite;
     textBoxDialogue.text = RemoveAndStoreTags(element.speakingDialogue);
     textBoxDialogue.maxVisibleCharacters = 0;
     StopEffects();
     if (element.puppet >= 0 && puppets[element.puppet] != null)
     {
         Image puppetImage = puppets[element.puppet].GetComponentsInChildren <Image>()[1];
         if (puppetImage.sprite != element.charInfo.sprite)
         {
             Vector3 tr = puppets[element.puppet].transform.eulerAngles;
             tr.y = 90;
             Sequence seq = DOTween.Sequence();
             seq.Append(puppets[element.puppet].transform.DORotate(tr, .2f));
             seq.AppendCallback(() => puppetImage.sprite = element.charInfo.sprite);
             seq.AppendInterval(.1f);
             tr.y = 0;
             seq.Append(puppets[element.puppet].transform.DORotate(tr, .1f));
             seq.AppendCallback(() => { StartTextEffects(); StartCoroutine(TypewriterText(element)); });
         }
         else
         {
             StartTextEffects();
             StartCoroutine(TypewriterText(element));
         }
     }
     else
     {
         StartTextEffects();
         StartCoroutine(TypewriterText(element));
     }
 }
Пример #4
0
 public void UpdateDialogue(DialogueElement current)
 {
     _isSpeaking = !current.IsCharacterTalking;
     if (_isSpeaking)
     {
         _imageBox.Image = _images[current.Expression];
     }
 }
 public void UpdateDialogue(DialogueElement current)
 {
     _isSpeaking = current.IsCharacterTalking;
     if (_isSpeaking)
     {
         _imageBox.Image = GameResources.GetCharacterImage(_character.Value, current.Expression);
     }
 }
Пример #6
0
    IEnumerator LoadingDialogueElement(DialogueElement element, string name)
    {
        yield return(new WaitForSecondsRealtime(decayTime));

        nameSlot.text = name;
        textSlot.text = element.characterLine;

        AdjustResponse(element);
    }
Пример #7
0
    /*
     * public DialogueHead DeserializeXMLDialogueLinq(TextAsset xmlDialogue){
     *      string xmlString = xmlDialogue.text;
     *
     *      Assembly assem = Assembly.GetExecutingAssembly ();
     *      XDocument xDoc = XDocument.Load (new StreamReader (xmlString));
     *
     *      DialogueHead dialogue = new DialogueHead();
     *      dialogue.NPCName = xDoc.Element("NPCName").Value;
     *      dialogue.FirstLineId = Int32.Parse(xDoc.Element("FirstLineId").Value);
     *
     *      dialogue.dialogueElements = xDoc.Descendants("DialogueElement").Select(element => {
     *              string typeName = element.Attribute("Type").Value;
     *              var type = assem.GetTypes().Where(t => t.Name == typeName).First();
     *              DialogueElement e = Activator.CreateInstance(type) as DialogueElement;
     *              foreach(var property in element.Descendants()){
     *                      type.GetProperty(property.Name.LocalName).SetValue(e, property.Value, null);
     *              }
     *              return e;
     *      }).ToArray();
     *
     *      return dialogue;
     * }
     */

    public DialogueHead DeserializeXMLDialogueLinq(string xmlDialoguePath)
    {
        //string xmlString = xmlDialogue.text;

        Assembly  assem = Assembly.GetExecutingAssembly();
        XDocument xDoc  = XDocument.Load(UnityEngine.Application.dataPath + xmlDialoguePath);

        DialogueHead dialogue = new DialogueHead();

        //Debug.Log (xDoc.Element("NPCName").Value);
        dialogue.NPCName     = xDoc.Descendants("NPCName").First().Value;
        dialogue.FirstLineId = Int32.Parse(xDoc.Descendants("FirstLineId").First().Value);

        dialogue.dialogueElements = xDoc.Descendants("DialogueElement").Select(element => {
            string typeName   = element.Attribute("Type").Value;
            var type          = assem.GetTypes().Where(t => t.Name == typeName).First();
            DialogueElement e = Activator.CreateInstance(type) as DialogueElement;
            Debug.Log("pass 0");
            foreach (var property in element.Descendants())
            {
                if (property.Name != "value")
                {
                    var setProp = type.GetProperty(property.Name.LocalName);
                    if (setProp.PropertyType.IsArray)
                    {
                        Debug.Log("Pass 1");
                        if (setProp.Name.Contains("Id"))
                        {
                            int[] i = property.Descendants("value").Select(v => { return(Int32.Parse(v.Value)); }).ToArray();
                            Debug.Log(i);
                            setProp.SetValue(e, i, null);
                        }
                        else
                        {
                            string[] s = property.Descendants("value").Select(v => v.Value).ToArray();
                            setProp.SetValue(e, s, null);
                            Debug.Log("Pass 2");
                        }
                    }
                    else
                    {
                        if (setProp.Name.Contains("Id"))
                        {
                            setProp.SetValue(e, Int32.Parse(property.Value), null);
                        }
                        else
                        {
                            setProp.SetValue(e, property.Value, null);
                        }
                    }
                }
            }
            return(e);
        }).ToArray();

        return(dialogue);
    }
Пример #8
0
 public void QueueDialogueElementTopAndRemoveNonImportant(DialogueElement dialogueElement)
 {
     RemoveAllNonImportantFromDialogueQueue();
     _dialogueElementsList.Add(dialogueElement);
     if (_queueIsRunning == false)
     {
         _queueIsRunning   = true;
         _currentCoroutine = StartCoroutine(IterateDialogueList());
     }
 }
Пример #9
0
        private DefaultChoiceElement CreateDefaultChoiceGUI(DialogueElement root, ConversationRow conversation,
                                                            ChoiceRow choice, IList <ContentElement> contents, string language)
        {
            var choiceElem = new DefaultChoiceElement();

            CreateChoiceContent(root.Header, choiceElem, conversation, choice, contents, language);

            root.Add(choiceElem);
            return(choiceElem);
        }
Пример #10
0
 private string GetDialogueTextInCurrentLanguage(DialogueElement elem)
 {
     if (language == "german")
     {
         return(elem.dialogueTextGerman);
     }
     else
     {
         return(elem.dialogueTextEnglish);
     }
 }
Пример #11
0
    IEnumerator PrintDialogueItem(DialogueElement elem)
    {
        string text = GetDialogueTextInCurrentLanguage(elem);

        dialogeFinishedPrinting = false;
        int j = 0;

        while (j < text.Length)
        {
            dialogueText.text += text[j];
            j++;
            yield return(new WaitForSeconds(elem.playbackSpeed));
        }
        dialogeFinishedPrinting = true;
    }
Пример #12
0
    public void SelectOption(int optionNumber)
    {
        DialogueOption options = (DialogueOption)currentLine;

        if (optionNumber > (options.Options.Length - 1))
        {
            EndDialogue();
        }
        else
        {
            currentLine = currentDialogue.FindLineById(options.DecisionLineIds [optionNumber]);
            CleanUpOptions();
            HandleDialogue();
        }
    }
Пример #13
0
 public void HandleDialogue()
 {
     if (currentLine.GetType() == typeof(DialogueLine))
     {
         DialogueLine line = (DialogueLine)currentLine;
         SetLine(line.Speaker, line.Text);
         return;
     }
     else if (currentLine.GetType() == typeof(DialogueIfBranch))
     {
         DialogueIfBranch ifLine = (DialogueIfBranch)currentLine;
         if (CheckConditions(ifLine.ConditionsToCheck, ifLine.CheckType))
         {
             if (ifLine.TrueLineId == 0)
             {
                 EndDialogue();
                 return;
             }
             currentLine = currentDialogue.FindLineById(ifLine.TrueLineId);
             HandleDialogue();
             return;
         }
         else if (ifLine.FalseLineId == 0)
         {
             EndDialogue();
             return;
         }
         else
         {
             currentLine = currentDialogue.FindLineById(ifLine.FalseLineId);
             ;
             HandleDialogue();
         }
         return;
     }
     else if (currentLine.GetType() == typeof(DialogueOption))
     {
         DialogueOption options = (DialogueOption)currentLine;
         SetLine(options.Speaker, options.Text);
         SetUpOptions(options);
         return;
     }
     else
     {
         EndDialogue();
     }
     return;
 }
Пример #14
0
    public void QueueDialogueElement(DialogueElement dialogueElement)
    {
        if (dialogueElement == null)
        {
            //Debug.Log("Dialogue Element: " + dialogueElement + " was not found, and could not be queued");
            return;
        }

        //Debug.Log("Dialogue Element: " + dialogueElement + " was queued");
        _dialogueElementsList.Add(dialogueElement);
        if (_queueIsRunning == false)
        {
            _queueIsRunning   = true;
            _currentCoroutine = StartCoroutine(IterateDialogueList());
        }
    }
Пример #15
0
        public void PostMessage([NotNull] DialogueElement message)
        {
            SetFriendIsTyping(false);

            var prefab = message.alignment == HorizontalPosition.Left
                ? leftAlignedPrefab
                : rightAlignedPrefab;

            var instance = Instantiate(prefab, contentParent);

            instance.GetComponentInChildren <TextMeshProUGUI>().text = Localization.Localization.Get(message.text);

            if (isActiveAndEnabled)
            {
                ScrollDown();
            }
        }
Пример #16
0
 // Start is called before the first frame update
 void Start()
 {
     canMoveCounter  = moveCoolDown;
     dialogueElement = GetComponent <DialogueElement>();
     if (motion == Motion.LeftRight)
     {
         motionPathTargets = LeftRight;
     }
     else if (motion == Motion.TopBottom)
     {
         motionPathTargets = TopBottom;
     }
     else if (motion == Motion.Circle)
     {
         motionPathTargets = Circle;
     }
 }
Пример #17
0
    public void AdvanceDialogue()
    {
        if (currentLine.SetWhenDone != null)
        {
            SetFlag(currentLine.SetWhenDone, currentLine.SetType);
            currentLine.TriggerPassed = true;
        }
        DialogueLine line = (DialogueLine)currentLine;

        if (line.NextLineId == 0)
        {
            EndDialogue();
        }
        else
        {
            currentLine = currentDialogue.FindLineById(line.NextLineId);
            Debug.Log("next line");
            HandleDialogue();
        }
    }
Пример #18
0
 public void PostMessage([NotNull] DialogueElement message)
 {
     openUI.PostMessage(message);
     if (!_isOpen)
     {
         closedUI.IncreaseNotificationCount();
         AudioManager.Instance.PlayPhoneNotificationSound();
     }
     else
     {
         if (message.alignment == HorizontalPosition.Left)
         {
             AudioManager.Instance.PlayPhoneOpenMessageReceivedSound();
         }
         else
         {
             AudioManager.Instance.PlayPhoneOpenMessageSentSound();
         }
     }
 }
Пример #19
0
    void AdjustResponse(DialogueElement element)
    {
        if (element.firstPlayerOption.isPositive)
        {
            currentPositiveResponse = element.firstPlayerOption;
        }
        else if (element.secondPlayerOption.isPositive)
        {
            currentPositiveResponse = element.secondPlayerOption;
        }

        if (!element.firstPlayerOption.isPositive)
        {
            currentNegativeResponse = element.firstPlayerOption;
        }
        else if (!element.secondPlayerOption.isPositive)
        {
            currentNegativeResponse = element.secondPlayerOption;
        }
    }
Пример #20
0
    private IEnumerator TypewriterText(DialogueElement element)
    {
        float lastTime = 0f;

        waiting = false;
        bool         displaying = true;
        TMP_TextInfo textInfo   = textBoxDialogue.textInfo;
        int          i          = 0;

        while (i <= textInfo.characterCount && displaying && !skip)
        {
            textBoxDialogue.maxVisibleCharacters = i;
            if (element.charInfo.sound != null)
            {
                audioSource.pitch = 1 + UnityEngine.Random.Range(-.17f, 0.17f);
                audioSource.PlayOneShot(element.charInfo.sound);
            }
            if (element.puppet != -1)
            {
                if (Time.time - lastTime > puppetMoveTime && puppets.Count > element.puppet)
                {
                    lastTime = Time.time;
                    Transform t = puppets[element.puppet].transform;
                    puppets[element.puppet].transform.DORotate(new Vector3(0, 0, Random.Range(-10f, 10f)), puppetMoveTime);
                    float y = puppets[element.puppet].transform.position.y;
                    DOTween.Sequence().Append(t.DOMoveY(y + 10, puppetMoveTime / 2f)).Append(t.DOMoveY(y, puppetMoveTime / 2f));
                }
            }
            i++;
            yield return(new WaitForSeconds(typewriterTime));
        }
        if (skip)
        {
            textBoxDialogue.maxVisibleCharacters = textInfo.characterCount;
        }

        skip    = false;
        waiting = true;
    }
Пример #21
0
    private IEnumerator IterateDialogueList()
    {
        while (_dialogueElementsList.Count != 0)
        {
            DialogueElement dialogueElement = _dialogueElementsList[0];
            //Debug.Log("Now playing: " + dialogueElement.voFile.name+" from queue");
            _currentDialogueElement = dialogueElement;
            if (_currentDialogueElement.triggerEventWithDelayFromStart)
            {
                _currentDialogueElement.SetStarted(true);
            }
            audioManager.PlaySound(dialogueElement.voFile);
            if (subtitlesActive)
            {
                StartCoroutine(subtitles.ConvertAndDisplaySubtitles(dialogueElement.subtitleText));
            }
            yield return(new WaitForSeconds(dialogueElement.voFile.source.clip.length + timeBetweenQueuedVo));

            if (_currentDialogueElement.triggerEventAtEnd)
            {
                _currentDialogueElement.SetEnded(true);
            }
            if (_dialogueElementsList.Count > 0)
            {
                try
                {
                    _dialogueElementsList.RemoveAt(0);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }
        _queueIsRunning = false;
        yield return(null);
    }
Пример #22
0
    /*
     * public int DialogueLength{
     *      get{ return currentDialogue.Length; }
     *      set { currentDialogue.Length = value; }
     * }
     */

    public void StartDialogue()
    {
        gameState = GameState.Dialogue;

        /*
         * DeserializeXMLDialogue (npcTarget.dialogueXMLPath);
         * if (gameState == GameState.Dialogue) {
         *      speakerName.text = currentDialogue.Speaker;
         *      dialogueText.text = currentDialogue.Speech [0];
         *      currentLine = 0;
         *      dialogueBox.SetActive (true);
         * }
         */
        if (npcTarget != null)
        {
            if (npcTarget.dialogueHead != null)
            {
                currentDialogue = npcTarget.dialogueHead;
                currentLine     = currentDialogue.FindLineById(currentDialogue.FirstLineId);
                dialogueBox.SetActive(true);
                HandleDialogue();
            }
        }
    }
Пример #23
0
    public void NextDialogueInQueue()
    {
        DialogueElement dialogueElement = _dialogueElementsQueue.Dequeue();

        PlayDialogue(dialogueElement);
    }
Пример #24
0
 public void LoadDialogueElement(DialogueElement element, string name, bool clearBox)
 {
     EnableMenu(true, clearBox);
     StartCoroutine(LoadingDialogueElement(element, name));
 }
Пример #25
0
    IEnumerator PrintDialogue(int startAt)
    {
        bool dialogueHasEnded = false;
        int  i = startAt;

        EnableBasicDialogue();
        while (!dialogueHasEnded)
        {
            DialogueElement currElement = dialogue.dialogueItems[i];
            if (!currElement.justCallMethode)
            {
                EnableBasicDialogue(false);
                string currentText = GetDialogueTextInCurrentLanguage(currElement);
                speakerName.text = currElement.speakerName;

                if (currElement.speakerPosition == DialogueElement.AvatarPos.left)
                {
                    var rotation = speakerLeft.transform.rotation;
                    speakerLeft.enabled = true;
                    speakerLeft.sprite  = currElement.speakerPic;

                    if (currElement.flipSpeakerPic)
                    {
                        speakerLeft.transform.rotation = new Quaternion(rotation.x, 180, rotation.z, rotation.w);
                    }
                    else
                    {
                        speakerLeft.transform.rotation = new Quaternion(rotation.x, 0, rotation.z, rotation.w);
                    }
                }
                else if (currElement.speakerPosition == DialogueElement.AvatarPos.right)
                {
                    var rotation = speakerRight.transform.rotation;
                    speakerRight.enabled = true;
                    speakerRight.sprite  = currElement.speakerPic;

                    if (currElement.flipSpeakerPic)
                    {
                        speakerRight.transform.rotation = new Quaternion(rotation.x, 180, rotation.z, rotation.w);
                    }
                    else
                    {
                        speakerRight.transform.rotation = new Quaternion(rotation.x, 0, rotation.z, rotation.w);
                    }
                }

                StartCoroutine("PrintDialogueItem", currElement);

                yield return(new WaitForSeconds(0.05f));

                while (!Input.GetButtonDown("Interact"))
                {
                    yield return(null);
                }

                //Print whole Dialogue Element after Interaced is pressed a second time
                if (!dialogeFinishedPrinting)
                {
                    StopCoroutine("PrintDialogueItem");
                    dialogueText.text = currentText;
                    yield return(new WaitForSeconds(0.05f));

                    while (!Input.GetButtonDown("Interact"))
                    {
                        yield return(null);
                    }
                }
                //ClenUp of old DialogueItem
                StopCoroutine("PrintDialogueItem");
                dialogueText.text = "";

                if (currElement.multiChoiceDialogue.Count > 0)
                {
                    isInMultiChoise = true;
                    SetMultiChoiceDialogue(currElement.multiChoiceDialogue);
                    while (isInMultiChoise)
                    {
                        yield return(null);
                    }
                }
            }

            //Call a methode before the next dialogue element
            if (currElement.nameOfMethodeToActivateBeforeNextText != "")
            {
                DisableCompleteDialogeBox();
                Type t = CallMethode(currElement.nameOfMethodeToActivateBeforeNextText);

                if (currElement.waitUntilMethodeIsFinished && t != null)
                {
                    PropertyInfo pI;

                    if (t != typeof(CutsceneActions))
                    {
                        pI = t.BaseType.GetProperty("CallFinished");
                    }
                    else
                    {
                        pI = t.GetProperty("CallFinished");
                    }

                    if (pI.PropertyType == typeof(bool))
                    {
                        while (!(bool)pI.GetValue(null))
                        {
                            yield return(new WaitForEndOfFrame());
                        }

                        pI.SetValue(null, false);
                    }
                    else
                    {
                        Debug.LogError("CallFinished of Property: " + pI.Name + " has the wrong Type. Must be bool.");
                    }
                }

                do
                {
                    yield return(new WaitForSeconds(currElement.waitForSecondsAfterMethodeFinished));
                } while (false);
            }

            i++;
            if (i >= dialogue.dialogueItems.Count)
            {
                dialogueHasEnded = true;
            }
        }

        if (dialogueEndedEventHandler != null)
        {
            dialogueEndedEventHandler.Invoke(this, null);
        }

        DisableCompleteDialogeBox();
    }
Пример #26
0
 /// <summary>
 /// Driver function to display a message and audio from the <c>DialogElement<c/> parameter.
 /// </summary>
 /// <param name="ele">The DialogElement containing the text and audio clip</param>
 public void GlobalMessage(DialogueElement ele)
 {
     m_GlobalMessageBoardText.text = ele.DialogueText;
     m_RobotAudioSource.clip       = ele.PlayBackSoundFile;
     m_RobotAudioSource.Play();
 }
    void ResolveNextID(DialogueElement element)
    {
        if (readyToCloseBranches) {
            CloseBranches(element.ID);
        }

        if (openLink != null) {
            openLink.Index = element.ID;
            openLink = null;
        }

        if (lastElement != null) {
            lastElement.DefaultNextID = element.ID;
        }

        thisElement = element;
        lastElement = element;
    }
 public BranchDialogueElementLink(DialogueElement ele, PhraseSequence prompt)
     : this(ele.ID, prompt)
 {
 }
 public void Break()
 {
     lastElement = null;
 }
Пример #30
0
        private DialogueElement CreateDialogueGUI(VisualElement root, ConversationRow conversation,
                                                  DialogueRow dialogue, IList <ContentElement> contents, string language)
        {
            var dialogueElem = new DialogueElement();

            var idElem = new IdElement {
                value = dialogue.Id
            };

            dialogueElem.Header.Add(idElem);

            var defaultChoiceData = dialogue.GetChoice(0);

            if (defaultChoiceData != null)
            {
                CreateDefaultChoiceGUI(dialogueElem, conversation, defaultChoiceData, contents, language);
            }

            if (dialogue.Choices.Count > 1)
            {
                var choiceContainer = new ChoiceContainer();
                choiceContainer.Add(new Label("Choices"));

                var first = true;

                foreach (var kv in dialogue.Choices)
                {
                    if (kv.Value.Id == 0)
                    {
                        continue;
                    }

                    var choiceElem = CreateChoiceGUI(choiceContainer, conversation, kv.Value, contents, language);

                    if (first)
                    {
                        first = false;
                        choiceElem.style.marginTop = 0;
                    }
                }

                dialogueElem.Add(choiceContainer);
            }

            if (!dialogue.IsEnd())
            {
                var sb        = new StringBuilder();
                var delayElem = new DelayElement("Delay")
                {
                    value = dialogue.Delay.ToString()
                };
                dialogueElem.Add(delayElem);

                var speakerElem = new SpeakerElement("Speaker")
                {
                    value = dialogue.Speaker
                };
                dialogueElem.Add(speakerElem);

                if (HasActors(dialogue))
                {
                    CreateCharacterTableGUI(dialogueElem, out var columnContainerElem);

                    CreateCharacterList <ActorColumnElement>(columnContainerElem, "Actor",
                                                             dialogue.Actor1, dialogue.Actor2, dialogue.Actor3, dialogue.Actor4);

                    CreateCharacterList <ActionColumnElement>(columnContainerElem, "Actions",
                                                              dialogue.Actions1.BuildString(sb), dialogue.Actions2.BuildString(sb),
                                                              dialogue.Actions3.BuildString(sb), dialogue.Actions4.BuildString(sb));
                }

                var highlightElem = new HighlightElement("Highlight")
                {
                    value = dialogue.Highlight.BuildString(sb)
                };
                dialogueElem.Add(highlightElem);
            }

            if (dialogue.CommandsOnStart.Count > 0 ||
                dialogue.CommandsOnEnd.Count > 0)
            {
                CreateCommandTableGUI(dialogueElem, dialogue.CommandsOnStart, dialogue.CommandsOnEnd);
            }

            root.Add(dialogueElem);
            return(dialogueElem);
        }
Пример #31
0
    public void _wm_say(string text, Sprite spr, bool touchToContinue)
    {
        if (topBarStatus == BarStatus.hidden)
        {
            _wm_showTopBar();
        }

        DialogueElement newElement;

        Image top, middle, bottom;
        Image topLeft, topRight, middleLeft, middleRight, bottomLeft, bottomRight;

        newElement         = new DialogueElement();
        newElement.element = DialogueElementType.text;

        //nextTextY = -295.0f; //////////////// REMOVE

        GameObject newGO = new GameObject();

        newGO.name = "Dialogue_bubble";


        GameObject newTopGO      = new GameObject();
        GameObject newTopLeftGO  = new GameObject();
        GameObject newTopRightGO = new GameObject();

        GameObject newMiddleGO      = new GameObject();
        GameObject newMiddleLeftGO  = new GameObject();
        GameObject newMiddleRightGO = new GameObject();

        GameObject newBottomGO      = new GameObject();
        GameObject newBottomLeftGO  = new GameObject();
        GameObject newBottomRightGO = new GameObject();



        GameObject newTextGO = new GameObject();

        GameObject newImageGO = new GameObject();


        //newGO.transform.localPosition = new Vector3 (0, 0, 0);

        top    = newTopGO.AddComponent <Image> ();
        middle = newMiddleGO.AddComponent <Image> ();
        bottom = newBottomGO.AddComponent <Image> ();

        topLeft  = newTopLeftGO.AddComponent <Image> ();
        topRight = newTopRightGO.AddComponent <Image> ();

        middleLeft  = newMiddleLeftGO.AddComponent <Image> ();
        middleRight = newMiddleRightGO.AddComponent <Image> ();

        bottomLeft  = newBottomLeftGO.AddComponent <Image> ();
        bottomRight = newBottomRightGO.AddComponent <Image> ();

        EventTrigger t;

        t = newTopGO.AddComponent <EventTrigger> ();
        EventTrigger.Entry entry = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerClick;
        switch (globalAnswerNumber)
        {
        case 1:
            entry.callback.AddListener(delegate {
                selectAnswer(1);
            });
            break;

        case 2:
            entry.callback.AddListener(delegate {
                selectAnswer(2);
            });
            break;

        case 3:
            entry.callback.AddListener(delegate {
                selectAnswer(3);
            });
            break;

        case 4:
            entry.callback.AddListener(delegate {
                selectAnswer(4);
            });
            break;

        case 5:
            entry.callback.AddListener(delegate {
                selectAnswer(5);
            });
            break;
        }
        t.triggers.Add(entry);
        t             = newMiddleGO.AddComponent <EventTrigger> ();
        entry         = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerClick;
        switch (globalAnswerNumber)
        {
        case 1:
            entry.callback.AddListener(delegate {
                selectAnswer(1);
            });
            break;

        case 2:
            entry.callback.AddListener(delegate {
                selectAnswer(2);
            });
            break;

        case 3:
            entry.callback.AddListener(delegate {
                selectAnswer(3);
            });
            break;

        case 4:
            entry.callback.AddListener(delegate {
                selectAnswer(4);
            });
            break;

        case 5:
            entry.callback.AddListener(delegate {
                selectAnswer(5);
            });
            break;
        }
        t.triggers.Add(entry);
        t             = newBottomGO.AddComponent <EventTrigger> ();
        entry         = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerClick;
        switch (globalAnswerNumber)
        {
        case 1:
            entry.callback.AddListener(delegate {
                selectAnswer(1);
            });
            break;

        case 2:
            entry.callback.AddListener(delegate {
                selectAnswer(2);
            });
            break;

        case 3:
            entry.callback.AddListener(delegate {
                selectAnswer(3);
            });
            break;

        case 4:
            entry.callback.AddListener(delegate {
                selectAnswer(4);
            });
            break;

        case 5:
            entry.callback.AddListener(delegate {
                selectAnswer(5);
            });
            break;
        }
        t.triggers.Add(entry);


        newGO.transform.parent = currentParent.transform;

        if (positionChanged)
        {
            switch (currentSpeaker)
            {
            case SpeakerPosition.left:
                topLeft.sprite  = LeftPoint; //Resources.Load<Sprite> ("Dialogue/ok/LeftTopPoint");
                topRight.sprite = TopRight;  //Resources.Load<Sprite> ("Dialogue/ok/RightTopCorner");
                break;

            case SpeakerPosition.right:
                topLeft.sprite  = TopLeft;    //Resources.Load<Sprite> ("Dialogue/ok/LeftTopCorner");
                topRight.sprite = RightPoint; //Resources.Load<Sprite> ("Dialogue/ok/RightTopPoint");
                break;

            case SpeakerPosition.center:
                topLeft.sprite  = TopLeft;  //.Load<Sprite> ("Dialogue/ok/LeftTopCorner");
                topRight.sprite = TopRight; //.Load<Sprite> ("Dialogue/ok/RightTopCorner");
                break;
            }
        }
        else
        {
            topLeft.sprite  = TopLeft;     //Resources.Load<Sprite> ("Dialogue/ok/LeftTopCorner");
            topRight.sprite = TopRight;    //Resources.Load<Sprite> ("Dialogue/ok/RightTopCorner");
        }
        top.sprite = TopCenter;            //Resources.Load<Sprite> ("Dialogue/ok/TopCenter");

        middle.sprite      = MiddleCenter; //Resources.Load<Sprite> ("Dialogue/ok/CenterCenter");
        middleLeft.sprite  = MiddleLeft;   //Resources.Load<Sprite> ("Dialogue/ok/LeftCenter");
        middleRight.sprite = MiddleRight;  //Resources.Load<Sprite> ("Dialogue/ok/RightCenter");

        bottom.sprite = BottomCenter;      //.Load<Sprite> ("Dialogue/ok/BottomCenter");

        bottomLeft.sprite  = BottomLeft;   //.Load<Sprite> ("Dialogue/ok/LeftBottomCorner");
        bottomRight.sprite = BottomRight;  //Resources.Load<Sprite> ("Dialogue/ok/RightBottomCorner");

        Image newImage = null;

        if (spr != null)
        {
            newImage        = newImageGO.AddComponent <Image> ();
            newImage.sprite = spr;
        }

        Text newText = newTextGO.AddComponent <Text> ();

        newText.text     = text;
        newText.fontSize = 26;

        t             = newTextGO.AddComponent <EventTrigger> ();
        entry         = new EventTrigger.Entry();
        entry.eventID = EventTriggerType.PointerClick;
        switch (globalAnswerNumber)
        {
        case 1:
            entry.callback.AddListener(delegate {
                selectAnswer(1);
            });
            break;

        case 2:
            entry.callback.AddListener(delegate {
                selectAnswer(2);
            });
            break;

        case 3:
            entry.callback.AddListener(delegate {
                selectAnswer(3);
            });
            break;

        case 4:
            entry.callback.AddListener(delegate {
                selectAnswer(4);
            });
            break;

        case 5:
            entry.callback.AddListener(delegate {
                selectAnswer(5);
            });
            break;
        }
        t.triggers.Add(entry);

        DialogueBlob newBlob = newGO.AddComponent <DialogueBlob> ();

        newBlob.dialogueObject = this;
        newBlob.readerMode     = readerMode;

        switch (currentSpeaker)
        {
        case SpeakerPosition.left:
            newBlob.theColor = leftColor;
            break;

        case SpeakerPosition.right:
            newBlob.theColor = rightColor;
            break;

        default:
            newBlob.theColor = centerColor;
            break;
        }

        newBlob.touchToContinue = touchToContinue;

        newBlob.isAnswerBlob = isAnswerBlob;

        newBlob.touchImage_0 = pressToContinue [0];
        newBlob.touchImage_1 = pressToContinue [1];

        top.transform.parent         = newGO.transform;
        middle.transform.parent      = newGO.transform;
        bottom.transform.parent      = newGO.transform;
        topLeft.transform.parent     = newGO.transform;
        middleLeft.transform.parent  = newGO.transform;
        bottomLeft.transform.parent  = newGO.transform;
        topRight.transform.parent    = newGO.transform;
        middleRight.transform.parent = newGO.transform;
        bottomRight.transform.parent = newGO.transform;

        newTextGO.transform.parent = newGO.transform;

        newBlob.theText   = newText;
        newBlob.textSpeed = globalTextSpeed;
        newBlob.text      = text;


        if (!usingAlienFont)           // Understandable
        {
            newText.font = NormalFont; //Resources.Load<Font> ("Fonts/GNUOLANE");
        }
        else                           // non-understandable
        {
            newText.font = AlienFont;  //.Load<Font> ("Fonts/PreAlphabet");
        }
        newText.color = Color.black;

        newText.alignment = TextAnchor.MiddleCenter;
        //newText.transform.position = new Vector3 (0, 0, 0);

        newBlob.theText = newText;


        float thisBubbleWidth;

        const float avgFontWidth = 14.0f;         // WARNING Magic??

        float textWidth = text.Length * avgFontWidth;

        thisBubbleWidth = textWidth;

        RectTransform rect = null;

        if (spr != null)
        {
            rect            = newImage.GetComponent <RectTransform> ();
            thisBubbleWidth = rect.sizeDelta.x;
        }
        //float MaxBubbleWidth = 600.0f;
        int nLines = (int)(textWidth / MaxBubbleWidth);

        thisBubbleHeight = 24.0f + 26.0f * nLines;


        if (textWidth < MinBubbleWidth)
        {
            thisBubbleWidth = MinBubbleWidth;
        }

        if (textWidth > MaxBubbleWidth)
        {
            thisBubbleWidth = MaxBubbleWidth;
            //int nExtraLines = ((int)(textWidth / MaxBubbleWidth));
            //thisBubbleHeight += nExtraLines * avgFontWidth; // also height
        }

        if (spr != null)
        {
            thisBubbleHeight = 16.0f + rect.sizeDelta.y;
        }

        //nextTextY = 0.0f;
        //targetScroll = 200.0f * 0.55f;

        if (prevBubbleHeight > 0.0f)
        {
            nextTextY -= ((thisBubbleHeight + 50.0f) / 2.0f + (prevBubbleHeight + 50.0f) / 2.0f);
            if (!positionChanged)
            {
                nextTextY += 6.0f;
            }
            positionChanged = false;
        }
        else
        {
            nextTextY      -= (thisBubbleHeight + 50.0f) / 2.0f;
            positionChanged = false;
        }

        while ((nextTextY - (thisBubbleHeight + 50.0f) / 2.0f + maxScroll) < -225)
        {
            maxScroll += 4.0f;
        }
        if (autoscroll)
        {
            targetScroll = maxScroll;
        }

        newBlob.centerYPos   = nextTextY;
        newBlob.bubbleHeight = thisBubbleHeight + 50.0f;

        //nextTextY -= (thisBubbleHeight+50.0f)/2.0f; //(thisBubbleHeight + 24.0f - nLines*5.0f) / 2.0f; // compensate for centered coordinates

        //nextTextY = 0.0f;

        /*newGO.AddComponent<RectTransform> ();
         *
         * newGO.GetComponent<RectTransform> ().anchorMax = new Vector2 (0, 1);
         * newGO.GetComponent<RectTransform> ().anchorMin = new Vector2 (0, 1);
         * newGO.GetComponent<RectTransform> ().pivot = new Vector2 (0, 0);*/

        newGO.name = newGO.name + "(H=" + thisBubbleHeight + ")";

        //float www;
        //www = Screen.width;
        //newGO.transform.localPosition = new Vector3 (0, nextTextY, 0);
        //newGO.GetComponent<RectTransform> ().anchoredPosition = new Vector2(0, nextTextY);
        if (currentSpeaker == SpeakerPosition.left)
        {
            //newGO.transform.localPosition = new Vector3 (-((float)Screen.width), 0, 0);// + thisBubbleWidth/2.0f + 15.0f, 0, 0); // + thisBubbleWidth/2.0f
            newGO.transform.localPosition = new Vector3(-bubbleContainerRef.GetComponent <RectTransform>().rect.width / 2.0f + thisBubbleWidth / 2.0f + 15.0f, 0, 0);
        }
        if (currentSpeaker == SpeakerPosition.right)
        {
            newGO.transform.localPosition = new Vector3(bubbleContainerRef.GetComponent <RectTransform>().rect.width / 2.0f - thisBubbleWidth / 2.0f - 86.0f, 0, 0);
        }
        if (currentSpeaker == SpeakerPosition.center)
        {
            newGO.transform.localPosition = new Vector3(0, 0, 0);
        }
        newTextGO.transform.localPosition   = new Vector3(32, nextTextY, 0);
        newTopGO.transform.localPosition    = new Vector3(32, 24.0f / 2.0f + thisBubbleHeight / 2.0f + nextTextY, 0);
        newMiddleGO.transform.localPosition = new Vector3(32, nextTextY, 0);
        newBottomGO.transform.localPosition = new Vector3(32, -24.0f / 2.0f - thisBubbleHeight / 2.0f + nextTextY, 0);

        newTopLeftGO.transform.localPosition    = new Vector3(-thisBubbleWidth / 2.0f + 32.0f / 2.0f, 24.0f / 2.0f + thisBubbleHeight / 2.0f + nextTextY, 0);
        newMiddleLeftGO.transform.localPosition = new Vector3(-thisBubbleWidth / 2.0f + 32.0f / 2.0f, nextTextY, 0);
        newBottomLeftGO.transform.localPosition = new Vector3(-thisBubbleWidth / 2.0f + 32.0f / 2.0f, -24.0f / 2.0f - thisBubbleHeight / 2.0f + nextTextY, 0);

        newTopRightGO.transform.localPosition    = new Vector3(32.0f + 32.0f / 2.0f + thisBubbleWidth / 2.0f, 24.0f / 2.0f + thisBubbleHeight / 2.0f + nextTextY, 0);
        newMiddleRightGO.transform.localPosition = new Vector3(32.0f + 32.0f / 2.0f + thisBubbleWidth / 2.0f, nextTextY, 0);
        newBottomRightGO.transform.localPosition = new Vector3(32.0f + 32.0f / 2.0f + thisBubbleWidth / 2.0f, -24.0f / 2.0f - thisBubbleHeight / 2.0f + nextTextY, 0);

        newText.GetComponent <RectTransform> ().sizeDelta     = new Vector2(thisBubbleWidth * 0.9f, 90.0f + thisBubbleHeight);
        newTopGO.GetComponent <RectTransform> ().sizeDelta    = new Vector2(thisBubbleWidth, 24);
        newMiddleGO.GetComponent <RectTransform> ().sizeDelta = new Vector2(thisBubbleWidth, thisBubbleHeight);
        newBottomGO.GetComponent <RectTransform> ().sizeDelta = new Vector2(thisBubbleWidth, 24);

        newTopLeftGO.GetComponent <RectTransform> ().sizeDelta    = new Vector2(32, 24);
        newMiddleLeftGO.GetComponent <RectTransform> ().sizeDelta = new Vector2(32, thisBubbleHeight);
        newBottomLeftGO.GetComponent <RectTransform> ().sizeDelta = new Vector2(32, 24);

        newTopRightGO.GetComponent <RectTransform> ().sizeDelta    = new Vector2(32, 24);
        newMiddleRightGO.GetComponent <RectTransform> ().sizeDelta = new Vector2(32, thisBubbleHeight);
        newBottomRightGO.GetComponent <RectTransform> ().sizeDelta = new Vector2(32, 24);

        if (spr != null)
        {
            newImageGO.transform.parent        = newGO.transform;
            newImageGO.transform.localPosition = new Vector3(32, nextTextY, 0);
        }

        newBlob.top         = top;
        newBlob.middle      = middle;
        newBlob.bottom      = bottom;
        newBlob.topLeft     = topLeft;
        newBlob.middleLeft  = middleLeft;
        newBlob.bottomLeft  = bottomLeft;
        newBlob.topRight    = topRight;
        newBlob.middleRight = middleRight;
        newBlob.bottomRight = bottomRight;
        newBlob.theText     = newText;
        newBlob.theParent   = this;

        newElement.data = text;

        elements.Add(newGO);
        elements.Add(newTopGO);
        elements.Add(newMiddleGO);
        elements.Add(newBottomGO);
        elements.Add(newTextGO);


        prevBubbleHeight = thisBubbleHeight;
    }