godot-psd-training/sceen/train/trainDoor.gd
2024-05-28 15:40:46 +08:00

59 lines
1.5 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:
trainDoorState=Train_Door_STATE.close
## 车门的故障枚举
enum TrainDoor_Fault_State{
noFault,#无故障
openFault,# 开门故障
}
##车门的故障状态
@onready var trainDoorFaultState : TrainDoor_Fault_State = TrainDoor_Fault_State.noFault :
set(value):
if trainDoorFaultState != value:
trainDoorFaultState = value
##设置故障
func setTrainFault (faultType:TrainDoor_Fault_State)-> void:
trainDoorFaultState = faultType
##恢复故障
func removeTrainDoorFault ()-> void:
trainDoorFaultState = TrainDoor_Fault_State.noFault