private UISoundData CompileSoundProperties(SoundRootNode soundRootNode) { UISoundData soundData = new UISoundData(); // set defaults soundData.duration = new UITimeMeasurement(1, UITimeMeasurementUnit.Percentage); soundData.pitch = 1; soundData.iterations = 1; soundData.tempo = 1; for (int i = 0; i < soundRootNode.children.Count; i++) { StyleASTNode property = soundRootNode.children[i]; if (property is SoundPropertyNode soundPropertyNode) { StyleASTNode value = soundPropertyNode.value; switch (soundPropertyNode.name.ToLower()) { case "asset": soundData.asset = StylePropertyMappers.MapString(value, context); break; case "duration": soundData.duration = StylePropertyMappers.MapUITimeMeasurement(value, context); break; case "iterations": soundData.iterations = (int)StylePropertyMappers.MapNumberOrInfinite(value, context); break; case "pitch": soundData.pitch = StylePropertyMappers.MapNumber(value, context); break; case "pitchrange": soundData.pitchRange = StylePropertyMappers.MapFloatRange(value, context); break; case "tempo": soundData.tempo = StylePropertyMappers.MapNumber(value, context); break; case "volume": soundData.volume = StylePropertyMappers.MapNumber(value, context); break; case "mixergroup": soundData.mixerGroup = StylePropertyMappers.MapString(value, context); break; } } else { throw new CompileException(property, "Expected a sound property."); } } return(soundData); }
private UISoundData CompileSound(SoundRootNode soundRootNode) { UISoundData data = CompileSoundProperties(soundRootNode); data.name = soundRootNode.identifier; data.styleSheetFileName = context.fileName; return(data); }
public void RunSound() { var nodes = StyleParser.Parse(@" sound notification { Asset = ""sounds/notification1""; MixerGroup = ""Master Group 1""; Duration = 2s; Iterations = Infinite; Pitch = -0.4; PitchRange = range(0.1, 0.4); Tempo = 23.9; Volume = 0.9; } style someStyle { run sound(notification); } ".Trim()); StyleSheet styleSheet = NewStyleSheetCompiler().Compile("test", nodes); Assert.AreEqual(1, styleSheet.styleGroupContainers.Length); UIStyleGroupContainer container = styleSheet.styleGroupContainers[0]; Assert.AreEqual("someStyle", container.name); Assert.AreEqual(1, container.groups[0].normal.runCommands.Count); Assert.AreEqual(1, styleSheet.sounds.Length); UISoundData soundData = styleSheet.sounds[0]; Assert.AreEqual("sounds/notification1", soundData.asset); Assert.AreEqual("Master Group 1", soundData.mixerGroup); Assert.AreEqual(UITimeMeasurementUnit.Seconds, soundData.duration.unit); Assert.AreEqual(2f, soundData.duration.value); Assert.AreEqual(-1, soundData.iterations); Assert.AreEqual(-0.4f, soundData.pitch); Assert.AreEqual(0.1f, soundData.pitchRange.Min); Assert.AreEqual(0.4f, soundData.pitchRange.Max); Assert.AreEqual(23.9f, soundData.tempo); Assert.AreEqual(0.9f, soundData.volume); }
public override void OnCreate() { application.SoundSystem.onSoundPlayed += evt => { currentSound = evt.SoundData; }; application.SoundSystem.onSoundStopped += evt => { currentSound = default; }; }