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 IEnumerator RoutineMoving(float destinationY)
    {
        bool    isFinished = false;
        Vector2 temp       = rectTransform.anchoredPosition;

        while (isFinished == false)
        {
            temp = rectTransform.anchoredPosition;
            if (elevatorData.status == ElevatorStatus.MovingDown)
            {
                temp.y -= speed * Time.deltaTime;
                if (temp.y <= destinationY)
                {
                    isFinished = true;
                }
            }
            else if (elevatorData.status == ElevatorStatus.MovingUp)
            {
                temp.y += speed * Time.deltaTime;
                if (temp.y >= destinationY)
                {
                    isFinished = true;
                }
            }

            rectTransform.anchoredPosition = temp;

            UpdateElevatorPositionRequest request = new UpdateElevatorPositionRequest(rectTransform.anchoredPosition.y);
            onUpdateElevatorPositionCallback?.Invoke(request);
            yield return(new WaitForEndOfFrame());
        }
        temp.y = destinationY;
        rectTransform.anchoredPosition = temp;

        yield return(new WaitForEndOfFrame());
    }
 void OnGetUpdateElevatorPositionRequest(UpdateElevatorPositionRequest request)
 {
     //Logger.Log(logTagReq, "OnGetUpdateElevatorPositionRequest " + JsonUtility.ToJson(request));
     HandleUpdateElevatorPositionRequest(request);
 }