extends TotalScene class_name LargePassengerFlowScene ## 照相机名字的枚举 enum Camera_name{ #VehicleControlRoom,#车控室 SparePartsCabinet,#备品柜 PartsArea,#备品区 StationHall,#站厅 UpPlatform,#上行站台 DownPlatform,#下行站台 #APassageway,#A出入口 StationHallAExit,#站厅A出口 AEntrance,#A入口 APassage,#A口通道 #BPassageway,#B出入口 StationHallBExit,#站厅B出口 BEntrance,#B入口 BPassage,#B口通道 #CPassageway,#C出入口 StationHallCExit,#站厅C出口 CEntrance,#C入口 CPassage,#C口通道 #DPassageway,#D出入口 StationHallDExit,#站厅D出口 DEntrance,#D入口 DPassage,#D口通道 #StaionHallA,#站厅A端 ALowerStepSwitch,#A端扶梯下部开关 ATVM,#A端TVM AInboundGate,#A端进站闸机 AExitGate,#A端出站闸机 AUpperStep,#A端扶梯上部 ALowerStep,#A端扶梯下部 AGangway,#A端站厅步梯口 #StationHallB,#站厅B端 BLowerStepSwitch,#B端扶梯下部开关 BTVM,#B端TVM BInboundGate,#B端进站闸机 BExitGate,#B端出站闸机 BUpperStep,#B端扶梯上部 BLowerStep,#B端扶梯下部 BGangway,#B端站厅步梯口 } @onready var cameras = $AllCamera.get_children() ##切换相机 func switchCamera (camera :Camera_name)-> void: currentActiveCamera = cameras[camera] cameras[camera].make_current() ## 人运动区域的枚举 enum PlayerWalkArea3D { AEntrance,#A入口 BTicketingArea, #购票区B端 AEntranceGateArea, #闸机A入口区 BElevatorUpArea, #扶梯上区B端 BElevatorDownArea,#扶梯下区B端 screenDoorWaitArea,#屏蔽门等待区域 } ##区域运动(连续的路径点) func playerGoToNextArea(peopleWalkFollow:PlayerPathFollow,nextArea: PlayerWalkArea3D) -> void: match nextArea: PlayerWalkArea3D.AEntrance: peopleWalkFollow.player.setTargetPos(Vector3(-60,9.8,43),0.1) peopleWalkFollow.player.goToTarget() await peopleWalkFollow.player.ArriveTargetPos peopleWalkFollow.player.setTargetPos(Vector3(3,5.22,41),0.1) peopleWalkFollow.player.goToTarget() await peopleWalkFollow.player.ArriveTargetPos peopleWalkFollow.player.setTargetPos(Vector3(3,5.22,18.6),0.1) peopleWalkFollow.player.goToTarget() await peopleWalkFollow.player.ArriveTargetPos await get_tree().create_timer(1).timeout playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.BTicketingArea) PlayerWalkArea3D.BTicketingArea: var BTicketingAreaPos = Vector3(-11.27,5.22,15.73) if peopleWalkFollow.id % 2 == 0: BTicketingAreaPos = Vector3(-11.27,5.22,13.1) walkByPathFollow([BTicketingAreaPos],peopleWalkFollow) await peopleWalkFollow.player.ArriveTargetPos await get_tree().create_timer(5).timeout playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.AEntranceGateArea) PlayerWalkArea3D.AEntranceGateArea: var AEntranceGateAreaPos = Vector3(36,5.22,14) var playerNextPos = Vector3(-11.27,5.22,14.5) if peopleWalkFollow.id % 2 == 0: playerNextPos = Vector3(-11.27,5.22,11) walkByPathFollow([ playerNextPos],peopleWalkFollow) await peopleWalkFollow.player.ArriveTargetPos peopleWalkFollow.player.setTargetPos(Vector3(14,5.22,17),0.1) peopleWalkFollow.player.goToTarget() await peopleWalkFollow.player.ArriveTargetPos walkByPathFollow([AEntranceGateAreaPos],peopleWalkFollow) await peopleWalkFollow.player.ArriveTargetPos await get_tree().create_timer(1).timeout playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.BElevatorUpArea) PlayerWalkArea3D.BElevatorUpArea: var BElevatorUpAreaPos = Vector3(31,5.22,11.2) walkByPathFollow([Vector3(36,5.22,11.2),BElevatorUpAreaPos],peopleWalkFollow) await peopleWalkFollow.player.ArriveTargetPos await get_tree().create_timer(1).timeout playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.BElevatorDownArea) PlayerWalkArea3D.BElevatorDownArea: var BElevatorDownAreaPos = Vector3(13.54,0.85,11.2) walkByPathFollow([BElevatorDownAreaPos],peopleWalkFollow) await peopleWalkFollow.player.ArriveTargetPos playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.screenDoorWaitArea) PlayerWalkArea3D.screenDoorWaitArea: goToScreenDoorAreaAndWaitTrain(peopleWalkFollow,0) ##演示排队的区域 var screenDoorAreaInfo = [ { "areaName": "ScreenDoorWaitArea1", "screenDoorName": 'screenDoor1', }, { "areaName": "ScreenDoorWaitArea2", "screenDoorName": 'screenDoor2', }, { "areaName": "ScreenDoorWaitArea3", "screenDoorName": 'screenDoor3', }, { "areaName": "ScreenDoorWaitArea4", "screenDoorName": 'screenDoor4', }, ] ##进入指定屏蔽门区域并等待上车 func goToScreenDoorAreaAndWaitTrain(peopleWalkFollow:PlayerPathFollow, screenDoorAreaInfoIndex:int) -> void: var screenDoorPos = $platform.get_node(screenDoorAreaInfo[screenDoorAreaInfoIndex].screenDoorName).get_node('dimiantishi').get_global_position() var addPoint = Vector3(screenDoorPos.x,screenDoorPos.y,screenDoorPos.z+2) walkByPathFollow([addPoint,screenDoorPos],peopleWalkFollow) await self.screenDoorOpenConfirmSignal var trainPoint1 = Vector3(screenDoorPos.x,screenDoorPos.y,screenDoorPos.z-3) var trainPoint2 = Vector3(screenDoorPos.x+3,screenDoorPos.y,screenDoorPos.z-3) walkByPathFollow([trainPoint1,trainPoint2],peopleWalkFollow) await self.screenDoorCloseConfirmSignal peopleWalkFollow.queue_free() const ArrayUtils = preload("res://util/ArrayUtils.gd") func _on_screen_door_wait_area_screen_door_area_enter(curentArea: Area3D, peopleWalkFollow: PlayerPathFollow) -> void: var waitPeopleCounts = [$AllScreenDoorWaitArea/ScreenDoorWaitArea1.waitPeopleCount,$AllScreenDoorWaitArea/ScreenDoorWaitArea2.waitPeopleCount,$AllScreenDoorWaitArea/ScreenDoorWaitArea3.waitPeopleCount] for index in range(screenDoorAreaInfo.size()): if screenDoorAreaInfo[index].areaName == curentArea.name and curentArea.waitPeopleCount-1 <= ArrayUtils.removeElementByIndex(waitPeopleCounts,index).min() : peopleWalkFollow.peopleStopWalk() goToScreenDoorAreaAndWaitTrain(peopleWalkFollow,index) func _on_screen_door_wait_area_1_area_entered(area: Area3D) -> void: if $AllScreenDoorWaitArea/ScreenDoorWaitArea1.waitPeopleCount>=4 : trainComeAndLeace() ##通过PathFollow运动 func walkByPathFollow(allTargetPos:Array,peopleWalkFollow:PlayerPathFollow,curveAngle=Vector3()) -> void: var walkPoints = [peopleWalkFollow.player.position] for child in allTargetPos: var xOffset = child.x - peopleWalkFollow.buildPos.x var yOffset = child.y - peopleWalkFollow.buildPos.y var zOffset = child.z - peopleWalkFollow.buildPos.z walkPoints.append(Vector3(xOffset,yOffset,zOffset)) peopleWalkFollow.setPathPoints(walkPoints,curveAngle) peopleWalkFollow.peopleBeginWalk() var people_scene = preload("res://sceen/people/peoplewalkfollow.tscn") ##开始生成人的运动 func startGeneratePeople() -> void: $AllTimer/generatePeopleAEntranceTimer.start() ##A入口生成 var totalOfAEntrance=0 func _on_generate_people_a_entrance_timer_timeout() -> void: if totalOfAEntrance< 15: totalOfAEntrance += 1 #$AllTimer/generatePeopleAEntranceTimer.wait_time = 10000 var peoplrInstance = people_scene.instantiate() add_child(peoplrInstance) peoplrInstance.global_position = Vector3(-80,9.8,46) peoplrInstance.buildPos = Vector3(-80,9.8,46) peoplrInstance.speed = 1 peoplrInstance.id = totalOfAEntrance playerGoToNextArea(peoplrInstance,LargePassengerFlowScene.PlayerWalkArea3D.AEntrance) else : $AllTimer/generatePeopleAEntranceTimer.stop() ##下行站台生成 var totalOfDownPlatform=0 func _on_generate_people_down_platform_timer_timeout() -> void: if totalOfDownPlatform< 9: totalOfDownPlatform += 1 var peoplrInstance = people_scene.instantiate() add_child(peoplrInstance) peoplrInstance.global_position = Vector3(13.54,0.85,11.2) peoplrInstance.buildPos = Vector3(13.54,0.85,11.2) peoplrInstance.speed = 1 goToScreenDoorAreaAndWaitTrain(peoplrInstance,0) else : $AllTimer/generatePeopleDownPlatformTimer.stop() func trainComeAndLeace() -> void: self.trainComeAndOpenScreenDoor() await get_tree().create_timer(25).timeout self.closeScreenDoorAndTrainLeave() func _ready(): $platform.showCameraAndShortcutTool()