private void SetVelocity(Vector2 velocity) { _rigidbody2D.velocity = velocity; if (!_isMoving && _rigidbody2D.velocity != Vector2.zero) { _isMoving = true; _onMoveStart.Invoke(); } else if (_isMoving && _rigidbody2D.velocity == Vector2.zero) { _isMoving = false; _onMoveEnd.Invoke(); } }
private void OnMoveEnd(object sender, EventArgs e) { MoveEnd?.Invoke(sender, e); }
/// <summary> /// 控制目标 /// </summary> private void ControlTarget() { if (Input.GetKeyDown(KeyCode.Mouse0)) { m_MouseDonw = true; m_IsMove = false; } if (Input.GetKey(KeyCode.Mouse0)) { float inputX = Input.GetAxis("Mouse X"); float inputY = Input.GetAxis("Mouse Y"); float x = 0; float y = 0; float z = 0; switch (m_SelectedAxis) { case RuntimeHandleAxis.None: break; case RuntimeHandleAxis.X: if (!LockX) { x = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.right); } break; case RuntimeHandleAxis.Y: if (!LockY) { y = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.up); } break; case RuntimeHandleAxis.Z: if (!LockZ) { z = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.forward); } break; case RuntimeHandleAxis.XY: if (!LockX) { x = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.right); } if (!LockY) { y = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.up); } break; case RuntimeHandleAxis.XZ: if (!LockX) { x = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.right); } if (!LockZ) { z = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.forward); } break; case RuntimeHandleAxis.YZ: if (!LockY) { y = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.up); } if (!LockZ) { z = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.forward); } break; case RuntimeHandleAxis.XYZ: x = y = z = inputX; break; default: break; } if (!m_IsMove && (x != 0 || y != 0 || z != 0)) { m_IsMove = true; } m_CurrentHandle.Transform(new Vector3(x, y, z) * m_ScreenScale); } if (Input.GetKeyUp(KeyCode.Mouse0)) { m_MouseDonw = false; if (m_IsMove) { MoveEnd?.Invoke(transform.position); } } }