Exemplo n.º 1
0
        void ShowPanel(Vector3 position, Transform interactableTransform, CommandType possibleCommands)
        {
            commandPanel.transform.position = new Vector3(position.x, position.y, commandPanel.transform.position.z);

            if (!possibleCommands.HasFlag(CommandType.NONE))
            {
                foreach (CommandType commandType in GetFlags(possibleCommands))
                {
                    CommandButton button = commandButtons.AddCommand(commandType);
                    SetCommandAction(button, position, interactableTransform, commandType);
                }
                //
                // foreach (CommandType commandType in Enum.GetValues(typeof(CommandType)))
                // {
                //     if (commandType == CommandType.NONE)
                //         continue;
                //
                //     CommandButton button = commandButtons.AddCommand(commandType);
                //     SetCommandAction(button, position, interactableTransform, commandType);
                // }

                commandButtons.PositionChildren();
            }

            commandPanel.SetActive(true);
            commandInput.panelOpen = true;
            StartCoroutine(commandButtons.ShowButtons());
        }
Exemplo n.º 2
0
        void SetCommandAction(CommandButton button, Vector3 position, Transform interactableTransform, CommandType commandType)
        {
            switch (commandType)
            {
            case CommandType.NONE:
                break;

            case CommandType.MOVE:
                button.SetCommand(() =>
                {
                    commandManager.AddCommand(new MovePositionCommand(position));
                    HidePanel();
                });
                break;

            case CommandType.FEED:
                button.SetCommand(() =>
                {
                    commandManager.AddCommand(new MoveAndInteractCommand(interactableTransform, typeof(IFeedable)));
                    HidePanel();
                });
                break;

            case CommandType.PLANT_FUEL:
                button.SetCommand(() =>
                {
                    commandManager.AddCommand(new PlantCommand(position));
                    HidePanel();
                });
                break;

            case CommandType.HARVEST:
                button.SetCommand(() =>
                {
                    commandManager.AddCommand(new MoveAndInteractCommand(interactableTransform, typeof(IHarvestable)));
                    HidePanel();
                });
                break;

            case CommandType.CRAFT:
                button.SetCommand(() =>
                {
                    HidePanel();
                });
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(commandType), commandType, null);
            }
        }