godot-psd-training/sceen/platform/screenDoor.gd
2024-05-09 14:43:36 +08:00

142 lines
4.0 KiB
GDScript

extends Node3D
##屏蔽门
class_name ScreenDoor
@onready var left_animation_player: AnimationPlayer = $LeftAnimationPlayer
@onready var right_animation_player: AnimationPlayer = $RightAnimationPlayer
@export var mtd_material: ShaderMaterial
@export var mtd_fault_material: ShaderMaterial
##是否设置隔离带
@onready var isSetIsolationStrip:bool = false :
set(value):
if isSetIsolationStrip != value:
isSetIsolationStrip = value
if isSetIsolationStrip:
$IsolationStrip.visible = true
else :
$IsolationStrip.visible = false
##粘胶带
func adhesiveTape ()-> void:
if $leftDoor_broken.visible == true :
$left_tape.visible = true
## 屏蔽门的状态枚举
enum ScreenDoor_State{
opening,# 正在开门
open,#开到位
closeing,#正在关门
close,# 关到位
}
##屏蔽门的状态
@onready var screenDoorState : ScreenDoor_State = ScreenDoor_State.close :
set(value):
if screenDoorState != value:
screenDoorState = value
if screenDoorState == ScreenDoor_State.opening :
left_animation_player.play("leftOpen")
right_animation_player.play("rightOpen")
elif screenDoorState == ScreenDoor_State.closeing :
left_animation_player.play("leftClose")
right_animation_player.play("rightClose")
##打开屏蔽门
func openScreenDoor (isUseLCBKey=false)-> void:
if screenDoorState == ScreenDoor_State.close and (screenDoorFaultState != ScreenDoor_Fault_State.openFault or isUseLCBKey):
screenDoorState=ScreenDoor_State.opening
$Timer.connect('timeout', _on_timer_timeout)
$Timer.start(0.3)
##关闭屏蔽门
func closeScreenDoor (isUseLCBKey=false)-> void:
if screenDoorState == ScreenDoor_State.open and (screenDoorFaultState != ScreenDoor_Fault_State.closeFault or isUseLCBKey):
screenDoorState=ScreenDoor_State.closeing
$Timer.connect('timeout', _on_timer_timeout)
$Timer.start(0.3)
func _on_left_animation_player_animation_finished(anim_name: StringName) -> void:
if anim_name == 'leftOpen':
screenDoorState = ScreenDoor_State.open
$Timer.stop()
is_dark = false
_set_mtd(is_dark)
elif anim_name == 'leftClose':
screenDoorState = ScreenDoor_State.close
$Timer.stop()
is_dark = true
_set_mtd(is_dark)
## 屏蔽门的故障枚举
enum ScreenDoor_Fault_State{
noFault,#无故障
openFault,# 开门故障
closeFault,# 关门故障
pinchPeople,#夹人
glassBreakage,#玻璃破碎
}
##屏蔽门的故障状态
@onready var screenDoorFaultState : ScreenDoor_Fault_State = ScreenDoor_Fault_State.noFault :
set(value):
if screenDoorFaultState != value:
screenDoorFaultState = value
##设置故障
func setScreenDoorFault (faultType:ScreenDoor_Fault_State)-> void:
screenDoorFaultState = faultType
if faultType == ScreenDoor_Fault_State.glassBreakage :
$leftDoor_broken.visible = true
$leftDoor_broken/AudioStreamPlayer.play()
elif faultType == ScreenDoor_Fault_State.openFault :
$MTD.material_override = mtd_fault_material
elif faultType == ScreenDoor_Fault_State.closeFault :
$MTD.material_override = mtd_fault_material
mtd_fault_material.set_shader_parameter('is_dark', false)
##恢复故障
func removeScreenDoorFault ()-> void:
screenDoorFaultState = ScreenDoor_Fault_State.noFault
$MTD.material_override = mtd_material
##以下是lcb相关
class LcbKeyWindow :
var keyName: String
var keyState:LcbWindow.KNOB_STATE
func _init(keyName: String, keyState: LcbWindow.KNOB_STATE):
self.keyName = keyName
self.keyState = keyState
var lcbKey = LcbKeyWindow.new('',LcbWindow.KNOB_STATE.AUTO)
signal clickLcbSignalAndSent(screenDoor)
func _on_lcb_click() -> void:
clickLcbSignalAndSent.emit(self)
##点击屏蔽门
signal clicksScreenDoorSignal(screenDoor,mousePosition)
var is_dark = true
func _on_timer_timeout():
is_dark = !is_dark
_set_mtd(is_dark)
func _set_mtd(dark):
if is_dark:
mtd_material.set_shader_parameter('is_dark', true)
$SpotLight3D.hide()
else:
mtd_material.set_shader_parameter('is_dark', false)
$SpotLight3D.show()
func _ready():
$MTD.material_override = mtd_material
_set_mtd(is_dark)
$SpotLight3D.hide()