38 lines
1.2 KiB
GDScript
38 lines
1.2 KiB
GDScript
@tool
|
|
extends TextureButton
|
|
|
|
class_name SoundTextureButton
|
|
|
|
@export var generate_click_mask := false:
|
|
set(val):
|
|
generate_click_mask = false
|
|
if val and texture_normal:
|
|
var mask_image := texture_normal.get_image()
|
|
texture_click_mask = BitMap.new()
|
|
texture_click_mask.create_from_image_alpha(mask_image)
|
|
@export var audio_streams := [preload("res://asset/audio/sfx/ui/click.wav")] as Array[AudioStream]
|
|
@export var audio_collections = [] as Array[AudioStreamCollection]
|
|
|
|
|
|
func _ready():
|
|
if audio_streams:
|
|
var collection := AudioStreamCollection.new()
|
|
collection.audios = audio_streams
|
|
audio_collections.append(collection)
|
|
if audio_collections:
|
|
#print("sound button load audio_collections into audio_player")
|
|
var audio_player := RandomAudioStreamPlayer.new()
|
|
audio_player.audio_collections = audio_collections
|
|
button_down.connect(audio_player.play_random)
|
|
add_child(audio_player)
|
|
else:
|
|
push_warning("sound button has no audio_collections! ignore initialization of audio_player")
|
|
#button_down.connect(_on_press_down)
|
|
#button_up.connect(_on_press_up)
|
|
|
|
#func _on_press_down():
|
|
#InputUtil.set_cursor_hand_patting()
|
|
#
|
|
#func _on_press_up():
|
|
#InputUtil.set_cursor_hand_rest()
|