Initial commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
# Full video: https://www.youtube.com/watch?v=OEpfdmW6_s0
|
||||
# (c) Bryce Dixon, distributed under MIT License: https://github.com/BtheDestroyer/Godot_QuickAudio
|
||||
@icon("./icon.svg")
|
||||
extends Node
|
||||
|
||||
@onready var tree := get_tree() # Gets the slightest of performance improvements by caching the SceneTree
|
||||
|
||||
func _play_sound(sound: AudioStream, player, autoplay := true):
|
||||
player.stream = sound
|
||||
player.autoplay = autoplay
|
||||
player.finished.connect(func(): player.queue_free())
|
||||
tree.current_scene.add_child(player)
|
||||
return player
|
||||
|
||||
# Use this for non-diagetic music or UI sounds which have no position
|
||||
func play_sound(sound: AudioStream, autoplay := true) -> AudioStreamPlayer:
|
||||
return _play_sound(sound, AudioStreamPlayer.new(), autoplay)
|
||||
|
||||
# Use this for 2D gameplay sounds which should fade with distance
|
||||
# Note: Remember to set the global_position or reparent(new_parent, false)!
|
||||
func play_sound_2d(sound: AudioStream, autoplay := true) -> AudioStreamPlayer2D:
|
||||
return _play_sound(sound, AudioStreamPlayer2D.new(), autoplay)
|
||||
|
||||
# Use this for 3D gameplay sounds which should fade with distance
|
||||
# Note: Remember to set the global_position or reparent(new_parent, false)!
|
||||
func play_sound_3d(sound: AudioStream, autoplay := true) -> AudioStreamPlayer3D:
|
||||
return _play_sound(sound, AudioStreamPlayer3D.new(), autoplay)
|
||||
|
||||
|
||||
#########################################
|
||||
# Extra fun stuff for music transitions #
|
||||
#########################################
|
||||
|
||||
func fade_in(audio_stream_player, seconds := 1.0, tween := create_tween()):
|
||||
if not (audio_stream_player is AudioStreamPlayer or audio_stream_player is AudioStreamPlayer2D or audio_stream_player is AudioStreamPlayer3D):
|
||||
push_error("Non-AudioStreamPlayer[XD] provided to Audio.fade_in(...)")
|
||||
return
|
||||
tween.tween_method(func(x): audio_stream_player.volume_db = linear_to_db(x), db_to_linear(audio_stream_player.volume_db), 1.0, seconds)
|
||||
|
||||
|
||||
func fade_out(audio_stream_player, seconds := 1.0, tween := create_tween()):
|
||||
if not (audio_stream_player is AudioStreamPlayer or audio_stream_player is AudioStreamPlayer2D or audio_stream_player is AudioStreamPlayer3D):
|
||||
push_error("Non-AudioStreamPlayer[XD] provided to Audio.fade_out(...)")
|
||||
return
|
||||
tween.tween_method(func(x): audio_stream_player.volume_db = linear_to_db(x), db_to_linear(audio_stream_player.volume_db), 0.0, seconds)
|
||||
tween.tween_callback(func(): audio_stream_player.stop(); audio_stream_player.queue_free())
|
||||
|
||||
|
||||
func cross_fade(audio_stream_player_out, audio_stream_player_in, seconds := 1.0, tween := create_tween()):
|
||||
if not (audio_stream_player_out is AudioStreamPlayer or audio_stream_player_out is AudioStreamPlayer2D or audio_stream_player_out is AudioStreamPlayer3D):
|
||||
push_error("Non-AudioStreamPlayer[XD] provided to Audio.cross_fade(...) as audio_stream_player_out")
|
||||
return
|
||||
if not (audio_stream_player_in is AudioStreamPlayer or audio_stream_player_in is AudioStreamPlayer2D or audio_stream_player_in is AudioStreamPlayer3D):
|
||||
push_error("Non-AudioStreamPlayer[XD] provided to Audio.cross_fade(...) as audio_stream_player_in")
|
||||
return
|
||||
fade_in(audio_stream_player_in, seconds, tween)
|
||||
fade_out(audio_stream_player_out, seconds, tween.parallel())
|
||||
|
||||
func sequential_fade(audio_stream_player_out, audio_stream_player_in, out_seconds := 1.0, in_seconds := out_seconds, tween := create_tween(), empty_seconds := 0.0):
|
||||
if not (audio_stream_player_out is AudioStreamPlayer or audio_stream_player_out is AudioStreamPlayer2D or audio_stream_player_out is AudioStreamPlayer3D):
|
||||
push_error("Non-AudioStreamPlayer[XD] provided to Audio.sequential_fade(...) as audio_stream_player_out")
|
||||
return
|
||||
if not (audio_stream_player_in is AudioStreamPlayer or audio_stream_player_in is AudioStreamPlayer2D or audio_stream_player_in is AudioStreamPlayer3D):
|
||||
push_error("Non-AudioStreamPlayer[XD] provided to Audio.sequential_fade(...) as audio_stream_player_in")
|
||||
return
|
||||
fade_out(audio_stream_player_out, out_seconds, tween)
|
||||
if empty_seconds > 0.0:
|
||||
tween.tween_interval(empty_seconds)
|
||||
fade_in(audio_stream_player_in, in_seconds, tween)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cujwm7u5pvogl
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Bryce "BtheDestroyer" Dixon
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,42 @@
|
||||
#  Godot_QuickAudio
|
||||
|
||||
Light-weight and easy-to-use interface for creating sound effects and music systems
|
||||
|
||||
## [Overview Video](https://www.youtube.com/watch?v=OEpfdmW6_s0)
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
### From Asset Library
|
||||
|
||||
1. Search "QuickAudio" in the "Asset Library" tab (at the top next to 2D, 3D, and Script) of the Godot editor.
|
||||
1. Add the plugin to your project.
|
||||
|
||||
### Manual Download
|
||||
|
||||
1. Download the code from this repository.
|
||||
1. Extract the downloaded archive to your project; resulting files should end up in `res://addons/quick_audio` (Files outside of that folder are not needed)
|
||||
1. Go to your Project Settings, select the
|
||||
|
||||
## How to Use
|
||||
|
||||
See the full demo scripts for [sound effects](https://github.com/BtheDestroyer/Godot_QuickAudio/blob/master/addons/quick_audio/SFXDemo.gd) and [music](https://github.com/BtheDestroyer/Godot_QuickAudio/blob/master/addons/quick_audio/MusicDemo.gd).
|
||||
|
||||
### Quick start:
|
||||
|
||||
```gdscript
|
||||
extends Node3D
|
||||
|
||||
@export var music: AudioStream
|
||||
@export var sound: AudioStream
|
||||
|
||||
func _ready():
|
||||
Audio.play_sound(music)
|
||||
|
||||
var time := 0.0
|
||||
func _process(delta):
|
||||
time += delta
|
||||
if time > 1.0:
|
||||
time -= 1.0
|
||||
Audio.play_sound_3d(sound).global_position = global_position
|
||||
```
|
||||
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="32"
|
||||
height="32"
|
||||
viewBox="0 0 8.4666667 8.4666667"
|
||||
version="1.1"
|
||||
id="svg5"
|
||||
inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
|
||||
sodipodi:docname="icon.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview7"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:document-units="mm"
|
||||
showgrid="false"
|
||||
units="px"
|
||||
inkscape:zoom="24.886869"
|
||||
inkscape:cx="14.405187"
|
||||
inkscape:cy="19.387734"
|
||||
inkscape:window-width="2560"
|
||||
inkscape:window-height="1377"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs2">
|
||||
<linearGradient
|
||||
id="linearGradient10122"
|
||||
inkscape:swatch="solid">
|
||||
<stop
|
||||
style="stop-color:#000000;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop10120" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<path
|
||||
style="fill:#7b7b7b;fill-opacity:1;stroke:#000000;stroke-width:0.265;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 0.26458333,4.2333333 0,-1.0583333 H 1.3229167 L 5.8208333,0.26458333 V 8.2020833 L 1.3229167,5.2916667 H 0.26458333 Z"
|
||||
id="path922"
|
||||
sodipodi:nodetypes="cccccccc" />
|
||||
<path
|
||||
style="fill:#ffcb00;fill-opacity:1;stroke:#000000;stroke-width:0.218338;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 3.8616623,5.7021608 4.9918248,2.3736682 6.1473617,3.6798564 7.7800043,2.2353531 6.6498416,5.5638457 5.4943047,4.2576577 Z"
|
||||
id="path10144"
|
||||
sodipodi:nodetypes="ccccccc" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,43 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dabftvq3kx5he"
|
||||
path="res://.godot/imported/icon.svg-97708c4c4c70e97af4253d257fbfafd7.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/quick_audio/icon.svg"
|
||||
dest_files=["res://.godot/imported/icon.svg-97708c4c4c70e97af4253d257fbfafd7.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
@@ -0,0 +1,7 @@
|
||||
[plugin]
|
||||
|
||||
name="QuickAudio"
|
||||
description="Light-weight and easy-to-use interface for creating sound effects and music systems"
|
||||
author="Bryce Dixon"
|
||||
version="1.0"
|
||||
script="quick_audio.gd"
|
||||
@@ -0,0 +1,8 @@
|
||||
@tool
|
||||
extends EditorPlugin
|
||||
|
||||
func _enter_tree():
|
||||
add_autoload_singleton("Audio", "./Audio.gd")
|
||||
|
||||
func _exit_tree():
|
||||
remove_autoload_singleton("Audio")
|
||||
@@ -0,0 +1 @@
|
||||
uid://4d3sx2tw0oqo
|
||||
Reference in New Issue
Block a user