/// <summary> /// Loads the next line from the fileLines array /// </summary> void LoadNewLine() { // Split the line into its components and store them parsedText = fileLines[currentLine].Split('|'); currentLine++; bool sameChar = false; // Check if it's the same character if (currentCharacter) { sameChar = currentCharacter.name == parsedText[0]; } // Set the variables currentCharacter = characterDictionary[parsedText[0]]; characterName = currentCharacter.name; characterExpression = parsedText[1].ToLower(); characterDialogue = parsedText[2]; if (sameChar) { StartDisplaying(); } else { UIManager.m_Instance.SwapDialogue(currentCharacter.m_UiData); } }
public void EndScene() { Debug.Log($"<color=#5cd3e0>[Dialogue]</color> Finished dialogue {sceneName.name}"); LeanTween.alphaCanvas(darkenedBackground, 0.0f, 0.2f); if (blur) { LeanTween.value(blur.gameObject, Blur, 1, 0, 0.2f); } StopCoroutine(displayDialogueCoroutine); // Stops the typing out dialogueBox.text = characterDialogue; // Fills the textbox with the entirety of the character's line isDisplayingText = false; // Marks the system as no longer typing out currentLine = fileLines.Length; if (clearAfterScene) // Clears the scene if told to { sceneName = null; } UIManager.m_Instance.SwapFromDialogue(); leftCharacter = null; rightCharacter = null; UIManager.m_Instance.ShowTurnIndicator(); UIManager.m_Instance.m_ActiveUI = false; dialogueActive = false; LeanTween.size(bustL.rectTransform, defaultPortraitSize, 0.1f); LeanTween.size(bustR.rectTransform, defaultPortraitSize, 0.1f); UIManager.m_Instance.SlideElement(UIManager.m_Instance.m_LeftSpeaker, UIManager.ScreenState.Offscreen, ClearDialogueBox); UIManager.m_Instance.SlideElement(UIManager.m_Instance.m_RightSpeaker, UIManager.ScreenState.Offscreen); onFinishDialogueActions.Dequeue()?.Invoke(); if (sceneQueue.Count > 0) { TriggerDialogue(sceneQueue.Dequeue()); } }
/// <summary> /// Clears the dialogue box's name, dialogue and image /// </summary> void ClearDialogueBox() { bustL.sprite = null; bustR.sprite = null; nameBox.text = string.Empty; dialogueBox.text = string.Empty; currentCharacter = null; }
/// <summary> /// Converts the expression string into the associated Sprite variable in the given character. /// Returns the unknown character sprite if no associated character is found /// </summary> /// <returns></returns> Sprite GetCharacterPortrait(CharacterPortraitContainer character, string expression) { try { return((Sprite)typeof(CharacterPortraitContainer).GetField(expression).GetValue(character)); } catch (Exception exception) { if (exception is KeyNotFoundException) // Character not found - return default character sprite. { return(defaultCharacterSprite); } else if (exception is NullReferenceException) // Expression not found - return neutral. { return((Sprite)typeof(CharacterPortraitContainer).GetField("neutral").GetValue(character)); } else { throw exception; } } }
void Start() { LeanTouch.OnFingerSwipe += HandleFingerSwipe; characterPortraitContainer = GameObject.Find("Character Portrait Container").GetComponent <CharacterPortraitContainer>(); }
private void ManageDialoguePortrait(Side side) { // Set references CharacterPortraitContainer character; Image bust; UIManager.TweenedElement speaker; CharacterPortraitContainer otherCharacter; Image otherBust; UIManager.TweenedElement otherSpeaker; if (side == Side.Left) { character = leftCharacter; bust = bustL; speaker = UIManager.m_Instance.m_LeftSpeaker; leftCharacter = currentCharacter; otherCharacter = rightCharacter; otherBust = bustR; otherSpeaker = UIManager.m_Instance.m_RightSpeaker; nameHolder.anchoredPosition = namePos; } else { character = rightCharacter; bust = bustR; speaker = UIManager.m_Instance.m_RightSpeaker; rightCharacter = currentCharacter; otherCharacter = leftCharacter; otherBust = bustL; otherSpeaker = UIManager.m_Instance.m_LeftSpeaker; nameHolder.anchoredPosition = new Vector2(-namePos.x, namePos.y); } // Grey out the other character LeanTween.color(otherBust.rectTransform, Color.gray, 0.1f); LeanTween.color(bust.rectTransform, Color.white, 0.1f); // Swap portraits if (character == currentCharacter) { bust.sprite = GetCharacterPortrait(currentCharacter, characterExpression); // Grow the active speaker LeanTween.size(otherBust.rectTransform, defaultPortraitSize, 0.1f); LeanTween.size(bust.rectTransform, defaultPortraitSize * 1.1f, 0.1f); } else { LeanTween.color(otherBust.rectTransform, Color.gray, 0.1f); LeanTween.color(bust.rectTransform, Color.white, 0.1f); character = currentCharacter; UIManager.m_Instance.SlideElement(speaker, UIManager.ScreenState.Offscreen, () => { bust.sprite = GetCharacterPortrait(currentCharacter, characterExpression); UIManager.m_Instance.SlideElement(speaker, UIManager.ScreenState.Onscreen); // Grow the active speaker LeanTween.size(otherBust.rectTransform, defaultPortraitSize, 0.1f); LeanTween.size(bust.rectTransform, defaultPortraitSize * 1.1f, 0.1f); }); } }