示例#1
0
        public DispatcherOptions Dispatch(Type type, params object[] parameters)
        {
            var options = new DispatcherOptions(this);

            this.Dispatch(type, options, parameters);
            return(options);
        }
示例#2
0
        public DispatcherOptions InvokeDispatch(Type type, float time, params object[] parameters)
        {
            var options = new DispatcherOptions(this);

            this.StartCoroutine(this.DispatchByTimer(type, options, time, parameters));
            return(options);
        }
示例#3
0
        /// <summary>
        /// Dispatches a command by type.
        /// </summary>
        /// <param name="type">The type of the command to be dispatched.</typeparam>
        /// <param name="options">Dispatcher options to be applied to the command.</param>
        /// <param name="parameters">Command parameters.</param>
        private void Dispatch(Type type, DispatcherOptions options, params object[] parameters)
        {
            if (this.ContainsRegistration(type))
            {
                ICommand command = null;

                var item = this.commands[type];
                if (item is ICommand)
                {
                    // Singleton.
                    command = (ICommand)item;
                }
                else
                {
                    // Transient.
                    command = this.GetCommandFromPool(type, (List <ICommand>)item);
                    this.container.Inject(command);
                }

                command.dispatcher = this;
                command.running    = true;
                command.Execute(parameters);
                options.command = command;

                if (command.keepAlive)
                {
                    if (command is IUpdatable && !eventCallerExtension.updateable.Contains((IUpdatable)command))
                    {
                        eventCallerExtension.updateable.Add((IUpdatable)command);
                    }
                }
                else
                {
                    this.Release(command);
                }
            }
            else
            {
                throw new CommandException(
                          string.Format(CommandException.NO_COMMAND_FOR_TYPE, type));
            }
        }
示例#4
0
        /// <summary>
        /// Dispatches a command by type after a given time in seconds.
        /// </summary>
        /// <param name="type">The type of the command to be dispatched.</param>
        /// <param name="options">Dispatcher options.</param>
        /// <param name="time">Time to dispatch the command (seconds).</param>
        /// <param name="parameters">Command parameters.</param>
        private IEnumerator DispatchByTimer(Type type, DispatcherOptions options, float time, params object[] parameters)
        {
            yield return(new UnityEngine.WaitForSeconds(time));

            this.Dispatch(type, options, parameters);
        }