Created
June 25, 2021 01:12
-
-
Save sjvnnings/e085e9a3468ea55e1f24269156690cbf to your computer and use it in GitHub Desktop.
An Area node that mimics the functionality of Godot's ProximityGroup, without it's drawbacks and confusing documentation.
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
extends Area | |
class_name CustomProximityGroup | |
signal broadcast(method_name, params) | |
enum dispatch_modes{ | |
PROXY, | |
SIGNAL | |
} | |
export var group_name := "" | |
export(dispatch_modes) var dispatch_mode | |
export var execute_self_on_broadcast := true | |
func _ready(): | |
if group_name != "": | |
add_to_group(group_name) | |
func _execute(method_name : String, params := []): | |
if dispatch_mode == dispatch_modes.PROXY: | |
var parent = get_parent() | |
if parent != null and parent.has_method(method_name): | |
parent.callv(method_name, params) | |
else: | |
emit_signal("broadcast", method_name, params) | |
func broadcast(method_name : String, params := []): | |
if execute_self_on_broadcast: | |
_execute(method_name, params) | |
for a in get_overlapping_areas(): | |
if a.is_in_group(group_name) and a.has_method("_execute"): | |
a._execute(method_name, params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment