特效性能
parent
072113046a
commit
88a35fd5c2
@ -1,22 +1,38 @@
|
|||||||
extends Node3D
|
extends Node3D
|
||||||
class_name EffectManager
|
class_name EffectManager
|
||||||
|
|
||||||
|
var effect_count_max: int = 10
|
||||||
|
var effect_count_dict: Dictionary = {}
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
Global.effect_mgr = self
|
Global.effect_mgr = self
|
||||||
SignalManager.effect_create.connect(on_effect_create)
|
SignalManager.effect_create.connect(on_effect_create)
|
||||||
|
|
||||||
|
|
||||||
func on_effect_create(effect: Node3D):
|
func on_effect_create(effect: Node3D):
|
||||||
add_child(effect)
|
add_child(effect)
|
||||||
|
|
||||||
|
|
||||||
func cast_particle(resource: Resource, pos: Vector3, direction = Vector3.UP) -> void:
|
func cast_particle(resource: Resource, pos: Vector3, direction = Vector3.ZERO, effect_scale: Vector3 = Vector3.ZERO) -> void:
|
||||||
var new_particle: Particle = resource.instantiate() as Particle
|
var resource_name = resource.resource_path
|
||||||
add_child(new_particle)
|
if not resource_name in effect_count_dict:
|
||||||
new_particle.position = pos
|
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:
|
if direction.abs().angle_to(Vector3.RIGHT) < 0.01:
|
||||||
direction.z = 0.1
|
direction.z = 0.1
|
||||||
if direction.angle_to(Vector3.UP) > 0.01 and (-direction).angle_to(Vector3.UP) > 0.01:
|
if direction.angle_to(Vector3.UP) > 0.01 and (-direction).angle_to(Vector3.UP) > 0.01:
|
||||||
new_particle.look_at(pos - direction)
|
new_effect.look_at(pos - direction)
|
||||||
else:
|
else:
|
||||||
new_particle.rotation.x = deg_to_rad(-90)
|
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
|
||||||
|
|||||||
Loading…
Reference in New Issue