Beispiel #1
0
        public void Initialize(CommandControllerUI controller, CommandUI parentCommand)
        {
            _controller   = controller;
            ParentCommand = parentCommand;

            _containerNestedMenu.gameObject.SetActive(false);
            _commandField.text = string.Empty;
        }
        public void DeleteCommand(CommandUI command)
        {
            if (command.ParentCommand != null)
            {
                command.ParentCommand.NestedCommands.Remove(command);
            }
            else
            {
                _firstLevelCommands.Remove(command);
            }

            command.gameObject.SetActive(false);
        }
        public void EditCommand(CommandUI commandUI, string newTextValue)
        {
            BaseCommand command;

            if (GameController.Instance().CommandsController.TryGetSimpleCommand(newTextValue, out command))
            {
                commandUI.ErrorWave.gameObject.SetActive(false);

                if (commandUI.HasNestedCommands && (command is DoCommand || command is WhileCommand))
                {
                    commandUI.MakeParent();
                }
            }
            else
            {
                commandUI.ErrorWave.gameObject.SetActive(true);
            }
        }
        public CommandUI AddCommand(Transform parentTransform = null, CommandUI parentCommand = null)
        {
            AudioManager.Instance().Play(AudioClips.Click);

            CommandUI newCommand = FindDisableCommand(_firstLevelCommands);

            if (newCommand != null)
            {
                //If get disable command need remove it from parent command
                if (newCommand.ParentCommand == null)
                {
                    _firstLevelCommands.Remove(newCommand);
                }
                else
                {
                    newCommand.ParentCommand.NestedCommands.Remove(newCommand);
                }

                newCommand.gameObject.SetActive(true);
            }
            else
            {
                newCommand = SpawnNewCommand();
            }

            if (parentTransform == null)
            {
                newCommand.transform.SetParent(transform, false);

                newCommand.Initialize(this, null);
                _firstLevelCommands.Add(newCommand);
            }
            else
            {
                newCommand.transform.parent = parentTransform;

                newCommand.Initialize(this, parentCommand);
                parentCommand.NestedCommands.Add(newCommand);
            }

            return(newCommand);
        }
        private CommandUI SpawnNewCommand()
        {
            CommandUI newInput = Instantiate(_defaultCommand.gameObject).GetComponent <CommandUI>();

            return(newInput);
        }