Created
July 18, 2025 01:35
-
-
Save dogboydog/dc2cdc683cccc1ea482b212126199252 to your computer and use it in GitHub Desktop.
YarnSpinner for Godot - Play sounds when characters are revealed from the typewriter effect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using Godot; | |
using Godot.Collections; | |
using Yarn.Markup; | |
using YarnSpinnerGodot; | |
namespace MyGame; | |
public partial class DialogueTypewriterSounds : ActionMarkupHandler { | |
[Export] public Array<AudioStream> typewriterSounds; | |
private DateTime _lastTypeWriter = DateTime.Now; | |
private const float TYPEWRITER_COOLDOWN = 0.05f; | |
public override void OnLineDisplayComplete() { } | |
public override void OnLineWillDismiss() { } | |
public override void | |
OnPrepareForLine(MarkupParseResult line, RichTextLabel text) { } | |
public override void | |
OnLineDisplayBegin(MarkupParseResult line, RichTextLabel text) { } | |
public override YarnTask OnCharacterWillAppear(int currentCharacterIndex, | |
MarkupParseResult line, | |
CancellationToken cancellationToken) { | |
var elapsed = DateTime.Now - _lastTypeWriter; | |
if (elapsed <= TimeSpan.FromSeconds(TYPEWRITER_COOLDOWN)) { | |
return YarnTask.CompletedTask; | |
} | |
// todo : <play a sound from typeWriterSounds here > | |
_lastTypeWriter = DateTime.Now; | |
return YarnTask.CompletedTask; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment