Late initialize editing controls

main
copygirl 2 months ago
parent e1a6c15f5f
commit ac0d3f12bb
  1. 17
      addons/terrain-editing/terrain_editing_plugin.gd

@ -3,24 +3,23 @@ extends EditorPlugin
const CONTAINER := CustomControlContainer.CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT
var controls_scene := preload("res://terrain/editing/TerrainEditingControls.tscn")
var controls_script := preload("res://terrain/editing/TerrainEditingControls.cs")
var controls : Control;
var controls: Control = null;
func _handles(object: Object) -> bool:
return object.get_script() == controls_script
func _enter_tree() -> void:
controls = controls_scene.instantiate()
var script := object.get_script() as CSharpScript
return script and script.resource_path.ends_with("/Terrain.cs")
func _exit_tree() -> void:
if not controls: return
if controls.get_parent():
remove_control_from_container(CONTAINER, controls)
controls.free()
func _make_visible(visible: bool) -> void:
if visible:
if not controls:
var controls_scene = load("res://terrain/editing/TerrainEditingControls.tscn")
controls = controls_scene.instantiate()
add_control_to_container(CONTAINER, controls)
elif controls.get_parent():
elif controls and controls.get_parent():
remove_control_from_container(CONTAINER, controls)

Loading…
Cancel
Save