Esempio n. 1
0
    /// <summary>
    /// move to destinated room
    /// </summary>
    /// <param name="points">way-points to reach room</param>
    /// <returns>null</returns>
    private IEnumerator MoveToDestination(List <Transform> points, Room r, WorkSpot workSpot)
    {
        int index = 0;

        while (index < points.Count)
        {
            transform.localPositionTransition(points[index].position, 2f);

            while (transform.position != points[index].position)
            {
                yield return(new WaitForEndOfFrame());
            }
            index++;
        }

        _currentState = State.Working;
        UpgradeManager.Instance.GetRoomData(_currentRoomIndex).AddWorker();

        _spriteRenderer.sortingOrder = DefaultSorting;
        if (workSpot.DestinationWay.Count > 0)
        {
            StartCoroutine(MoveToDestinationSpot(workSpot.DestinationWay));
        }
        else
        {
            transform.localPositionTransition(workSpot.SpotPosition.position, 1f);
        }

        _currentWorkSpot = workSpot;

        _clicked = false;

        yield return(null);
    }
Esempio n. 2
0
    private void Update()
    {
        if (_selected)
        {
            if (Input.GetMouseButtonDown(0))
            {
                _clicked = true;
            }
        }


        if (_clicked && Input.GetMouseButtonDown(1) && _currentState != State.Changing)
        {
            Room r = GetClickedRoom();

            if (r != null)
            {
                WorkSpot workingSpot = r.GetWorkingSpot();
                workingSpot.IsFree = false;
                if (_currentState == State.Waiting)
                {
                    StartChangingRoom(0, r.RoomIndex, r, true, workingSpot);
                }
                if (_currentState == State.Working)
                {
                    Panel data = UpgradeManager.Instance.GetRoomData(_currentRoomIndex);
                    if (data != null)
                    {
                        data.RemoveWorker();
                    }
                    UpgradeManager.Instance.GetRoomData(_currentRoomIndex).RemoveWorker();

                    if (_currentWorkSpot != null && _currentWorkSpot.DestinationWay.Count > 0)
                    {
                        _currentState = State.Changing;
                        _spriteRenderer.sortingOrder = MoveSorting;
                        StartCoroutine(MoveToDestination(GameController.Instance.WayPointHandler.GetWayFromOutside(r.RoomIndex), r, workingSpot));
                        _currentRoomIndex = r.RoomIndex;
                    }
                    else
                    {
                        StartChangingRoom(_currentRoomIndex, r.RoomIndex, r, false, workingSpot);
                    }
                }
            }
        }
    }
Esempio n. 3
0
    private void StartChangingRoom(int current, int target, Room r, bool isFirstPlace, WorkSpot targetSpot)
    {
        _currentState = State.Changing;
        _spriteRenderer.sortingOrder = MoveSorting;
        List <Transform> points = GameController.Instance.WayPointHandler.GetWayPoints(current, target, isFirstPlace);

        StartCoroutine(MoveToDestination(points, r, targetSpot));
        _currentRoomIndex = target;
    }