コード例 #1
0
    // Use this for initialization
    void Start()
    {
        //Read the XML document
        xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(XMLAsset.text);

        //Set references
        Transform content = dialogueBox.transform.FindChild("Content");

        dialogueBoxText = content.FindChild("Text").gameObject.GetComponent <Text>();
        dialogueBoxTextRectTransform = dialogueBoxText.gameObject.GetComponent <RectTransform>();
        face = content.FindChild("Head").gameObject.GetComponent <Image>();

        audio      = gameObject.GetComponent <AudioSource>();
        background = dialogueBox.transform.FindChild("background").gameObject.GetComponent <Image>();
        continueButtonController = dialogueBox.transform.FindChild("ContinueButtonController").gameObject;
        continueButtonKeyboard   = dialogueBox.transform.FindChild("ContinueButtonKeyboard").gameObject;

        //Initialize variables
        dialogueCharacterDB = new DialogueCharacterDB();

        //Make initial preparations
        state = dialogueBoxState.OFF;
        dialogueBox.SetActive(false);
        continueButtonController.SetActive(false);
        continueButtonKeyboard.SetActive(false);

        correctToResolution();
    }
コード例 #2
0
    public void callScene(int sceneNum)
    {
        //We read the scene text of the given id
        XmlNode scene = xmlDoc.SelectSingleNode("/Dialogue/Set[@lang = \"" + Configuration.getLanguage() + "\"]/Scene[@id = \"" + sceneNum + "\"]");

        //We add the lines to the message list
        for (int i = 0; i < scene.ChildNodes.Count; i++)
        {
            messageList.Add(scene.ChildNodes[i].InnerText);
        }

        //We prepare the text
        dialogueBox.SetActive(true);
        player.allowMovement = false;
        state = dialogueBoxState.PREPARE_TEXT;

        if (advanceBarEnemies != null)
        {
            advanceBarEnemies.Pause(true);
        }
    }
コード例 #3
0
ファイル: DialogueScript.cs プロジェクト: TeamGlitch/Glitch
	// Use this for initialization
	void Start () {

		//Read the XML document
		xmlDoc = new XmlDocument();
		xmlDoc.LoadXml(XMLAsset.text);

		//Set references
		Transform content = dialogueBox.transform.FindChild("Content");

		dialogueBoxText = content.FindChild("Text").gameObject.GetComponent<Text>();
		dialogueBoxTextRectTransform = dialogueBoxText.gameObject.GetComponent<RectTransform>();
		face = content.FindChild("Head").gameObject.GetComponent<Image>();

		audio = gameObject.GetComponent<AudioSource>();
		background = dialogueBox.transform.FindChild("background").gameObject.GetComponent<Image>();
		continueButtonController = dialogueBox.transform.FindChild("ContinueButtonController").gameObject;
        continueButtonKeyboard = dialogueBox.transform.FindChild("ContinueButtonKeyboard").gameObject;

		//Initialize variables
		dialogueCharacterDB = new DialogueCharacterDB();

		//Make initial preparations
		state = dialogueBoxState.OFF;
		dialogueBox.SetActive(false);
		continueButtonController.SetActive(false);
        continueButtonKeyboard.SetActive(false);

        correctToResolution();
	}
コード例 #4
0
ファイル: DialogueScript.cs プロジェクト: TeamGlitch/Glitch
	public void callScene(int sceneNum){

		//We read the scene text of the given id
    	XmlNode scene = xmlDoc.SelectSingleNode("/Dialogue/Set[@lang = \"" + Configuration.getLanguage() + "\"]/Scene[@id = \"" + sceneNum + "\"]");

		//We add the lines to the message list 
		for (int i = 0; i < scene.ChildNodes.Count; i++) {
			messageList.Add (scene.ChildNodes[i].InnerText);
		}

		//We prepare the text
		dialogueBox.SetActive(true);
        player.allowMovement = false;
		state = dialogueBoxState.PREPARE_TEXT;

        if(advanceBarEnemies != null)
            advanceBarEnemies.Pause(true);
	}
