65 lines
2.0 KiB
GDScript3
65 lines
2.0 KiB
GDScript3
class_name AudioStreamPlayer_StateReceiver
|
|
extends AudioStreamPlayer
|
|
|
|
export var debug_component: bool = false
|
|
export var callable_state_machine :NodePath
|
|
var request_state_change: FuncRef
|
|
|
|
export(Array, Resource) var sound_effects
|
|
|
|
onready var current_state = StateAnimatedActor.new()
|
|
|
|
# Declare member variables here. Examples:
|
|
# var a = 2
|
|
# var b = "text"
|
|
|
|
var sound_effects_dict: Dictionary
|
|
|
|
#class_name FrameSoundEffects
|
|
#extends Resource
|
|
#
|
|
#
|
|
#export (String) var animation_name
|
|
#export(int) var frame_number
|
|
#export (AudioStreamSample) var sound
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
# Trying something new with a custom resourse.
|
|
for i in sound_effects:
|
|
sound_effects_dict[i.animation_name + str(i.frame_number)] = i.sound
|
|
print (sound_effects_dict)
|
|
|
|
request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state')
|
|
## Connect signal to get alerted of state change
|
|
get_node(callable_state_machine).connect("state_changed", self,"_on_state_change")
|
|
## A reference to the current state machine state
|
|
current_state = get_node(callable_state_machine).current_state
|
|
|
|
|
|
# Experimenting with sound based resources I did this and it worked
|
|
#sound_effect_player.stream = sound_effects.sounds["pew"]
|
|
#print(sounds.sounds["pew"])
|
|
#sound_effects.play()
|
|
|
|
var last_sound_frame_animation: String = ''
|
|
var last_sound_frame: int = -1
|
|
func play_sound_frame(animation: String, frame: int ):
|
|
##DEBUG:
|
|
#if animation == 'run' and frame == 6:
|
|
# print("Do the thign! (", animation + str(frame), ")", " (", last_sound_frame_animation + str(last_sound_frame), ")")
|
|
if animation != last_sound_frame_animation or frame != last_sound_frame:
|
|
last_sound_frame = frame
|
|
last_sound_frame_animation = animation
|
|
var sound_index = animation + str(frame)
|
|
if sound_effects_dict.has(sound_index):
|
|
stream = sound_effects_dict[sound_index]
|
|
play()
|
|
print(self.name, " Playing SE: ", sound_index)
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
#func _process(delta):
|
|
# pass
|