private Vector3 GetPanDelta() { if (!this.isPanning) { return(Vector3.zero); } if (!DeviceInfo.UsesTouchInput) { Vector3 vector = WPFMonoBehaviour.ScreenToZ0(this.m_panStartPosition) - WPFMonoBehaviour.ScreenToZ0(Input.mousePosition); this.m_panStartPosition = Input.mousePosition; this.CalculatePanningSpeed(vector); return(vector); } if (Input.touchCount != 1) { return(Vector3.zero); } Touch touch = Input.GetTouch(0); if (touch.fingerId != this.m_panTouchFingerId) { return(Vector3.zero); } Vector3 vector2 = WPFMonoBehaviour.ScreenToZ0(this.m_panStartPosition) - WPFMonoBehaviour.ScreenToZ0(touch.position); this.m_panStartPosition = touch.position; this.CalculatePanningSpeed(vector2); return(vector2); }
private void UpdateCameraPreview(ref Vector3 currentPos, ref float currentFOV) { Vector3 b = this.GetPanDelta(); if (!this.isPanning && this.m_panningSpeed > 10f) { b = Time.deltaTime * (this.m_panningSpeed - 10f) * this.m_panningVelocity.normalized; this.m_panningSpeed *= Mathf.Pow(0.925f, Time.deltaTime / 0.0166666675f); } currentPos += b; float zoomDelta = this.GetZoomDelta(); if (!this.m_transitionToPreviewActive || zoomDelta > 0f) { float num = currentFOV; currentFOV += zoomDelta; float min = (!this.m_transitionToPreviewActive) ? 9f : this.m_cameraBuildZoom; currentFOV = Mathf.Clamp(currentFOV, min, this.m_cameraMaxZoom); float num2 = currentFOV - num; if (num2 < 0f) { Vector3 a = WPFMonoBehaviour.ScreenToZ0(Input.mousePosition) - currentPos; a.z = 0f; Vector3 vector = -0.15f * num2 * a; Vector3 a2 = currentPos + vector; this.EnforceCameraLimits(ref a2, ref currentFOV); Vector3 b2 = a2 - (currentPos + vector); vector += b2; this.panPosition += vector; currentPos += vector; } } if (GuiManager.GetPointer().doubleClick&& !GuiManager.GetPointer().onWidget) { WPFMonoBehaviour.levelManager.SetGameState(LevelManager.GameState.Building); Singleton <AudioManager> .Instance.Play2dEffect(WPFMonoBehaviour.gameData.commonAudioCollection.cameraZoomIn); } }
private void UpdateCameraFollow(ref Vector3 currentPos, ref float currentFOV) { if (WPFMonoBehaviour.levelManager.ContraptionRunning == null) { return; } this.AutoZoom(ref currentPos, ref currentFOV); float zoomDelta = this.GetZoomDelta(); if (currentFOV < this.m_cameraMinZoom) { float num = this.m_cameraMinZoom - currentFOV; currentFOV += 3.5f * num * GameTime.DeltaTime; } Vector3 position = WPFMonoBehaviour.levelManager.ContraptionRunning.m_cameraTarget.transform.position; float f = (currentPos.x - position.x) / (currentFOV * ((float)Screen.width / (float)Screen.height)); float f2 = (currentPos.y - position.y) / currentFOV; if ((Mathf.Abs(f) > 1f || Mathf.Abs(f2) > 1f) && !this.m_returningToDefaultPosition) { if (this.isPanning || zoomDelta != 0f) { this.m_freeCameraMode = true; } } else if (this.m_freeCameraMode) { this.m_freeCameraMode = false; this.m_returningToDefaultPosition = true; this.m_returnToCenterSpeed = 50f; } Vector3 a; if (this.m_freeCameraMode) { a = Vector3.zero; } else { a = position + Vector3.ClampMagnitude(WPFMonoBehaviour.levelManager.ContraptionRunning.m_cameraTarget.GetComponent <Rigidbody>().velocity * 1.5f, 20f) - (currentPos - this.panPosition); } currentPos += a * GameTime.DeltaTime; if (this.isPanning || this.m_panningSpeed > 10f) { Vector3 vector = this.GetPanDelta(); if (!this.isPanning) { vector = Time.deltaTime * (this.m_panningSpeed - 10f) * this.m_panningVelocity.normalized; this.m_panningSpeed *= Mathf.Pow(0.925f, Time.deltaTime / 0.0166666675f); } this.m_autoZoomEnabled = false; this.m_autoZoomAmount = 0f; Vector3 a2 = currentPos + vector; this.EnforceCameraLimits(ref a2, ref currentFOV); Vector3 b = a2 - (currentPos + vector); vector += b; this.panPosition += vector; currentPos += vector; } if (zoomDelta != 0f) { if (Mathf.Abs(zoomDelta) > 0.01f) { this.m_returningToDefaultPosition = false; this.m_autoZoomEnabled = false; this.m_autoZoomAmount = 0f; } float num2 = currentFOV; currentFOV += zoomDelta; currentFOV = Mathf.Clamp(currentFOV, this.m_cameraMinZoom, this.m_cameraMaxZoom); Vector3 a3 = currentPos; this.EnforceCameraLimits(ref a3, ref currentFOV); Vector3 b2 = a3 - currentPos; this.panPosition += b2; float num3 = currentFOV - num2; if (num3 < 0f) { Vector3 a4 = WPFMonoBehaviour.ScreenToZ0(Input.mousePosition) - currentPos; a4.z = 0f; Vector3 vector2 = -0.15f * num3 * a4; Vector3 a5 = currentPos + vector2; this.EnforceCameraLimits(ref a5, ref currentFOV); Vector3 b3 = a5 - (currentPos + vector2); vector2 += b3; this.panPosition += vector2; currentPos += vector2; } } if (GuiManager.GetPointer().doubleClick&& !GuiManager.GetPointer().onWidget) { this.m_returningToDefaultPosition = true; if (this.m_freeCameraMode) { this.m_returnToCenterSpeed = 50f; } } else if (GuiManager.TouchCount != 0) { this.m_returningToDefaultPosition = false; } if (this.m_returningToDefaultPosition) { if (this.m_freeCameraMode) { this.m_freeCameraMode = false; } this.m_autoZoomEnabled = true; Vector3 b4 = currentPos - this.panPosition; this.EnforceCameraLimits(ref b4, ref currentFOV); if (this.m_returnToCenterSpeed < 200f) { this.m_returnToCenterSpeed += 100f * Time.deltaTime; } Vector3 a6 = -this.panPosition; if (a6.sqrMagnitude > 1f) { a6 = a6.normalized; } Vector3 vector3 = this.m_returnToCenterSpeed * Time.deltaTime * a6; Vector3 a7 = currentPos + vector3; this.EnforceCameraLimits(ref a7, ref currentFOV); Vector3 b5 = a7 - (currentPos + vector3); vector3 += b5; this.panPosition += vector3; currentPos += vector3; if (Vector3.Distance(currentPos, b4) < 0.01f && Mathf.Abs(this.m_cameraMinZoom - currentFOV) < 0.01f) { this.m_returningToDefaultPosition = false; } if (currentFOV > this.m_cameraMinZoom) { float num4 = this.m_cameraMinZoom - currentFOV; num4 = Mathf.Clamp(num4, -1f, 1f); currentFOV += 0.2f * this.m_returnToCenterSpeed * num4 * Time.deltaTime; } } else if (!this.isPanning && zoomDelta == 0f) { this.m_returnToCenterTimer += Time.deltaTime; if (this.m_returnToCenterTimer > 4f) { if (this.m_freeCameraMode) { this.m_returnToCenterSpeed = 50f; } this.m_freeCameraMode = false; if (this.m_returnToCenterSpeed < 80f) { this.m_returnToCenterSpeed += 40f * Time.deltaTime; } Vector3 a8 = -this.panPosition; if (a8.sqrMagnitude > 1f) { a8 = a8.normalized; } Vector3 vector4 = this.m_returnToCenterSpeed * Time.deltaTime * a8; Vector3 a9 = currentPos + vector4; this.EnforceCameraLimits(ref a9, ref currentFOV); Vector3 b6 = a9 - (currentPos + vector4); vector4 += b6; this.panPosition += vector4; currentPos += vector4; } } else { this.m_returnToCenterTimer = 0f; this.m_returnToCenterSpeed = 0f; } }