コード例 #5
0
ファイル: DialogueScript.cs プロジェクト: TeamGlitch/Glitch
	// Update is called once per frame
	void Update () {

        if (state != dialogueBoxState.OFF)
        {
            if(Camera.current != null && Camera.current.aspect != currentResolution)
                correctToResolution();
            if (audio.volume != SoundManager.instance.getSoundVolume())
                audio.volume = SoundManager.instance.getSoundVolume();
        }

		switch (state) {

			case dialogueBoxState.PREPARE_TEXT: //Preparing the message to write

				//Sets the message to print to the first message in the list
				messageToPrint = messageList[0];

				//Cleans the tags and stores it as the clean message
				letterIndex = 0;
				cleanMessage = "";
				while (letterIndex < messageToPrint.Length) {
                    if (messageToPrint[letterIndex] == '[')
                    {
                        preRead();
					} else {
                        cleanMessage += messageToPrint[letterIndex];
					}
                    letterIndex++;
				}

				//Sets the properties to default and starts writting
				letterIndex = -1;
				cleanIndex = -1;
				if(animationIndex != -1) animationIndex = 0;

				autoJump = false;
				waitBetweenLetters = defaultWaitBetweenLetters;
				skipable = true;

                dialogueBoxText.text = "";

				state = dialogueBoxState.WRITTING;

			break;

			case dialogueBoxState.WRITTING: //Currently writting in the dialogue box

				//If A is pressed, skip message
				if (InputManager.ActiveDevice.Action1.WasPressed && skipable) {
				
					letterIndex = messageToPrint.Length;
					nextLetterTime = 0;

				} 
				//If there's a face and it's time to put the next animation sprite
				else if (animationIndex != -1 && Time.time > nextAnimationStep) {
					
					//Get it's index
					animationIndex++;
					if (animationIndex == faceAnimationSprites.Count) {
						animationIndex = 0;
					}

					//Change the sprite and set the next change time
					face.sprite = faceAnimationSprites[animationIndex];
					nextAnimationStep = Time.time + faceAnimationSpeed;
				}
				
				//If we can print the next letter
				if (Time.time > nextLetterTime) {

					//Go to the next letter
					letterIndex++;
					cleanIndex++;

					//If the end has been reached
					if (letterIndex >= messageToPrint.Length) {

						//Put the message directly
						dialogueBoxText.text = cleanMessage;

						//Go to wait
						state = dialogueBoxState.WAITING;

						//If there's a face, stop the animation in the first frame
						if(animationIndex != -1) animationIndex = 0;
						face.sprite = faceAnimationSprites[0];

						//Remove the message from the list and activate the continue button (if it doesn't autojump)
						messageList.RemoveAt(0);
						if (!autoJump) {
                            if (InputManager.ActiveDevice.Name == "Keyboard/Mouse")
                                continueButtonKeyboard.SetActive(true);
                            else
							    continueButtonController.SetActive(true);
						}

					} else {

						//If not, we determine when the next letter will appear
						nextLetterTime = Time.time + waitBetweenLetters;
						
						//If the pointer is not visible, show it
						showPointerBug = true;

						//Read all the tags in this position (if there's any)
						while (letterIndex < messageToPrint.Length && messageToPrint[letterIndex] == '[') {
							ReadTag();
						}
						
						audio.Play();

						//We send the message to print with color tags that make it invisible from the print
						//letter to the end. We do this rather than doing subscripts because they mess the paragraph aligment
						string pointer = "";
						if (showPointerBug) {
							pointer += randomLetters[currentRandomLetter];
						}
						dialogueBoxText.text = cleanMessage.Insert(cleanIndex, pointer + "<color=#00000000>") + "</color>";

					}

				} else if (Time.time > nextBuggedLetterTime) {

					//We change the writting pointer's currently showed sign and we determine the next sign change
					if(showPointerBug){
						currentRandomLetter = Random.Range (0, randomLetters.Length);
						dialogueBoxText.text = cleanMessage.Insert(cleanIndex, randomLetters[currentRandomLetter] + "<color=#00000000>") + "</color>";
						nextBuggedLetterTime = Time.time + waitBetweenBuggedLetters;
					}
				}
					
			break;

			case dialogueBoxState.WAITING: //Message on dialogue box. Waiting for next instruction

				//The wait ends
				if (InputManager.ActiveDevice.Action1.WasPressed || autoJump) {

					corruptedPosition = -1;
					continueButtonController.SetActive(false);
                    continueButtonKeyboard.SetActive(false);

					//If there are more text, we return to the prepare_text state
					if (messageList.Count > 0) {
						state = dialogueBoxState.PREPARE_TEXT;
					} else {
                        if (advanceBarEnemies != null)
                            advanceBarEnemies.Pause(false);
						dialogueBox.SetActive(false);
						if (player.allowMovement == false) {
							player.allowMovement = true;
							player.playerActivedJump = true;
						}
                        state = dialogueBoxState.OFF;
					}

				} else {
				
					//If there is no corruption on the message
					if (corruptedPosition == -1) {

						//0.75% chance to corrupt a char
						if(Random.value > 0.9925f){

							//Selects a position, stores it's value and sets a duration
							corruptedPosition = Random.Range(0, dialogueBoxText.text.Length);
							originalChar = dialogueBoxText.text[corruptedPosition];
							timeToSolve = Time.time + Random.Range(0.05f, 0.4f);

							//Changes the position to a random symbol
							string newText = dialogueBoxText.text.Remove(corruptedPosition, 1);
							newText = newText.Insert(corruptedPosition, randomLetters[Random.Range(0, randomLetters.Length)]);
							dialogueBoxText.text = newText;
						}

					}
					//If there is corruption and its duration has ended
					else if (Time.time > timeToSolve){

						//Fixes the corrupted char
						string newText = dialogueBoxText.text.Remove(corruptedPosition, 1);
						newText = newText.Insert(corruptedPosition, originalChar.ToString());
						dialogueBoxText.text = newText;
						corruptedPosition = -1;

					}
				}

			break;

		}
	}
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        if (state != dialogueBoxState.OFF)
        {
            if (Camera.current != null && Camera.current.aspect != currentResolution)
            {
                correctToResolution();
            }
            if (audio.volume != SoundManager.instance.getSoundVolume())
            {
                audio.volume = SoundManager.instance.getSoundVolume();
            }
        }

        switch (state)
        {
        case dialogueBoxState.PREPARE_TEXT:                 //Preparing the message to write

            //Sets the message to print to the first message in the list
            messageToPrint = messageList[0];

            //Cleans the tags and stores it as the clean message
            letterIndex  = 0;
            cleanMessage = "";
            while (letterIndex < messageToPrint.Length)
            {
                if (messageToPrint[letterIndex] == '[')
                {
                    preRead();
                }
                else
                {
                    cleanMessage += messageToPrint[letterIndex];
                }
                letterIndex++;
            }

            //Sets the properties to default and starts writting
            letterIndex = -1;
            cleanIndex  = -1;
            if (animationIndex != -1)
            {
                animationIndex = 0;
            }

            autoJump           = false;
            waitBetweenLetters = defaultWaitBetweenLetters;
            skipable           = true;

            dialogueBoxText.text = "";

            state = dialogueBoxState.WRITTING;

            break;

        case dialogueBoxState.WRITTING:                 //Currently writting in the dialogue box

            //If A is pressed, skip message
            if (InputManager.ActiveDevice.Action1.WasPressed && skipable)
            {
                letterIndex    = messageToPrint.Length;
                nextLetterTime = 0;
            }
            //If there's a face and it's time to put the next animation sprite
            else if (animationIndex != -1 && Time.time > nextAnimationStep)
            {
                //Get it's index
                animationIndex++;
                if (animationIndex == faceAnimationSprites.Count)
                {
                    animationIndex = 0;
                }

                //Change the sprite and set the next change time
                face.sprite       = faceAnimationSprites[animationIndex];
                nextAnimationStep = Time.time + faceAnimationSpeed;
            }

            //If we can print the next letter
            if (Time.time > nextLetterTime)
            {
                //Go to the next letter
                letterIndex++;
                cleanIndex++;

                //If the end has been reached
                if (letterIndex >= messageToPrint.Length)
                {
                    //Put the message directly
                    dialogueBoxText.text = cleanMessage;

                    //Go to wait
                    state = dialogueBoxState.WAITING;

                    //If there's a face, stop the animation in the first frame
                    if (animationIndex != -1)
                    {
                        animationIndex = 0;
                    }
                    face.sprite = faceAnimationSprites[0];

                    //Remove the message from the list and activate the continue button (if it doesn't autojump)
                    messageList.RemoveAt(0);
                    if (!autoJump)
                    {
                        if (InputManager.ActiveDevice.Name == "Keyboard/Mouse")
                        {
                            continueButtonKeyboard.SetActive(true);
                        }
                        else
                        {
                            continueButtonController.SetActive(true);
                        }
                    }
                }
                else
                {
                    //If not, we determine when the next letter will appear
                    nextLetterTime = Time.time + waitBetweenLetters;

                    //If the pointer is not visible, show it
                    showPointerBug = true;

                    //Read all the tags in this position (if there's any)
                    while (letterIndex < messageToPrint.Length && messageToPrint[letterIndex] == '[')
                    {
                        ReadTag();
                    }

                    audio.Play();

                    //We send the message to print with color tags that make it invisible from the print
                    //letter to the end. We do this rather than doing subscripts because they mess the paragraph aligment
                    string pointer = "";
                    if (showPointerBug)
                    {
                        pointer += randomLetters[currentRandomLetter];
                    }
                    dialogueBoxText.text = cleanMessage.Insert(cleanIndex, pointer + "<color=#00000000>") + "</color>";
                }
            }
            else if (Time.time > nextBuggedLetterTime)
            {
                //We change the writting pointer's currently showed sign and we determine the next sign change
                if (showPointerBug)
                {
                    currentRandomLetter  = Random.Range(0, randomLetters.Length);
                    dialogueBoxText.text = cleanMessage.Insert(cleanIndex, randomLetters[currentRandomLetter] + "<color=#00000000>") + "</color>";
                    nextBuggedLetterTime = Time.time + waitBetweenBuggedLetters;
                }
            }

            break;

        case dialogueBoxState.WAITING:                 //Message on dialogue box. Waiting for next instruction

            //The wait ends
            if (InputManager.ActiveDevice.Action1.WasPressed || autoJump)
            {
                corruptedPosition = -1;
                continueButtonController.SetActive(false);
                continueButtonKeyboard.SetActive(false);

                //If there are more text, we return to the prepare_text state
                if (messageList.Count > 0)
                {
                    state = dialogueBoxState.PREPARE_TEXT;
                }
                else
                {
                    if (advanceBarEnemies != null)
                    {
                        advanceBarEnemies.Pause(false);
                    }
                    dialogueBox.SetActive(false);
                    if (player.allowMovement == false)
                    {
                        player.allowMovement     = true;
                        player.playerActivedJump = true;
                    }
                    state = dialogueBoxState.OFF;
                }
            }
            else
            {
                //If there is no corruption on the message
                if (corruptedPosition == -1)
                {
                    //0.75% chance to corrupt a char
                    if (Random.value > 0.9925f)
                    {
                        //Selects a position, stores it's value and sets a duration
                        corruptedPosition = Random.Range(0, dialogueBoxText.text.Length);
                        originalChar      = dialogueBoxText.text[corruptedPosition];
                        timeToSolve       = Time.time + Random.Range(0.05f, 0.4f);

                        //Changes the position to a random symbol
                        string newText = dialogueBoxText.text.Remove(corruptedPosition, 1);
                        newText = newText.Insert(corruptedPosition, randomLetters[Random.Range(0, randomLetters.Length)]);
                        dialogueBoxText.text = newText;
                    }
                }
                //If there is corruption and its duration has ended
                else if (Time.time > timeToSolve)
                {
                    //Fixes the corrupted char
                    string newText = dialogueBoxText.text.Remove(corruptedPosition, 1);
                    newText = newText.Insert(corruptedPosition, originalChar.ToString());
                    dialogueBoxText.text = newText;
                    corruptedPosition    = -1;
                }
            }

            break;
        }
    }