2024-07-16 11:00:51 +08:00
|
|
|
extends Node3D
|
|
|
|
|
2024-07-17 11:23:34 +08:00
|
|
|
##闸机门
|
2024-07-16 11:00:51 +08:00
|
|
|
class_name GateDoor
|
|
|
|
@onready var left_animation_player: AnimationPlayer = $LeftAnimationPlayer
|
|
|
|
@onready var right_animation_player: AnimationPlayer = $RightAnimationPlayer
|
|
|
|
|
|
|
|
|
2024-07-17 11:23:34 +08:00
|
|
|
## 闸机门的状态枚举
|
2024-07-16 11:00:51 +08:00
|
|
|
enum Gate_Door_STATE{
|
|
|
|
opening,# 正在开门
|
|
|
|
open,#开到位
|
|
|
|
closeing,#正在关门
|
|
|
|
close,# 关到位
|
|
|
|
}
|
|
|
|
|
2024-07-17 11:23:34 +08:00
|
|
|
##闸机门的状态
|
2024-07-16 11:00:51 +08:00
|
|
|
@onready var gateDoorState : Gate_Door_STATE = Gate_Door_STATE.close :
|
|
|
|
set(value):
|
|
|
|
if gateDoorState != value:
|
|
|
|
gateDoorState = value
|
|
|
|
if gateDoorState == Gate_Door_STATE.open :
|
|
|
|
left_animation_player.play("leftOpen")
|
|
|
|
right_animation_player.play("rightOpen")
|
|
|
|
elif gateDoorState == Gate_Door_STATE.close :
|
|
|
|
left_animation_player.play("leftClose")
|
|
|
|
right_animation_player.play("rightClose")
|
|
|
|
|
|
|
|
|
2024-07-17 11:23:34 +08:00
|
|
|
##打开闸机门
|
2024-07-16 11:00:51 +08:00
|
|
|
func openGateDoor ()-> void:
|
|
|
|
if gateDoorState == Gate_Door_STATE.close :
|
|
|
|
gateDoorState = Gate_Door_STATE.open
|
|
|
|
|
|
|
|
|
2024-07-17 11:23:34 +08:00
|
|
|
##关闭闸机门
|
2024-07-16 11:00:51 +08:00
|
|
|
func closeGateDoor ()-> void:
|
|
|
|
if gateDoorState == Gate_Door_STATE.open :
|
|
|
|
gateDoorState=Gate_Door_STATE.close
|
2024-07-17 11:23:34 +08:00
|
|
|
|
|
|
|
var waitPeopleCount = 0
|
|
|
|
func _on_area_3d_area_entered(area: Area3D) -> void:
|
|
|
|
var peopleWalkFollow = area.get_parent().get_parent()
|
|
|
|
if peopleWalkFollow is PlayerPathFollow :
|
|
|
|
waitPeopleCount += 1
|
|
|
|
openGateDoor()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_area_3d_area_exited(area: Area3D) -> void:
|
|
|
|
var peopleWalkFollow = area.get_parent().get_parent()
|
|
|
|
if peopleWalkFollow is PlayerPathFollow :
|
|
|
|
waitPeopleCount -= 1
|
|
|
|
if waitPeopleCount==0 :
|
|
|
|
closeGateDoor()
|