-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkToLevel.gd
More file actions
75 lines (61 loc) · 1.8 KB
/
LinkToLevel.gd
File metadata and controls
75 lines (61 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
extends RayCast
class_name LinkToLevel
#enum
export(PackedScene) var scene
export(String) var scene_path
export(bool) var autoload_target
var target_instance
var parent
func get_target_scene() -> PackedScene:
if scene_path:
scene = load(scene_path)
return scene
func set_target_instance(_target_instance):
target_instance = _target_instance
target_instance.connect("was_unloaded", self, "_on_target_unloaded")
func _ready():
parent = get_parent()
scene = get_target_scene()
# assert(scene, "Error: A link must have a scene or scene path")
if scene and !target_instance:
set_up_loader()
# if autoload_target:
# load_target()
# else:
# set_up_loader()
func should_load(test = false) -> bool:
if !scene:
return false
# if autoload_target:
# return true
cast_to = to_local(Vector3(0,0,0))
return is_colliding() && get_collider().name == "Camera"
func get_link_type():
return 'unimplemented'
func get_complementary_link():
print('unimplemented')
func update_target_transform():
print('unimplemented')
func _physics_process(delta):
if should_load():
load_target()
if target_instance and !target_instance.i_got_it:
update_target_transform()
func load_target():
enabled = false
scene = get_target_scene()
if !target_instance and scene:
set_target_instance(scene.instance())
update_target_transform()
var link = get_complementary_link()
link.set_target_instance(parent)
link.scene_path = parent.filename
get_node("/root/Root/World").add_child(target_instance)
print("loading ", get_link_type(), " level: ", target_instance.name, ' from ', parent.name)
func set_up_loader():
target_instance = null
enabled = true
func _on_target_unloaded():
# if !autoload_target:
# target_instance.queue_free()
set_up_loader()