Example #1
0
    public IEnumerator RoutineSendStatusUpdateRequest(ElevatorStatus newStatus, float delayTime)
    {
        yield return(new WaitForSeconds(delayTime));

        UpdateElevatorStatusRequest request = new UpdateElevatorStatusRequest(newStatus);

        onElevatorStatusUpdateCallback?.Invoke(request);
    }
    void HandleGetElevatorStatusUpdateRequest(UpdateElevatorStatusRequest request)
    {
        if (elevatorData.status == ElevatorStatus.Arrived && request.newStatus == ElevatorStatus.Opening)
        {
            elevatorData.status = ElevatorStatus.Opening;
            // Send both update status and update response to GUI
            UpdateElevatorStatusResponse updateStatusRepsonse = new UpdateElevatorStatusResponse(ResultCode.Succeeded, elevatorData.status);
            SendUpdateElevatorStatusResponse(updateStatusRepsonse);

            UpdateElevatorResponse updateElevatorResponse = new UpdateElevatorResponse(elevatorData, 0);
            SendUpdateElevatorResponse(updateElevatorResponse);
        }

        if (elevatorData.status == ElevatorStatus.Opening && request.newStatus == ElevatorStatus.Opened)
        {
            elevatorData.status = ElevatorStatus.Opened;
            UpdateElevatorStatusResponse response = new UpdateElevatorStatusResponse(ResultCode.Succeeded, elevatorData.status);
            SendUpdateElevatorStatusResponse(response);
        }

        if (elevatorData.status == ElevatorStatus.Opened && request.newStatus == ElevatorStatus.Closing)
        {
            elevatorData.status = ElevatorStatus.Closing;
            UpdateElevatorStatusResponse updateStatusResponse = new UpdateElevatorStatusResponse(ResultCode.Succeeded, elevatorData.status);
            SendUpdateElevatorStatusResponse(updateStatusResponse);

            UpdateElevatorResponse updateElevatorResponse = new UpdateElevatorResponse(elevatorData, 0);
            SendUpdateElevatorResponse(updateElevatorResponse);
        }

        if (elevatorData.status == ElevatorStatus.Closing && request.newStatus == ElevatorStatus.Closed)
        {
            elevatorData.status = ElevatorStatus.Closed;
            UpdateElevatorStatusResponse updateStatusResponse = new UpdateElevatorStatusResponse(ResultCode.Succeeded, elevatorData.status);
            SendUpdateElevatorStatusResponse(updateStatusResponse);

            UpdateElevator();
        }
    }
 void OnGetElevatorStatusUpdateRequest(UpdateElevatorStatusRequest request)
 {
     Logger.Log(logTagReq, "OnGetElevatorStatusUpdateRequest" + JsonUtility.ToJson(request));
     HandleGetElevatorStatusUpdateRequest(request);
 }