|
1 | 1 | @tool |
2 | 2 | extends EditorPlugin |
3 | 3 |
|
| 4 | +const addon_path = "res://addons/health_hitbox_hurtbox/%s" |
| 5 | + |
| 6 | +var hit_box_2d_added: bool |
| 7 | +var hit_scan_2d_added: bool |
| 8 | +var hurt_box_2d_added: bool |
| 9 | + |
| 10 | +var hit_box_3d_added: bool |
| 11 | +var hit_scan_3d_added: bool |
| 12 | +var hurt_box_3d_added: bool |
| 13 | + |
4 | 14 | func _enter_tree() -> void: |
5 | 15 | add_custom_type("Health", "Node", |
6 | 16 | preload("health/health.gd"), |
7 | 17 | preload("health/health.svg")) |
8 | 18 |
|
9 | 19 | # Load 2D components |
10 | | - add_custom_type("HitBox2D", "Area2D", |
11 | | - preload("2d/hit_box_2d/hit_box_2d.gd"), |
12 | | - preload("2d/hit_box_2d/hit_box_2d.svg")) |
13 | | - add_custom_type("HitScan2D", "RayCast2D", |
14 | | - preload("2d/hit_scan_2d/hit_scan_2d.gd"), |
15 | | - preload("2d/hit_scan_2d/hit_scan_2d.svg")) |
16 | | - add_custom_type("HurtBox2D", "Area2D", |
17 | | - preload("2d/hurt_box_2d/hurt_box_2d.gd"), |
18 | | - preload("2d/hurt_box_2d/hurt_box_2d.svg")) |
| 20 | + if FileAccess.file_exists(addon_path % "2d/hit_box_2d/hit_box_2d.gd"): |
| 21 | + hit_box_2d_added = true |
| 22 | + add_custom_type("HitBox2D", "Area2D", |
| 23 | + preload("2d/hit_box_2d/hit_box_2d.gd"), |
| 24 | + preload("2d/hit_box_2d/hit_box_2d.svg")) |
| 25 | + if FileAccess.file_exists(addon_path % "2d/hit_scan_2d/hit_scan_2d.gd"): |
| 26 | + hit_scan_2d_added = true |
| 27 | + add_custom_type("HitScan2D", "RayCast2D", |
| 28 | + preload("2d/hit_scan_2d/hit_scan_2d.gd"), |
| 29 | + preload("2d/hit_scan_2d/hit_scan_2d.svg")) |
| 30 | + if FileAccess.file_exists(addon_path % "2d/hurt_box_2d/hurt_box_2d.gd"): |
| 31 | + hurt_box_2d_added = true |
| 32 | + add_custom_type("HurtBox2D", "Area2D", |
| 33 | + preload("2d/hurt_box_2d/hurt_box_2d.gd"), |
| 34 | + preload("2d/hurt_box_2d/hurt_box_2d.svg")) |
19 | 35 |
|
20 | 36 | # Load 3D components |
21 | | - add_custom_type("HitBox3D", "Area3D", |
22 | | - preload("3d/hit_box_3d/hit_box_3d.gd"), |
23 | | - preload("3d/hit_box_3d/hit_box_3d.svg")) |
24 | | - add_custom_type("HitScan3D", "RayCast3D", |
25 | | - preload("3d/hit_scan_3d/hit_scan_3d.gd"), |
26 | | - preload("3d/hit_scan_3d/hit_scan_3d.svg")) |
27 | | - add_custom_type("HurtBox3D", "Area3D", |
28 | | - preload("3d/hurt_box_3d/hurt_box_3d.gd"), |
29 | | - preload("3d/hurt_box_3d/hurt_box_3d.svg")) |
| 37 | + if FileAccess.file_exists(addon_path % "3d/hit_box_3d/hit_box_3d.gd"): |
| 38 | + hit_box_3d_added = true |
| 39 | + add_custom_type("HitBox3D", "Area3D", |
| 40 | + preload("3d/hit_box_3d/hit_box_3d.gd"), |
| 41 | + preload("3d/hit_box_3d/hit_box_3d.svg")) |
| 42 | + if FileAccess.file_exists(addon_path % "3d/hit_scan_3d/hit_scan_3d.gd"): |
| 43 | + hit_scan_3d_added = true |
| 44 | + add_custom_type("HitScan3D", "RayCast3D", |
| 45 | + preload("3d/hit_scan_3d/hit_scan_3d.gd"), |
| 46 | + preload("3d/hit_scan_3d/hit_scan_3d.svg")) |
| 47 | + if FileAccess.file_exists(addon_path % "3d/hurt_box_3d/hurt_box_3d.gd"): |
| 48 | + hurt_box_3d_added = true |
| 49 | + add_custom_type("HurtBox3D", "Area3D", |
| 50 | + preload("3d/hurt_box_3d/hurt_box_3d.gd"), |
| 51 | + preload("3d/hurt_box_3d/hurt_box_3d.svg")) |
30 | 52 |
|
31 | 53 |
|
32 | 54 | func _exit_tree() -> void: |
33 | 55 | remove_custom_type("Health") |
34 | 56 |
|
35 | 57 | # Remove 2D components |
36 | | - remove_custom_type("HitBox2D") |
37 | | - remove_custom_type("HitScan2D") |
38 | | - remove_custom_type("HurtBox2D") |
| 58 | + if hit_box_2d_added: |
| 59 | + remove_custom_type("HitBox2D") |
| 60 | + if hit_scan_2d_added: |
| 61 | + remove_custom_type("HitScan2D") |
| 62 | + if hurt_box_2d_added: |
| 63 | + remove_custom_type("HurtBox2D") |
39 | 64 |
|
40 | 65 | # Remove 3D components |
41 | | - remove_custom_type("HitBox3D") |
42 | | - remove_custom_type("HitScan3D") |
43 | | - remove_custom_type("HurtBox3D") |
| 66 | + if hit_box_3d_added: |
| 67 | + remove_custom_type("HitBox3D") |
| 68 | + if hit_scan_3d_added: |
| 69 | + remove_custom_type("HitScan3D") |
| 70 | + if hurt_box_3d_added: |
| 71 | + remove_custom_type("HurtBox3D") |
0 commit comments