Merge pull request #30 from Nitwel/testing
Add sound effects and make clicks time based
This commit is contained in:
commit
31782c60ab
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -13,3 +13,4 @@
|
|||
*.gltf filter=lfs diff=lfs merge=lfs -text
|
||||
*.obj filter=lfs diff=lfs merge=lfs -text
|
||||
*.mtl filter=lfs diff=lfs merge=lfs -text
|
||||
*.wav filter=lfs diff=lfs merge=lfs -text
|
||||
|
|
3
assets/sound/click.wav
Normal file
3
assets/sound/click.wav
Normal file
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:373cde6b402bd106fea9260b833a429e496caaf500d3b7186bed2fd36b0c6b01
|
||||
size 17452
|
24
assets/sound/click.wav.import
Normal file
24
assets/sound/click.wav.import
Normal file
|
@ -0,0 +1,24 @@
|
|||
[remap]
|
||||
|
||||
importer="wav"
|
||||
type="AudioStreamWAV"
|
||||
uid="uid://k1xeit7qyqlq"
|
||||
path="res://.godot/imported/click.wav-e8a30ec71317fecc836e787d9d63b4a3.sample"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sound/click.wav"
|
||||
dest_files=["res://.godot/imported/click.wav-e8a30ec71317fecc836e787d9d63b4a3.sample"]
|
||||
|
||||
[params]
|
||||
|
||||
force/8_bit=false
|
||||
force/mono=false
|
||||
force/max_rate=false
|
||||
force/max_rate_hz=44100
|
||||
edit/trim=false
|
||||
edit/normalize=false
|
||||
edit/loop_mode=0
|
||||
edit/loop_begin=0
|
||||
edit/loop_end=-1
|
||||
compress/mode=0
|
3
assets/sound/spawn.wav
Normal file
3
assets/sound/spawn.wav
Normal file
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:4dbe8aa4dcfb16741a9439283d0ceeeb83b7153c26f8cab421d381676b8e51b5
|
||||
size 38780
|
24
assets/sound/spawn.wav.import
Normal file
24
assets/sound/spawn.wav.import
Normal file
|
@ -0,0 +1,24 @@
|
|||
[remap]
|
||||
|
||||
importer="wav"
|
||||
type="AudioStreamWAV"
|
||||
uid="uid://ducbejs36cuim"
|
||||
path="res://.godot/imported/spawn.wav-144efb9acab2ae0dd785e23bcaa07433.sample"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sound/spawn.wav"
|
||||
dest_files=["res://.godot/imported/spawn.wav-144efb9acab2ae0dd785e23bcaa07433.sample"]
|
||||
|
||||
[params]
|
||||
|
||||
force/8_bit=false
|
||||
force/mono=false
|
||||
force/max_rate=false
|
||||
force/max_rate_hz=44100
|
||||
edit/trim=false
|
||||
edit/normalize=false
|
||||
edit/loop_mode=0
|
||||
edit/loop_begin=0
|
||||
edit/loop_end=-1
|
||||
compress/mode=0
|
|
@ -2,6 +2,7 @@ extends Node3D
|
|||
|
||||
@onready var _controller := XRHelpers.get_xr_controller(self)
|
||||
@export var ray: RayCast3D
|
||||
@export var timespan_click = 200.0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
|
@ -11,6 +12,7 @@ func _ready():
|
|||
var _last_collided: Object = null
|
||||
var _is_pressed := false
|
||||
var _is_grabbed := false
|
||||
var _time_pressed := 0.0
|
||||
var _moved := false
|
||||
var _click_point := Vector3.ZERO
|
||||
|
||||
|
@ -19,18 +21,17 @@ func _physics_process(delta):
|
|||
_handle_move()
|
||||
|
||||
func _handle_move():
|
||||
if _is_pressed == false && _is_grabbed == false:
|
||||
var time_passed = Time.get_ticks_msec() - _time_pressed
|
||||
if time_passed <= timespan_click || (_is_pressed == false && _is_grabbed == false):
|
||||
return
|
||||
|
||||
var distance = ray.get_collision_point().distance_to(_click_point)
|
||||
_moved = true
|
||||
|
||||
if _moved || distance > 0.02:
|
||||
if _is_pressed:
|
||||
_call_fn(_last_collided, "_on_press_move")
|
||||
_moved = true
|
||||
if _is_grabbed:
|
||||
_call_fn(_last_collided, "_on_grab_move")
|
||||
_moved = true
|
||||
if _is_pressed:
|
||||
_call_fn(_last_collided, "_on_press_move")
|
||||
|
||||
if _is_grabbed:
|
||||
_call_fn(_last_collided, "_on_grab_move")
|
||||
|
||||
func _handle_enter_leave():
|
||||
var collider = ray.get_collider()
|
||||
|
@ -52,6 +53,7 @@ func _on_button_pressed(button):
|
|||
match button:
|
||||
"trigger_click":
|
||||
_is_pressed = true
|
||||
_time_pressed = Time.get_ticks_msec()
|
||||
_click_point = ray.get_collision_point()
|
||||
_call_fn(collider, "_on_press_down")
|
||||
"grip_click":
|
||||
|
|
|
@ -21,6 +21,7 @@ var active: bool = false :
|
|||
return active
|
||||
|
||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||
@onready var click_sound: AudioStreamPlayer = $ClickSound
|
||||
|
||||
func _ready():
|
||||
if initial_active:
|
||||
|
@ -34,6 +35,7 @@ func _on_click(_event):
|
|||
return
|
||||
|
||||
active = !active
|
||||
AudioPlayer.play_effect("click")
|
||||
|
||||
return {
|
||||
"active": active
|
||||
|
@ -46,6 +48,7 @@ func _on_press_down(_event):
|
|||
if toggleable:
|
||||
return
|
||||
|
||||
AudioPlayer.play_effect("click")
|
||||
animation_player.play("down")
|
||||
|
||||
func _on_press_up(_event):
|
||||
|
|
|
@ -121,11 +121,13 @@ func _on_entity_click(entity_name):
|
|||
if entity_name == "#back":
|
||||
selected_device = null
|
||||
page = last_device_page
|
||||
AudioPlayer.play_effect("click")
|
||||
render()
|
||||
return
|
||||
|
||||
var type = entity_name.split(".")[0]
|
||||
print(type)
|
||||
AudioPlayer.play_effect("spawn")
|
||||
|
||||
if type == "switch":
|
||||
var switch = Switch.instantiate()
|
||||
|
|
|
@ -39,12 +39,17 @@ func _ready():
|
|||
)
|
||||
|
||||
func generate_mesh():
|
||||
var corner_count = wall_corners.get_child_count()
|
||||
|
||||
if corner_count < 3:
|
||||
return
|
||||
|
||||
var st = SurfaceTool.new()
|
||||
var wall_up = Vector3.UP * 3
|
||||
|
||||
st.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
|
||||
|
||||
for i in range(wall_corners.get_child_count()):
|
||||
for i in range(corner_count):
|
||||
var corner = get_corner(i)
|
||||
|
||||
print(corner.position, " ", corner.position + wall_up)
|
||||
|
|
15
lib/globals/audio_player.gd
Normal file
15
lib/globals/audio_player.gd
Normal file
|
@ -0,0 +1,15 @@
|
|||
extends AudioStreamPlayer
|
||||
|
||||
var click_sound = preload("res://assets/sound/click.wav")
|
||||
var spawn_sound = preload("res://assets/sound/spawn.wav")
|
||||
|
||||
func _ready():
|
||||
volume_db = -18
|
||||
|
||||
func play_effect(sound):
|
||||
if sound == "click":
|
||||
stream = click_sound
|
||||
elif sound == "spawn":
|
||||
stream = spawn_sound
|
||||
|
||||
play()
|
|
@ -20,6 +20,7 @@ config/icon="res://assets/logo.png"
|
|||
XRToolsUserSettings="*res://addons/godot-xr-tools/user_settings/user_settings.gd"
|
||||
Request="*res://lib/globals/request.gd"
|
||||
HomeAdapters="*res://lib/globals/home_adapters.gd"
|
||||
AudioPlayer="*res://lib/globals/audio_player.gd"
|
||||
|
||||
[editor_plugins]
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user