Пример #1
0
        public bool Home(IAxis Axis)
        {
            bool ret = false;

            if (!this.IsEnabled) // the controller is configured to be disabled in the config file
            {
                Axis.LastError = "the controller is disabled";
            }
            else if (!this.IsInitialized)   // the controller is not initialized
            {
                Axis.LastError = "the controller is not initialized";
            }
            else if (!Axis.IsEnabled)   // the axis moved is disabled in the config file
            {
                Axis.LastError = "the axis is disabled";
            }
            else
            {
                if (BusyAxesCount <= 0)
                {
                    OnMoveBegin?.Invoke(this, new EventArgs());
                }

                IncreaceBusyAxesCount();
                ret = HomeProcess(Axis);
                DecreaceBusyAxesCount();

                if (BusyAxesCount <= 0)
                {
                    OnMoveEnd?.Invoke(this, new EventArgs());
                }
            }

            return(ret);
        }
Пример #2
0
 public async void NotifyMoveEnd(Event e)
 {
     try
     {
         await UpdateBounds();
     }
     catch (Exception ex)
     {
         NotifyBackgroundExceptionOccurred(ex);
     }
     finally
     {
         OnMoveEnd?.Invoke(this, e);
     }
 }
Пример #3
0
    public virtual bool Move(Vector3 moveDir)
    {
        if (!IsCanDoAction())
        {
            return(false);
        }

        int moveRow = (int)(_thisObject.Row + moveDir.x);
        int moveCol = (int)(_thisObject.Col + moveDir.y);

        bool is_moving = false;

        if (IsCanMove(moveRow, moveCol))
        {
            is_moving = true;
        }
        else if (canTurnInPlace && IsCanMove(_thisObject.Row, _thisObject.Col))
        {
            _thisObject.MoveDirection = moveDir;
            is_moving  = true;
            _isInPlace = true;

            moveRow = _thisObject.Row;
            moveCol = _thisObject.Col;

            if (Utility.GetMainTargetCamera() != null)
            {
                Utility.GetMainTargetCamera().ShakeCamera(45.0f);
            }
        }

        if (is_moving)
        {
            LockObject();

            TileManager.Get.MoveObject(_thisObject, moveRow, moveCol);

            InternalOnlyMove(_thisObject.transform.position, TileManager.Get.GetTilePosition(moveRow, moveCol));

            if (OnMoveEndCallBack != null)
            {
                OnMoveEndCallBack.Invoke();
            }
            return(true);
        }
        return(false);
    }
Пример #4
0
        private void Update()
        {
            if (!_isMoving)
            {
                return;
            }

            if (Input.GetMouseButton(1))
            {
                OnMove?.Invoke(this, (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition) - _initialPosition);
            }
            else
            {
                _isMoving = false;
                OnMoveEnd?.Invoke(this, Camera.main.ScreenToWorldPoint(Input.mousePosition));
            }
        }
Пример #5
0
    private IEnumerator JoystickUpdate()
    {
        while (enabled)
        {
            yield return(new WaitUntil(() => Input.GetMouseButtonDown(0)));

            OnMoveBegin?.Invoke();

            var startPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            startPos.z = 0;

            while (Input.GetMouseButton(0))
            {
                var endPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                endPos.z = 0;

                var direction = endPos - startPos;
                direction = Vector3.ClampMagnitude(direction * sensitivity, maxSpeed);

                var temp = transform.position + (direction * Time.deltaTime);

                if (temp.x < MAX_WIDTH || temp.x > MIN_WIDTH)
                {
                    direction.x = 0;
                }
                if (temp.y < MAX_HEIGHT || temp.y > MIN_HEIGHT)
                {
                    direction.y = 0;
                }

                transform.up = direction;

                transform.position += direction * Time.deltaTime;

                OnMove?.Invoke(transform.position + direction);

                yield return(new WaitForFixedUpdate());
            }

            OnMoveEnd?.Invoke();
        }
    }
Пример #6
0
        protected IEnumerator SmoothMovement(Vector3 end)
        {
            IsMoving = true;
            {
                float sqrRemainingDistance = (transform.position - end).sqrMagnitude;
                while (sqrRemainingDistance > Mathf.Epsilon)
                {
                    Vector3 newPostion = Vector3.MoveTowards(_rb2D.position, end,
                                                             _inverseMoveTime * _unityService.GetDeltaTime());

                    _rb2D.MovePosition(newPostion);
                    sqrRemainingDistance = (transform.position - end).sqrMagnitude;
                    yield return(null);
                }

                _rb2D.MovePosition(end);
            }
            IsMoving = false;
            OnMoveEnd?.Invoke(this, null);
        }
Пример #7
0
        public bool Move(IAxis Axis, MoveMode Mode, int Speed, int Distance)
        {
            bool ret = false;

            if (!this.IsEnabled)
            {
                Axis.LastError = "the controller is disabled";
            }
            if (!this.IsInitialized)
            {
                Axis.LastError = "the controller is not initialized";
            }
            else if (!Axis.IsEnabled)
            {
                Axis.LastError = "the axis is disabled";
            }
            else if (!Axis.IsHomed)
            {
                Axis.LastError = "the axis is not homed";
            }
            else
            {
                if (BusyAxesCount <= 0)
                {
                    OnMoveBegin?.Invoke(this, new EventArgs());
                }

                IncreaceBusyAxesCount();

                ret = MoveProcess(Axis, Mode, Speed, Distance);

                DecreaceBusyAxesCount();

                if (BusyAxesCount <= 0)
                {
                    OnMoveEnd?.Invoke(this, new EventArgs());
                }
            }

            return(ret);
        }
Пример #8
0
    protected virtual void MoveUpdate()
    {
        float distJump = _currJumpHeight / _moveLeftTime;

        _moveLeftTime -= Time.deltaTime;

        if (_moveLeftTime <= 0.0f)
        {
            _currJumpHeight = 0.0f;
            _moveLeftTime   = 0.0f;
            if (OnMoveEndCallBack != null)
            {
                OnMoveEndCallBack.Invoke();
            }
            ChangeStatus(ActionStatus.IDLE);
        }
        else
        {
            float JumpDistance = Mathf.Sin(Mathf.PI + _moveLeftTime * Mathf.PI * 2 / _moveTimeSec) * _velocity * _jumpGuage * Time.deltaTime;
            _currJumpHeight += JumpDistance;
        }
        CalcPosition();
    }
Пример #9
0
 public void NotifyMoveEnd(Event eventArgs)
 {
     OnMoveEnd?.Invoke(this, eventArgs);
 }
Пример #10
0
 private void ForceMoveEndEvent()
 {
     OnMoveEnd?.Invoke(new OnMoveEndEventArgs(currentPlayer, isFirstStage, players));
 }
Пример #11
0
 public void NotifyMoveEnd(Event e) => OnMoveEnd?.Invoke(this, e);