Beispiel #1
0
    public void ChangeResultPos(CommandChangeResultPos _command)
    {
        DishResultContainer dishResultContainer = dishResultContainerArr[_command.pos];

        if (_command.targetPos == -1)
        {
            dishResultContainer.Clear();
        }
        else
        {
            DishResultContainer targetDishResultContainer = dishResultContainerArr[_command.targetPos];

            if (targetDishResultContainer.result == null)
            {
                targetDishResultContainer.SetResult(dishResultContainer.result);

                dishResultContainer.SetResult(null);
            }
            else
            {
                DishResultUnit tmpDishResult = targetDishResultContainer.result;

                targetDishResultContainer.SetResult(dishResultContainer.result);

                dishResultContainer.SetResult(tmpDishResult);
            }
        }
    }
Beispiel #2
0
    private void ClickRequirementUnitContainer(RequirementUnitContainer _container)
    {
        if (selectedUnitList.Count == _container.requirement.dishArr.Length)
        {
            List <int> list = new List <int>();

            for (int i = 0; i < selectedUnitList.Count; i++)
            {
                ControlUnit controlUnit = selectedUnitList[i];

                if (controlUnit is DishResultContainer)
                {
                    DishResultContainer container = controlUnit as DishResultContainer;

                    list.Add(container.index);
                }
                else
                {
                    DishResultBt bt = controlUnit as DishResultBt;

                    list.Add(-bt.dish.index - 1);
                }
            }

            if (client.CheckCanCompleteRequirement(list, _container.requirement))
            {
                //send command
                client.CompleteRequirement(list, _container.requirement.uid);
            }
        }

        ClearSelectedUnitList();
    }
Beispiel #3
0
    private void DragControlUnit(ControlUnit _startUnit, ControlUnit _endUnit)
    {
        if (_startUnit is SeatUnit)
        {
            SeatUnit unit = _startUnit as SeatUnit;

            if (_endUnit is SeatUnit)
            {
                SeatUnit endUnit = _endUnit as SeatUnit;

                if (endUnit.GetWorker() == null)
                {
                    //send command
                    client.ChangeWorkerPos(unit.GetWorker().index, endUnit.index);
                }
            }
        }
        else if (_startUnit is DishResultContainer)
        {
            DishResultContainer unit = _startUnit as DishResultContainer;

            if (_endUnit is DishResultContainer)
            {
                DishResultContainer endUnit = _endUnit as DishResultContainer;

                //send command
                client.ChangeResultPos(unit.index, endUnit.index);
            }
            else if (_endUnit is TrashContainer)
            {
                //send command
                client.ChangeResultPos(unit.index, -1);
            }
        }
        else
        {
            DishResultBt unit = _startUnit as DishResultBt;

            if (_endUnit is DishResultContainer)
            {
                DishResultContainer endUnit = _endUnit as DishResultContainer;

                if (endUnit.result == null)
                {
                    //send command
                    client.CompleteDish(unit.dish.index, endUnit.index);
                }
            }
            else if (_endUnit is TrashContainer)
            {
                //send command
                client.CompleteDish(unit.dish.index, -1);
            }
        }
    }
Beispiel #4
0
    public void Init(DishClientCore _core, bool _canControl)
    {
        core = _core;

        canControl = _canControl;

        trashContainer.Init(core);

        for (int i = 0; i < CookConst.RESULT_STATE.Length; i++)
        {
            GameObject go = GameObjectFactory.Instance.GetGameObject("Assets/Resource/prefab/resultContainer.prefab", null);

            go.transform.SetParent(dishResultContainer, false);

            (go.transform as RectTransform).anchoredPosition = new Vector2(i * dishResultGap, 0);

            DishResultContainer drc = go.GetComponent <DishResultContainer>();

            drc.Init(core, i, canControl);

            dishResultContainerArr[i] = drc;
        }

        for (int i = 0; i < CookConst.WORKER_NUM; i++)
        {
            GameObject go = GameObjectFactory.Instance.GetGameObject("Assets/Resource/prefab/workerUnit.prefab", null);

            WorkerUnit workerUnit = go.GetComponent <WorkerUnit>();

            workerArr[i] = workerUnit;

            workerUnit.Init(core, i);

            go = GameObjectFactory.Instance.GetGameObject("Assets/Resource/prefab/seat.prefab", null);

            go.transform.SetParent(seatContainer, false);

            (go.transform as RectTransform).anchoredPosition = new Vector2(i * seatGap, 0);

            SeatUnit seatUnit = go.GetComponent <SeatUnit>();

            seatUnit.Init(core, -i - 1, canControl);

            seatArr[i] = seatUnit;

            seatUnit.SetWorker(workerArr[i]);
        }
    }
Beispiel #5
0
    public void CompleteDish(CommandCompleteDish _command)
    {
        Dish dish = dishList[_command.pos];

        if (_command.targetPos != -1)
        {
            DishResultContainer dishResultContainer = dishResultContainerArr[_command.targetPos];

            dishResultContainer.SetResult(dish.resultUnit);

            dish.RemoveDishResult();
        }
        else
        {
            dish.DestroyDishResult();
        }
    }
