You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.2 KiB
GDScript

extends Node3D
class_name EffectManager
var effect_count_max: int = 10
var effect_count_dict: Dictionary = {}
func _ready():
Global.effect_mgr = self
SignalManager.effect_create.connect(on_effect_create)
func on_effect_create(effect: Node3D):
add_child(effect)
func cast_particle(resource: Resource, pos: Vector3, direction = Vector3.ZERO, effect_scale: Vector3 = Vector3.ZERO) -> void:
var resource_name = resource.resource_path
if not resource_name in effect_count_dict:
effect_count_dict[resource_name] = 0
if effect_count_dict[resource_name] >= effect_count_max:
return
var new_effect: EffectBase = resource.instantiate() as EffectBase
new_effect.resource_name = resource_name
new_effect.effect_destroy.connect(_on_effect_destroy)
effect_count_dict[resource_name] += 1
add_child(new_effect)
new_effect.position = pos
if direction:
if direction.abs().angle_to(Vector3.RIGHT) < 0.01:
direction.z = 0.1
if direction.angle_to(Vector3.UP) > 0.01 and (-direction).angle_to(Vector3.UP) > 0.01:
new_effect.look_at(pos - direction)
else:
new_effect.rotation.x = deg_to_rad(-90)
if effect_scale:
new_effect.scale = effect_scale
func _on_effect_destroy(resource_name) -> void:
effect_count_dict[resource_name] -= 1