Unverified Commit 9f9dedba authored by Gerard Gascón's avatar Gerard Gascón Committed by GitHub
Browse files

Removed old scripts

parent 0e8b8b18
Loading
Loading
Loading
Loading
+0 −75
Original line number Diff line number Diff line
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class DialogueSystem : MonoBehaviour{

    public static DialogueSystem instance;

    public GameObject nameField = default;
    public TextMeshProUGUI nameText = default;
    public TMP_Animated dialogue = default;
    public Image faceImage = default;

    Queue<string> sentences;
    bool talking;
    Animator anim;

    void Awake(){
        instance = this;
        sentences = new Queue<string>();
        anim = GetComponent<Animator>();
    }

    /// <summary>Start or continue the dialogue
    /// <para>This function returns false if the dialogue has ended.</para>
    /// </summary>
    public bool Dialogue(Dialogue dialogue){
        if(!talking){
            if (dialogue.displayName){
                nameText.text = dialogue.characterName;
                nameField.SetActive(true);
                nameText.gameObject.SetActive(true);
            }else{
                nameField.SetActive(false);
                nameText.gameObject.SetActive(false);
            }

            if (dialogue.characterImage)
                faceImage.sprite = dialogue.characterImage;
            else
                faceImage.sprite = null;

            sentences.Clear();
            if(dialogue.sentences.Length != 0){
                foreach (string sentence in dialogue.sentences){
                    sentences.Enqueue(sentence);
                }
            }else{
                sentences.Enqueue("I am error. No text has been added");
            }
            talking = true;

            if(sentences.Count == 0){
                talking = false;
                return false;
            }

            string sentenceToShow = sentences.Dequeue();
            this.dialogue.ReadText(sentenceToShow);
            anim.SetBool("Talking", true);
            return true;
        }else{
            if (sentences.Count == 0){
                talking = false;
                anim.SetBool("Talking", false);
                return false;
            }

            string sentenceToShow = sentences.Dequeue();
            this.dialogue.ReadText(sentenceToShow);
            return true;
        }
    }
}
+0 −11
Original line number Diff line number Diff line
fileFormatVersion: 2
guid: caad12703fd5c3349acc637253734ac9
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 
+0 −78
Original line number Diff line number Diff line
using System.Collections;
using UnityEngine;
using UnityEngine.Events;

namespace TMPro{
    [System.Serializable] public class TextRevealEvent : UnityEvent<char> { }
    [System.Serializable] public class DialogueEvent : UnityEvent { }

    public class TMP_Animated : TextMeshProUGUI{

        float speed = 20;

        public TextRevealEvent onTextReveal;
        public DialogueEvent onDialogueFinish;

		void Update(){
            /*if(Application.isPlaying)
                this.Animate();*/
        }

		public void ReadText(string newText){
            text = string.Empty;

            string[] subTexts = newText.Split('<', '>');

            string displayText = "";
            for (int i = 0; i < subTexts.Length; i++){
                if (i % 2 == 0)
                    displayText += subTexts[i];
                else if (!isCustomTag(subTexts[i].Replace(" ", "")))
                    displayText += $"<{subTexts[i]}>";
            }

            bool isCustomTag(string tag){
                return tag.StartsWith("speed=") || tag.StartsWith("pause=") || tag.StartsWith("wave") || tag.StartsWith("rainbow") || tag.StartsWith("shake");
            }

            text = displayText;
            maxVisibleCharacters = 0;
            StartCoroutine(Read());

            IEnumerator Read(){
                int subCounter = 0;
                int visibleCounter = 0;
                while(subCounter < subTexts.Length){
                    if(subCounter % 2 == 1){
                        yield return EvaluateTag(subTexts[subCounter].Replace(" ", ""));
                    }else{
                        while(visibleCounter < subTexts[subCounter].Length){
                            onTextReveal.Invoke(subTexts[subCounter][visibleCounter]);
                            visibleCounter++;
                            maxVisibleCharacters++;
                            //this.Animate();

                            yield return new WaitForSeconds(text[maxVisibleCharacters - 1] == ' ' ? 0 : (1f / speed));
                        }
                        visibleCounter = 0;
                    }
                    subCounter++;
                }
                yield return null;

                WaitForSeconds EvaluateTag(string tag){
                    if (tag.Length > 0){
                        if (tag.StartsWith("speed=")){
                            speed = float.Parse(tag.Split('=')[1]);
                        }else if (tag.StartsWith("pause=")){
                            return new WaitForSeconds(float.Parse(tag.Split('=')[1]));
                        }
                    }
                    return null;
                }

                onDialogueFinish.Invoke();
            }
        }
    }
}
+0 −11
Original line number Diff line number Diff line
fileFormatVersion: 2
guid: f713d84a3ae882945800780459e26170
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {fileID: 2800000, guid: 2fd6421f253b4ef1a19526541f9ffc0c, type: 3}
  userData: 
  assetBundleName: 
  assetBundleVariant: