Add files via upload

This commit is contained in:
Gerard Gascón 2022-09-25 12:04:28 +02:00 committed by GitHub
parent ff9831ed0b
commit c6fe332009
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 4 deletions

View file

@ -101,7 +101,6 @@ Text commands:
<p:[tiny,short,normal,long,read]> --> Pauses during a period of time
<anim:[wobble,wave,rainbow,shake]></anim> --> Reproduces an animation
<sp:number></sp> --> Changes reveal speed
<snd:soundname> --> Plays a sound from the AudioManager
```
### SceneManager

View file

@ -13,6 +13,10 @@ namespace SimpleTools.DialogueSystem {
static readonly Regex pauseRegex = new Regex(PAUSE_REGEX_STRING);
const string SOUND_REGEX_STRING = "<snd:(?<sound>" + REMAINDER_REGEX + ")>";
static readonly Regex soundRegex = new Regex(SOUND_REGEX_STRING);
const string PLAYMUSIC_REGEX_STRING = "<playmsc:(?<playmusic>" + REMAINDER_REGEX + ")>";
static readonly Regex playMusicRegex = new Regex(PLAYMUSIC_REGEX_STRING);
const string STOPMUSIC_REGEX_STRING = "<stopmsc:(?<stopmusic>" + REMAINDER_REGEX + ")>";
static readonly Regex stopMusicRegex = new Regex(STOPMUSIC_REGEX_STRING);
const string SPEED_REGEX_STRING = "<sp:(?<speed>" + REMAINDER_REGEX + ")>";
static readonly Regex speedRegex = new Regex(SPEED_REGEX_STRING);
const string ANIM_START_REGEX_STRING = "<anim:(?<anim>" + 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<DialogueCommand> 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<DialogueCommand> 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 {

View file

@ -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);
}
}
}