59 lines
1.5 KiB
GDScript
59 lines
1.5 KiB
GDScript
extends StaticBody3D
|
|
|
|
|
|
|
|
@onready var beds = preload("res://Scenes/Prefabs/DoubleBeds.tscn")
|
|
@export var buildTransparentPreivew: MeshInstance3D
|
|
|
|
|
|
var areas
|
|
var previewObject: Node3D
|
|
var is_placed = false
|
|
func _ready() -> void:
|
|
areas = get_children()
|
|
buildTransparentPreivew.visible = false
|
|
Global.exit_build_mode.connect(_on_exit_build_mode)
|
|
Global.enter_build_mode.connect(_on_enter_build_mode)
|
|
|
|
|
|
func _input_event(camera: Camera3D, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
|
|
if event.is_action_pressed("mouse_click") and Global.build_mode:
|
|
place_object()
|
|
|
|
|
|
|
|
func _mouse_enter() -> void:
|
|
if !is_placed and Global.build_mode and BuildManager.is_object_selected:
|
|
show_preview()
|
|
|
|
func _mouse_exit() -> void:
|
|
if !is_placed and Global.build_mode:
|
|
hide_preview()
|
|
|
|
func show_preview():
|
|
#previewObject = beds.instantiate()
|
|
previewObject = BuildManager.get_preview_object().instantiate()
|
|
|
|
areas[0].add_child(previewObject)
|
|
#previewObject.global_position.y = BuildManager.global_y
|
|
buildTransparentPreivew.visible = false
|
|
Global.preview_created.emit()
|
|
|
|
func hide_preview():
|
|
if is_placed != true:
|
|
if previewObject != null:
|
|
previewObject.queue_free()
|
|
buildTransparentPreivew.visible = true
|
|
|
|
func place_object():
|
|
is_placed = true
|
|
buildTransparentPreivew.visible = false
|
|
Global.object_placed.emit()
|
|
|
|
func _on_enter_build_mode():
|
|
if !is_placed:
|
|
buildTransparentPreivew.visible = true
|
|
func _on_exit_build_mode():
|
|
hide_preview()
|
|
buildTransparentPreivew.visible = false
|