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); }
public void GetGridSize(out int columns, out int rows) { columns = 0; rows = 0; if (this.m_gridData == null) { return; } for (int i = 0; i < this.m_gridData.Length; i++) { if (this.m_gridData[i] > 0) { rows++; columns = Mathf.Max(columns, WPFMonoBehaviour.GetNumberOfHighestBit(this.m_gridData[i]) + 1); } } }
public void LateUpdate() { if (!this.m_target) { return; } Vector3 vector = this.m_gameCamera.transform.position; Vector3 vector2 = this.m_target.transform.position; vector.z = 0f; vector2.z = 0f; Vector3 vector3 = vector2 - vector; float d = 1f; vector3 = vector3.normalized; vector -= vector3 * d; vector2 += vector3 * 0.5f; Vector3 vector4 = WPFMonoBehaviour.ClipAgainstViewport(vector, vector2); float num = Vector3.Distance(vector2, vector4); bool flag = false; if (num < 1f) { flag = true; } vector4 -= vector3 * d; Vector3 position = vector4 - vector3; Vector3 position2 = vector4; this.m_lineRenderer.SetPosition(0, position); this.m_lineRenderer.SetPosition(1, position2); if (flag) { this.m_alpha -= Time.deltaTime * 5f; } else { this.m_alpha += Time.deltaTime * 5f; } this.m_alpha = Mathf.Clamp01(this.m_alpha); Color white = Color.white; white.a = this.m_alpha; this.m_lineRenderer.SetColors(white, white); }
public override void InitGameMode() { base.CurrentConstructionGridRows = this.levelManager.m_constructionGridRows; int num = 1; int newGridHeight = 1; for (int i = 0; i < base.CurrentConstructionGridRows.Count; i++) { if (base.CurrentConstructionGridRows[i] != 0) { int numberOfHighestBit = WPFMonoBehaviour.GetNumberOfHighestBit(base.CurrentConstructionGridRows[i]); if (numberOfHighestBit + 1 > num) { num = numberOfHighestBit + 1; } newGridHeight = i + 1; } } int newGridXMin = -(num - 1) / 2; int newGridXMax = num / 2; Vector3 position = (!this.levelStart) ? Vector3.zero : this.levelStart.transform.position; this.levelManager.CreateGrid(num, newGridHeight, newGridXMin, newGridXMax, position); if (this.levelManager.ConstructionUI) { if (GameProgress.HasKey(SchematicButton.LastLoadedSlotKey, GameProgress.Location.Local, null)) { base.CurrentContraptionIndex = GameProgress.GetInt(SchematicButton.LastLoadedSlotKey, 0, GameProgress.Location.Local, null); } base.BuildContraption(WPFPrefs.LoadContraptionDataset(base.GetCurrentContraptionName())); } foreach (ConstructionUI.PartDesc partDesc in this.levelManager.ConstructionUI.PartDescriptors) { EventManager.Send(new PartCountChanged(partDesc.part.m_partType, partDesc.CurrentCount)); } GameObject gameObject = new GameObject("CollectibleStash"); gameObject.transform.parent = this.levelManager.transform; this.FindChallenges(); this.levelManager.m_CollectedDessertsCount = 0; this.PlaceDesserts(false); this.InitializeChallenges(); }
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); } }
public void Initialize(LevelManager newLevelManager) { EventManager.Connect(new EventManager.OnEvent <UIEvent>(this.ReceiveUIEvent)); EventManager.Connect(new EventManager.OnEvent <Pig.PigOutOfBounds>(this.OnPigOutOfBounds)); this.levelManager = newLevelManager; this.levelStart = WPFMonoBehaviour.FindSceneObjectOfType <LevelStart>(); Vector3 position = (!this.levelStart) ? Vector3.zero : this.levelStart.transform.position; if (this.gameData.m_contraptionPrefab) { Transform transform = UnityEngine.Object.Instantiate(this.gameData.m_contraptionPrefab, position, Quaternion.identity); this.ContraptionProto = transform.GetComponent <Contraption>(); } if (this.gameData.m_hudPrefab) { Transform transform2 = UnityEngine.Object.Instantiate(this.gameData.m_hudPrefab, position, Quaternion.identity); transform2.parent = this.levelManager.transform; } if (!this.ContraptionProto) { this.ContraptionProto = WPFMonoBehaviour.FindSceneObjectOfType <Contraption>(); } }
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; } }
public override void InitGameMode() { CakeRaceInfo?cakeRaceInfo = CakeRaceMode.cakeRaceInfo; if (cakeRaceInfo == null) { this.FindCakeRaceInfo(CakeRaceMode.currentRaceTrackIndex); } else { CakeRaceMode.currentRaceTrackIndex = CakeRaceMode.cakeRaceInfo.Value.TrackIndex; } this.gainedXP = 0; this.IsRaceOn = false; this.InitScoreVariables(); this.CreateCakes(); this.CreateProps(); base.Preview = this.CreatePreview(); base.CurrentConstructionGridRows = CakeRaceMode.cakeRaceInfo.Value.Start.GridData; base.CameraLimits = CakeRaceMode.cakeRaceInfo.Value.CameraLimits; base.GridCellPrefab = CakeRaceMode.cakeRaceInfo.Value.GridCellPrefab; base.TutorialPage = CakeRaceMode.cakeRaceInfo.Value.TutorialBookPrefab; int num = 1; int newGridHeight = 1; for (int i = 0; i < base.CurrentConstructionGridRows.Count; i++) { if (base.CurrentConstructionGridRows[i] != 0) { int numberOfHighestBit = WPFMonoBehaviour.GetNumberOfHighestBit(base.CurrentConstructionGridRows[i]); if (numberOfHighestBit + 1 > num) { num = numberOfHighestBit + 1; } newGridHeight = i + 1; } } int newGridXMin = -(num - 1) / 2; int newGridXMax = num / 2; this.levelManager.CreateGrid(num, newGridHeight, newGridXMin, newGridXMax, CakeRaceMode.cakeRaceInfo.Value.Start.Position); base.ContraptionProto.transform.position = CakeRaceMode.cakeRaceInfo.Value.Start.Position; this.InitParts(); base.CameraOffset = new Vector3(0f, 15f, 0f); base.PreviewOffset = new Vector3(0f, 15f, 0f); base.ConstructionOffset = new Vector3(0f, 0f, 0f); this.timeRunning = false; if (this.levelManager.ConstructionUI) { if (GameProgress.HasKey(SchematicButton.LastLoadedSlotKey, GameProgress.Location.Local, null)) { base.CurrentContraptionIndex = GameProgress.GetInt(SchematicButton.LastLoadedSlotKey, 0, GameProgress.Location.Local, null); } base.BuildContraption(WPFPrefs.LoadContraptionDataset(base.GetCurrentContraptionName())); foreach (ConstructionUI.PartDesc partDesc in this.levelManager.ConstructionUI.PartDescriptors) { EventManager.Send(new PartCountChanged(partDesc.part.m_partType, partDesc.CurrentCount)); } } EventManager.Connect(new EventManager.OnEvent <TimeBomb.BombOutOfBounds>(this.OnBombOutOfBounds)); }