示例#1
0
        private static IDisposable ConnectMove(IInputSource source, IInputTarget target)
        {
            //var observer = new InputArgsObserver(target, OnNextMove);
            //return source.Move.SubscribeSafe(observer);
            return(source.Move.Subscribe(OnNextMove));

            void OnNextMove(InputArgs args)
            {
                if (target.IsMoveAvailable())
                {
                    target.Move(args);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InputProcessor"/> class.
        /// </summary>
        /// <param name="source">The input source.</param>
        /// <param name="target">The input target.</param>
        public InputProcessor(IInputSource source, IInputTarget target)
        {
            _leftDownDisposable = source.LeftDown.Subscribe(
                (args) =>
            {
                if (target.IsLeftDownAvailable())
                {
                    target.LeftDown(args);
                }
            });

            _leftUpDisposable = source.LeftUp.Subscribe(
                (args) =>
            {
                if (target.IsLeftUpAvailable())
                {
                    target.LeftUp(args);
                }
            });

            _rightDownDisposable = source.RightDown.Subscribe(
                (args) =>
            {
                if (target.IsRightDownAvailable())
                {
                    target.RightDown(args);
                }
            });

            _rightUpDisposable = source.RightUp.Subscribe(
                (args) =>
            {
                if (target.IsRightUpAvailable())
                {
                    target.RightUp(args);
                }
            });

            _moveDisposable = source.Move.Subscribe(
                (args) =>
            {
                if (target.IsMoveAvailable())
                {
                    target.Move(args);
                }
            });
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InputProcessor"/> class.
        /// </summary>
        /// <param name="source">The input source.</param>
        /// <param name="target">The input target.</param>
        public InputProcessor(IInputSource source, IInputTarget target)
        {
            _leftDownDisposable = source.LeftDown.Subscribe(
                (v) =>
                {
                    if (target.IsLeftDownAvailable())
                    {
                        target.LeftDown(v.X, v.Y);
                    }
                });

            _leftUpDisposable = source.LeftUp.Subscribe(
                (v) =>
                {
                    if (target.IsLeftUpAvailable())
                    {
                        target.LeftUp(v.X, v.Y);
                    }
                });

            _rightDownDisposable = source.RightDown.Subscribe(
                (v) =>
                {
                    if (target.IsRightDownAvailable())
                    {
                        target.RightDown(v.X, v.Y);
                    }
                });

            _rightUpDisposable = source.RightUp.Subscribe(
                (v) =>
                {
                    if (target.IsRightUpAvailable())
                    {
                        target.RightUp(v.X, v.Y);
                    }
                });

            _moveDisposable = source.Move.Subscribe(
                (v) =>
                {
                    if (target.IsMoveAvailable())
                    {
                        target.Move(v.X, v.Y);
                    }
                });
        }
示例#4
0
        private static IDisposable ConnectMove(IInputSource source, IInputTarget target)
        {
#if USE_CUSTOM_OBSERVER
            var observer = new InputArgsObserver(target, OnNextMove);
            return(source.Move.Subscribe(observer));

            void OnNextMove(IInputTarget target, InputArgs args)
#else
            return(source.Move.Subscribe(OnNextMove));

            void OnNextMove(InputArgs args)
#endif
            {
                if (target.IsMoveAvailable())
                {
                    target.Move(args);
                }
            }
        }