Beispiel #6
0
    public void Clear()
    {
        for (int i = 0; i < CookConst.RESULT_STATE.Length; i++)
        {
            DishResultContainer drc = dishResultContainerArr[i];

            drc.Clear();
        }

        for (int i = 0; i < dishList.Count; i++)
        {
            Destroy(dishList[i].gameObject);
        }

        dishList.Clear();

        for (int i = 0; i < CookConst.WORKER_NUM; i++)
        {
            seatArr[i].SetWorker(workerArr[i]);
        }
    }
Beispiel #7
0
    public void RefreshData(PlayerData _playerData)
    {
        Clear();

        playerData = _playerData;

        money.text = playerData.money.ToString();

        List <DishData> dishDataList = playerData.dish;

        for (int i = 0; i < dishDataList.Count; i++)
        {
            DishData dishData = dishDataList[i];

            GameObject go = GameObjectFactory.Instance.GetGameObject("Assets/Resource/prefab/dish.prefab", null);

            go.transform.SetParent(dishContainer, false);

            (go.transform as RectTransform).anchoredPosition = new Vector2(0, -i * dishGap);

            Dish dish = go.GetComponent <Dish>();

            dish.Init(core, dishData, i, canControl);

            dishList.Add(dish);
        }

        DishResult[] dishResultArr = playerData.result;

        for (int i = 0; i < CookConst.RESULT_STATE.Length; i++)
        {
            DishResultContainer dishResultContainer = dishResultContainerArr[i];

            dishResultContainer.SetData(dishResultArr);

            DishResult dishResult = dishResultArr[i];

            if (dishResult != null)
            {
                GameObject go = GameObjectFactory.Instance.GetGameObject("Assets/Resource/prefab/dishResult.prefab", null);

                DishResultUnit dishResultUnit = go.GetComponent <DishResultUnit>();

                dishResultUnit.Init(core, dishResult);

                dishResultContainer.SetResult(dishResultUnit);
            }
        }

        for (int i = 0; i < CookConst.WORKER_NUM; i++)
        {
            Worker worker = playerData.workers[i];

            WorkerUnit workerUnit = workerArr[i];

            if (worker.pos < 0)
            {
                SeatUnit seat = seatArr[-worker.pos - 1];

                seat.SetWorker(workerUnit);
            }
            else
            {
                dishList[worker.pos].SetWorker(workerUnit);
            }
        }
    }
Beispiel #8
0
    private void ClickDishResultContainer(DishResultContainer _dishResultContainer)
    {
        if (selectedUnitList.Count == 0)
        {
            if (_dishResultContainer.result != null)
            {
                selectedUnitList.Add(_dishResultContainer);

                _dishResultContainer.SetSelected(true);
            }
        }
        else if (selectedUnitList.Count == 1)
        {
            ControlUnit lastSelectedUnit = selectedUnitList[0];

            if (lastSelectedUnit is DishResultBt)
            {
                if (_dishResultContainer.result == null)
                {
                    DishResultBt dishResultBt = lastSelectedUnit as DishResultBt;

                    //send command
                    client.CompleteDish(dishResultBt.dish.index, _dishResultContainer.index);

                    ClearSelectedUnitList();
                }
                else
                {
                    //ClearSelectedUnitList();

                    selectedUnitList.Add(_dishResultContainer);

                    _dishResultContainer.SetSelected(true);
                }
            }
            else if (lastSelectedUnit is DishResultContainer)
            {
                if (lastSelectedUnit == _dishResultContainer)
                {
                    ClearSelectedUnitList();
                }
                else
                {
                    if (_dishResultContainer.result == null)
                    {
                        DishResultContainer lastDishResultContainer = lastSelectedUnit as DishResultContainer;

                        //send command
                        client.ChangeResultPos(lastDishResultContainer.index, _dishResultContainer.index);

                        ClearSelectedUnitList();
                    }
                    else
                    {
                        selectedUnitList.Add(_dishResultContainer);

                        _dishResultContainer.SetSelected(true);
                    }
                }
            }
            else
            {
                ClearSelectedUnitList();

                if (_dishResultContainer.result != null)
                {
                    selectedUnitList.Add(_dishResultContainer);

                    _dishResultContainer.SetSelected(true);
                }
            }
        }
        else
        {
            if (_dishResultContainer.result != null)
            {
                int index = selectedUnitList.IndexOf(_dishResultContainer);

                if (index == -1)
                {
                    selectedUnitList.Add(_dishResultContainer);

                    _dishResultContainer.SetSelected(true);
                }
                else
                {
                    selectedUnitList.RemoveAt(index);

                    _dishResultContainer.SetSelected(false);
                }
            }
            else
            {
                ClearSelectedUnitList();
            }
        }
    }