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); }
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(); } }
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); }