godot-psd-training/sceen/train/trainDoor.gd
2024-06-04 09:15:28 +08:00

71 lines
2.0 KiB
GDScript

extends Node3D
##车门
class_name TrainDoor
@onready var left_animation_player: AnimationPlayer = $LeftAnimationPlayer
@onready var right_animation_player: AnimationPlayer = $RightAnimationPlayer
## 车门的状态枚举
enum Train_Door_STATE{
opening,# 正在开门
open,#开到位
closeing,#正在关门
close,# 关到位
}
##车门的状态
@onready var trainDoorState : Train_Door_STATE = Train_Door_STATE.close :
set(value):
if trainDoorState != value:
trainDoorState = value
if trainDoorState ==Train_Door_STATE.open :
left_animation_player.play("leftOpen")
right_animation_player.play("rightOpen")
elif trainDoorState ==Train_Door_STATE.close :
left_animation_player.play("leftClose")
right_animation_player.play("rightClose")
##打开车门
func openTrainDoor ()-> void:
if trainDoorState == Train_Door_STATE.close and trainDoorFaultState != TrainDoor_Fault_State.openFault :
trainDoorState=Train_Door_STATE.open
##关闭车门
func closeTrainDoor ()-> void:
if trainDoorState == Train_Door_STATE.open and trainDoorFaultState != TrainDoor_Fault_State.closeFault :
trainDoorState=Train_Door_STATE.close
##屏蔽门开关门到位信号
signal trainDoorOpenSignal(screenDoor:ScreenDoor)
signal trainDoorCloseSignal(screenDoor:ScreenDoor)
func _on_left_animation_player_animation_finished(anim_name: StringName) -> void:
if anim_name == 'leftOpen':
trainDoorOpenSignal.emit(self)
elif anim_name == 'leftClose':
trainDoorCloseSignal.emit(self)
## 车门的故障枚举
enum TrainDoor_Fault_State{
noFault,#无故障
openFault,# 开门故障
closeFault,# 关门故障
}
##车门的故障状态
@onready var trainDoorFaultState : TrainDoor_Fault_State = TrainDoor_Fault_State.noFault :
set(value):
if trainDoorFaultState != value:
trainDoorFaultState = value
##设置故障
func setTrainDoorFault (faultType:TrainDoor_Fault_State)-> void:
trainDoorFaultState = faultType
##恢复故障
func removeTrainDoorFault ()-> void:
trainDoorFaultState = TrainDoor_Fault_State.noFault