void Start() { CursorPlane = eCursorPlane.XYPlane; m_lastCursorPosition = this.transform.position; m_lastCursorPlane = CursorPlane; m_cursorIcon = this.transform.FindChild("Icon").gameObject; m_cursorIconRenderer = m_cursorIcon.GetComponent <MeshRenderer>(); SetCursorTexture(null); }
void Update() { CursorConstraints constraints = GetCursorConstraints(); Vector3 currentCursorPosition = this.transform.position; Vector3 desiredCursorPosition = currentCursorPosition; Quaternion desiredCursorOrientation = this.transform.rotation; Vector3 mouseDelta; mouseDelta.x = Input.GetAxis("Mouse X"); mouseDelta.y = Input.GetAxis("Mouse Y"); mouseDelta.z = 0.0f; // Keep the mouse hidden and locked Screen.showCursor = false; Screen.lockCursor = true; // Remember where the cursor was before it moves m_lastCursorPlane = CursorPlane; m_lastCursorPosition = currentCursorPosition; // Move the cursor switch (CursorPlane) { case eCursorPlane.XYPlane: { desiredCursorPosition.x = currentCursorPosition.x + mouseDelta.x * constraints.XYSpeedScale; desiredCursorPosition.y = currentCursorPosition.y + mouseDelta.y * constraints.XYSpeedScale; if (desiredCursorPosition.y < constraints.YMin && constraints.AllowXZPlane) { // Fold the remaining downward motion onto the XZ plane desiredCursorPosition.z = constraints.ZMax - (constraints.YMin - desiredCursorPosition.y); desiredCursorPosition.y = constraints.YMin; // Make the cursor perpendicular to the XZ plane desiredCursorOrientation = XZ_ORIENTATION; // Keep track of the cursor plane change CursorPlane = eCursorPlane.XZPlane; } } break; case eCursorPlane.XZPlane: { desiredCursorPosition.x = currentCursorPosition.x + mouseDelta.x * constraints.XZSpeedScale; desiredCursorPosition.z = currentCursorPosition.z + mouseDelta.y * constraints.XZSpeedScale; if (desiredCursorPosition.z > constraints.ZMax && constraints.AllowXZPlane) { // Fold the remaining Z+ motion onto the XY plane desiredCursorPosition.y = constraints.YMin + (desiredCursorPosition.z - constraints.ZMax); desiredCursorPosition.z = constraints.ZMax; // Make the cursor perpendicular to the XZ plane desiredCursorOrientation = XY_ORIENTATION; // Keep track of the cursor plane change CursorPlane = eCursorPlane.XYPlane; } } break; } // Keep cursor position in bounds at all times desiredCursorPosition = constraints.SnapPositionInsideBounds(desiredCursorPosition); // Update cursor position and orientation this.transform.position = desiredCursorPosition; this.transform.rotation = desiredCursorOrientation; }
void Update() { CursorConstraints constraints= GetCursorConstraints(); Vector3 currentCursorPosition = this.transform.position; Vector3 desiredCursorPosition = currentCursorPosition; Quaternion desiredCursorOrientation = this.transform.rotation; Vector3 mouseDelta; mouseDelta.x = Input.GetAxis("Mouse X"); mouseDelta.y = Input.GetAxis("Mouse Y"); mouseDelta.z = 0.0f; // Keep the mouse hidden and locked Screen.showCursor = false; Screen.lockCursor = true; // Remember where the cursor was before it moves m_lastCursorPlane = CursorPlane; m_lastCursorPosition = currentCursorPosition; // Move the cursor switch (CursorPlane) { case eCursorPlane.XYPlane: { desiredCursorPosition.x = currentCursorPosition.x + mouseDelta.x * constraints.XYSpeedScale; desiredCursorPosition.y = currentCursorPosition.y + mouseDelta.y * constraints.XYSpeedScale; if (desiredCursorPosition.y < constraints.YMin && constraints.AllowXZPlane) { // Fold the remaining downward motion onto the XZ plane desiredCursorPosition.z = constraints.ZMax - (constraints.YMin - desiredCursorPosition.y); desiredCursorPosition.y = constraints.YMin; // Make the cursor perpendicular to the XZ plane desiredCursorOrientation = XZ_ORIENTATION; // Keep track of the cursor plane change CursorPlane = eCursorPlane.XZPlane; } } break; case eCursorPlane.XZPlane: { desiredCursorPosition.x = currentCursorPosition.x + mouseDelta.x * constraints.XZSpeedScale; desiredCursorPosition.z = currentCursorPosition.z + mouseDelta.y * constraints.XZSpeedScale; if (desiredCursorPosition.z > constraints.ZMax && constraints.AllowXZPlane) { // Fold the remaining Z+ motion onto the XY plane desiredCursorPosition.y = constraints.YMin + (desiredCursorPosition.z - constraints.ZMax); desiredCursorPosition.z = constraints.ZMax; // Make the cursor perpendicular to the XZ plane desiredCursorOrientation = XY_ORIENTATION; // Keep track of the cursor plane change CursorPlane = eCursorPlane.XYPlane; } } break; } // Keep cursor position in bounds at all times desiredCursorPosition = constraints.SnapPositionInsideBounds(desiredCursorPosition); // Update cursor position and orientation this.transform.position = desiredCursorPosition; this.transform.rotation = desiredCursorOrientation; }
void Start() { CursorPlane = eCursorPlane.XYPlane; m_lastCursorPosition= this.transform.position; m_lastCursorPlane = CursorPlane; m_cursorIcon = this.transform.FindChild("Icon").gameObject; m_cursorIconRenderer = m_cursorIcon.GetComponent<MeshRenderer>(); SetCursorTexture(null); }