80 lines
2.1 KiB
GDScript
80 lines
2.1 KiB
GDScript
extends Node3D
|
|
|
|
|
|
|
|
@export var meshInstance: MeshInstance3D
|
|
@export var preview_shader: ShaderMaterial
|
|
@export var ActionNode: Node3D
|
|
@export var static_body: StaticBody3D
|
|
var default_shaders: Array
|
|
#var static_body: StaticBody3D
|
|
#var ActionNode: Node3D
|
|
var is_placed: bool = false
|
|
|
|
func _ready() -> void:
|
|
BuildManager.preview_created.connect(_on_preview_create)
|
|
BuildManager.object_placed.connect(_on_object_placed)
|
|
set_default_shaders()
|
|
|
|
static_body = $StaticBody3D
|
|
|
|
static_body.mouse_entered.connect(_on_mouse_enter)
|
|
static_body.mouse_exited.connect(_on_mouse_exit)
|
|
|
|
ActionNode = $ActionNode
|
|
|
|
func set_default_shaders():
|
|
var amount_shaders = meshInstance.get_surface_override_material_count()
|
|
default_shaders.resize( amount_shaders)
|
|
|
|
for i in amount_shaders:
|
|
default_shaders[i] = meshInstance.get_surface_override_material(i)
|
|
|
|
func restore_default_shaders():
|
|
for i in meshInstance.get_surface_override_material_count():
|
|
meshInstance.set_surface_override_material(i,default_shaders[i])
|
|
pass
|
|
|
|
func set_preview_shader_color():
|
|
if true:
|
|
set_green_color()
|
|
for i in meshInstance.get_surface_override_material_count():
|
|
meshInstance.set_surface_override_material(i,preview_shader)
|
|
pass
|
|
|
|
func set_green_color():
|
|
preview_shader.set_shader_parameter("color", Vector3(0,1.0,0))
|
|
|
|
func set_red_color():
|
|
preview_shader.set_shader_parameter("color", Vector3(1.0,0,0))
|
|
pass
|
|
|
|
|
|
|
|
func _on_preview_create():
|
|
set_preview_shader_color()
|
|
|
|
|
|
func _on_object_placed(build_postion):
|
|
restore_default_shaders()
|
|
|
|
|
|
|
|
func enable_outline():
|
|
for i in meshInstance.get_surface_override_material_count():
|
|
var material = meshInstance.get_surface_override_material(i)
|
|
if material.next_pass != null:
|
|
meshInstance.get_surface_override_material(i).next_pass.set_shader_parameter("is_active", true)
|
|
func disable_outline():
|
|
for i in meshInstance.get_surface_override_material_count():
|
|
var material = meshInstance.get_surface_override_material(i)
|
|
if material.next_pass != null:
|
|
meshInstance.get_surface_override_material(i).next_pass.set_shader_parameter("is_active", false)
|
|
|
|
|
|
|
|
func _on_mouse_enter():
|
|
enable_outline()
|
|
func _on_mouse_exit():
|
|
disable_outline()
|