void HandleUpdateElevatorPositionRequest(UpdateElevatorPositionRequest request)
    {
        uint nextFloor = elevatorData.curFloorLevel;

        if (elevatorData.status == ElevatorStatus.MovingDown)
        {
            nextFloor = elevatorData.curFloorLevel - 1;
            FloorController floorController = GetFloorController(nextFloor);
            if (floorController)
            {
                if (request.positionY <= floorController.GetFittedElevatorAnchoredPositionY())
                {
                    elevatorData.curFloorLevel = nextFloor;
                    // Update elevator status
                    SendElevatorStatusResponseToAllFloor();
                }
            }
        }
        else if (elevatorData.status == ElevatorStatus.MovingUp)
        {
            nextFloor = elevatorData.curFloorLevel + 1;
            FloorController floorController = GetFloorController(nextFloor);
            if (floorController)
            {
                if (request.positionY >= floorController.GetFittedElevatorAnchoredPositionY())
                {
                    elevatorData.curFloorLevel = nextFloor;
                    // Update elevator status
                    SendElevatorStatusResponseToAllFloor();
                }
            }
        }

        // Elevator arrived
        if (elevatorData.curFloorLevel == curDestFloor)
        {
            // Remove cur floor from list requesting
            listFloorsRequesting.Remove(curDestFloor);

            // Update floor status using elevator status
            if (elevatorData.status == ElevatorStatus.MovingDown || elevatorData.status == ElevatorStatus.MovingUp)
            {
                FloorData floorData = GetFloorData(elevatorData.curFloorLevel);
                floorData.OnElevatorArrived(curElevatorDirection);

                ElevatorArrivedResponse elevatorArrivedResponse = new ElevatorArrivedResponse(floorData);
                SendElevatorArrivedResponse(elevatorArrivedResponse);
            }

            elevatorData.status = ElevatorStatus.Arrived;
            UpdateElevatorResponse response = new UpdateElevatorResponse(elevatorData, 0);
            SendUpdateElevatorResponse(response);
        }
        else
        {
            UpdateElevatorPositionResponse response = new UpdateElevatorPositionResponse(ResultCode.Succeeded, elevatorData.curFloorLevel);
            SendUpdateElevatorPositionResponse(response);
        }
    }
Пример #2
0
 public void OnGetUpdateElevatorPositionResponse(UpdateElevatorPositionResponse response)
 {
     if (response.resultCode == ResultCode.Succeeded)
     {
         elevatorData.curFloorLevel = response.newLevel;
         UpdateUI();
     }
 }
 void SendUpdateElevatorPositionResponse(UpdateElevatorPositionResponse response)
 {
     elevatorController?.OnGetUpdateElevatorPositionResponse(response);
     //Logger.Log(Logger.kTagRes, "SendUpdateElevatorPositionResponse " + JsonUtility.ToJson(response));
 }