diff --git a/README.md b/README.md index 9145486..b9678df 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,6 @@ Text commands: --> Pauses during a period of time --> Reproduces an animation --> Changes reveal speed - --> Plays a sound from the AudioManager ``` ### SceneManager @@ -143,4 +142,4 @@ timer.Restart(); //Restarts the timer You can easily set up some things by right clicking in your Project Tab and then selecting Tools and clicking on the one you want to create. -Also you can right click in the Hierarchy for easily creating some GameObjects with the Tools in it. +Also you can right click in the Hierarchy for easily creating some GameObjects with the Tools in it. \ No newline at end of file diff --git a/Tools/DialogueSystem/DialogueUtility.cs b/Tools/DialogueSystem/DialogueUtility.cs index 98a67c3..da1fff6 100644 --- a/Tools/DialogueSystem/DialogueUtility.cs +++ b/Tools/DialogueSystem/DialogueUtility.cs @@ -13,6 +13,10 @@ namespace SimpleTools.DialogueSystem { static readonly Regex pauseRegex = new Regex(PAUSE_REGEX_STRING); const string SOUND_REGEX_STRING = "" + REMAINDER_REGEX + ")>"; static readonly Regex soundRegex = new Regex(SOUND_REGEX_STRING); + const string PLAYMUSIC_REGEX_STRING = "" + REMAINDER_REGEX + ")>"; + static readonly Regex playMusicRegex = new Regex(PLAYMUSIC_REGEX_STRING); + const string STOPMUSIC_REGEX_STRING = "" + REMAINDER_REGEX + ")>"; + static readonly Regex stopMusicRegex = new Regex(STOPMUSIC_REGEX_STRING); const string SPEED_REGEX_STRING = "" + REMAINDER_REGEX + ")>"; static readonly Regex speedRegex = new Regex(SPEED_REGEX_STRING); const string ANIM_START_REGEX_STRING = "" + REMAINDER_REGEX + ")>"; @@ -34,6 +38,8 @@ namespace SimpleTools.DialogueSystem { processedMessage = HandlePauseTags(processedMessage, result); processedMessage = HandleSoundTags(processedMessage, result); + processedMessage = HandlePlayMusicTags(processedMessage, result); + processedMessage = HandleStopMusicTags(processedMessage, result); processedMessage = HandleSpeedTags(processedMessage, result); processedMessage = HandleAnimStartTags(processedMessage, result); processedMessage = HandleAnimEndTags(processedMessage, result); @@ -113,6 +119,34 @@ namespace SimpleTools.DialogueSystem { processedMessage = Regex.Replace(processedMessage, SOUND_REGEX_STRING, ""); return processedMessage; } + static string HandlePlayMusicTags(string processedMessage, List result) { + MatchCollection playMatches = playMusicRegex.Matches(processedMessage); + foreach (Match match in playMatches) { + string val = match.Groups["playmusic"].Value; + string functionName = val; + result.Add(new DialogueCommand { + position = VisibleCharactersUpToIndex(processedMessage, match.Index), + type = DialogueCommandType.PlayMusic, + stringValue = functionName + }); + } + processedMessage = Regex.Replace(processedMessage, PLAYMUSIC_REGEX_STRING, ""); + return processedMessage; + } + static string HandleStopMusicTags(string processedMessage, List result) { + MatchCollection stopMatches = stopMusicRegex.Matches(processedMessage); + foreach (Match match in stopMatches) { + string val = match.Groups["stopmusic"].Value; + string functionName = val; + result.Add(new DialogueCommand { + position = VisibleCharactersUpToIndex(processedMessage, match.Index), + type = DialogueCommandType.StopMusic, + stringValue = functionName + }); + } + processedMessage = Regex.Replace(processedMessage, STOPMUSIC_REGEX_STRING, ""); + return processedMessage; + } static TextAnimationType GetTextAnimationType(string stringVal) { TextAnimationType result; @@ -157,7 +191,9 @@ namespace SimpleTools.DialogueSystem { TextSpeedChange, AnimStart, AnimEnd, - Sound + Sound, + PlayMusic, + StopMusic } public enum TextAnimationType { diff --git a/Tools/DialogueSystem/DialogueVertexAnimator.cs b/Tools/DialogueSystem/DialogueVertexAnimator.cs index 24eb6e4..38d6008 100644 --- a/Tools/DialogueSystem/DialogueVertexAnimator.cs +++ b/Tools/DialogueSystem/DialogueVertexAnimator.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Globalization; using TMPro; using UnityEngine; @@ -137,6 +138,17 @@ namespace SimpleTools.DialogueSystem { case DialogueCommandType.Sound: AudioManager.AudioManager.instance.PlayOneShot(command.stringValue); break; + case DialogueCommandType.PlayMusic: + string[] split0 = command.stringValue.Split(','); + AudioManager.AudioManager.instance.FadeIn(split0[0], float.Parse(split0[1], CultureInfo.InvariantCulture)); + break; + case DialogueCommandType.StopMusic: + string[] split1 = command.stringValue.Split(','); + for (int j = 0; j < split1.Length; j++) { + Debug.Log(split1[j]); + } + AudioManager.AudioManager.instance.FadeOut(split1[0], float.Parse(split1[1], CultureInfo.InvariantCulture)); + break; } commands.RemoveAt(i); i--; @@ -194,7 +206,7 @@ namespace SimpleTools.DialogueSystem { TextAnimInfo info = textAnimInfo[i]; if (charIndex >= info.startIndex && charIndex < info.endIndex) { if (info.type == TextAnimationType.rainbow) { - color = Color.HSVToRGB(Mathf.Repeat((time + destinationVertice.x * RAINBOW_LENGTH_ADJUSTMENT), 1f), .6f, 1); + color = Color.HSVToRGB(Mathf.Repeat((time + destinationVertice.x * RAINBOW_LENGTH_ADJUSTMENT), 1f), .75f, 1); } } }