public void Execute()
    {
        Command baseCommand;

        if (commandQueue.Count == 0)
        {
            UnityEngine.Debug.Log("RETURN");
            return;
        }

        baseCommand = commandQueue.Dequeue();

        switch (baseCommand.Type)
        {
        case CommandType.SetPosition:
        {
            SetPositionCommand setPositionCommand = (SetPositionCommand)baseCommand;
            Transform          newTransform       = setPositionCommand.transform;

            SetPositionResults result = new SetPositionResults(setPositionCommand.id, setPositionCommand.transform);

            resultsQueue.Enqueue(result);

            //ReturnToPool(setPositionPool, setPositionCommand);

            break;
        }
        }
    }
    // Adds a set position command to the queue
    public void SetPosition(Transform transform, int id)
    {
        //SetPositionCommand command = GetFromPool(setPositionPool);

        SetPositionCommand command = new SetPositionCommand();

        command.transform = transform;
        command.id        = id;
        QueueCommand(command);
    }
Пример #3
0
        private ICommand ParseSetPositionCommand(string toParse)
        {
            Position position = new Position(); 
            var arguments = toParse.Split(' '); 
            position.X = int.Parse(arguments[0]);
            position.Y = int.Parse(arguments[1]); 
            position.Direction = (Direction)Enum.Parse(typeof(Direction), arguments[2]);
            var setPositionCommand = new SetPositionCommand(position,_area);

            _positions.Add(position);
            return setPositionCommand;
        }
Пример #4
0
    /// <summary>
    /// Queue a command to set a Transform's position
    /// </summary>
    /// <param name="transform">
    /// Transform to set the position of
    /// </param>
    /// <param name="position">
    /// Position to set to the transform
    /// </param>
    /// <param name="result">
    /// Result to be filled in when the command executes. Must not be null.
    /// </param>
    /// <param name="result">
    /// Result to be filled in when the command executes. Must not be null.
    /// </param>
    public void SetPosition(
        Transform transform,
        Vector3 position,
        Result result)
    {
        Assert.IsTrue(transform != null);
        Assert.IsTrue(result != null);

        result.Reset();
        SetPositionCommand cmd = GetFromPool(setPositionPool);

        cmd.Transform = transform;
        cmd.Position  = position;
        cmd.Result    = result;
        QueueCommand(cmd);
    }
Пример #5
0
 /// <summary>
 /// Sets the position command handler.
 /// </summary>
 /// <param name="cmd">Cmd.</param>
 protected void SetPositionCommandHandler(SetPositionCommand cmd)
 {
     _cameraService.SetPosition(cmd.position);
 }
Пример #6
0
    /// <summary>
    /// Execute commands until there are none left or a maximum time is used
    /// </summary>
    /// <param name="maxMilliseconds">
    /// Maximum number of milliseconds to execute for. Must be positive.
    /// </param>
    public void Execute(int maxMilliseconds = int.MaxValue)
    {
        Assert.IsTrue(maxMilliseconds > 0);

        // Process commands until we run out of time
        executeLimitStopwatch.Reset();
        executeLimitStopwatch.Start();
        while (executeLimitStopwatch.ElapsedMilliseconds < maxMilliseconds)
        {
            // Get the next queued command, but stop if the queue is empty
            BaseCommand baseCmd;
            lock (commandQueue)
            {
                if (commandQueue.Count == 0)
                {
                    break;
                }
                baseCmd = commandQueue.Dequeue();
            }

            // Process the command. These steps are followed for each command:
            // 1. Extract the command's fields
            // 2. Reset the command's fields
            // 3. Do the work
            // 4. Return the command to its pool
            // 5. Make the result ready
            switch (baseCmd.Type)
            {
            case CommandType.NewGameObject:
            {
                // Extract the command's fields
                NewGameObjectCommand cmd = (NewGameObjectCommand)baseCmd;
                string name = cmd.Name;
                Result <GameObject> result = cmd.Result;

                // Reset the command's fields
                cmd.Name   = null;
                cmd.Result = null;

                // Return the command to its pool
                ReturnToPool(newGameObjectPool, cmd);

                // Do the work
                GameObject go = new GameObject(name);

                // Make the result ready
                result.Ready(go);
                break;
            }

            case CommandType.GetTransform:
            {
                // Extract the command's fields
                GetTransformCommand cmd    = (GetTransformCommand)baseCmd;
                GameObject          go     = cmd.GameObject;
                Result <Transform>  result = cmd.Result;

                // Reset the command's fields
                cmd.GameObject = null;
                cmd.Result     = null;

                // Return the command to its pool
                ReturnToPool(getTransformPool, cmd);

                // Do the work
                Transform transform = go.transform;

                // Make the result ready
                result.Ready(transform);
                break;
            }

            case CommandType.SetPosition:
            {
                // Extract the command's fields
                SetPositionCommand cmd       = (SetPositionCommand)baseCmd;
                Transform          transform = cmd.Transform;
                Vector3            position  = cmd.Position;
                Result             result    = cmd.Result;

                // Reset the command's fields
                cmd.Transform = null;
                cmd.Position  = Vector3.zero;
                cmd.Result    = null;

                // Return the command to its pool
                ReturnToPool(setPositionPool, cmd);

                // Do the work
                transform.position = position;

                // Make the result ready
                result.Ready();
                break;
            }
            }
        }
    }