void Update() { //Allow RMB panning only in certain modes, otherwise force wasd movement bool canPan = (editor.currentMode == LevelEditorBehaviour.EditMode.Events || editor.currentMode == LevelEditorBehaviour.EditMode.Links); if (Settings.LoadFromMemory && Controller.obj.levelEventController.hasLoaded && Settings.FollowRaymanInMemoryMode) { var rayman = LevelEditorData.Level.Rayman; if (rayman != null) { pos = new Vector3(rayman.XPosition / (float)LevelEditorData.Level.PixelsPerUnit, -(rayman.YPosition / (float)LevelEditorData.Level.PixelsPerUnit)); } } Vector3 mouseDeltaOrtho = Input.mousePosition - lastMousePosition; lastMousePosition = Input.mousePosition; if (LevelEditorData.Level != null) { // RMB scroling if (Input.GetMouseButton(1) && canPan) { if (!panStart.HasValue) { panStart = Input.mousePosition; } Rect screenRect = new Rect(0, 0, Screen.width, Screen.height); if (panning) { float xFactor = Camera.main.orthographicSize * 2.0f / Camera.main.pixelHeight; float yFactor = Camera.main.orthographicSize * 2.0f / Camera.main.pixelHeight; /*vel = 0.8f * Vector3.Lerp(vel, Vector3.ClampMagnitude(mousePosPrev - mousePosition, 50) * fov, * inertia <= 0 ? 1 : Time.deltaTime * 1f / inertia);*/ friction = fricStart; pos += new Vector3(-mouseDeltaOrtho.x * xFactor, -mouseDeltaOrtho.y * yFactor); } else if (Input.GetMouseButtonDown(1) && screenRect.Contains(Input.mousePosition)) // Only start panning if within game window when you click { panning = true; } } else { panStart = null; panning = false; } // Mouse wheel zooming if (!EventSystem.current.IsPointerOverGameObject()) { fov = Mathf.Clamp(fov - 0.25f * Input.mouseScrollDelta.y * fov, 3.75f, 50); } // WASD scrolling bool scrollLeft = Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A); bool scrollRight = Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D); bool scrollUp = Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W); bool scrollDown = Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S); bool scrolling = scrollLeft || scrollRight || scrollUp || scrollDown; if (scrolling || editor.scrolling) { friction = 30; } float scr = friction * Camera.main.orthographicSize * WASDScrollSpeed * Time.deltaTime; if (scrollLeft) { vel.x -= scr; } if (scrollRight) { vel.x += scr; } if (scrollUp) { vel.y += scr; } if (scrollDown) { vel.y -= scr; } // Stuff vel /= 1f + (1f * friction) * Time.deltaTime; pos += vel * Time.deltaTime; pos.x = Mathf.Clamp(pos.x, 0, levelTilemapController.camMaxX * levelTilemapController.CellSizeInUnits); pos.y = Mathf.Clamp(pos.y, -levelTilemapController.camMaxY * levelTilemapController.CellSizeInUnits, 0); pos.z = -10f; if (pixelSnap) { transform.position = PxlVec.SnapVec(pos); } else { transform.position = pos; } Camera.main.orthographicSize = Mathf.Lerp(Camera.main.orthographicSize, fov, Time.deltaTime * 8); } }
void UpdateOrthographic() { //Allow RMB panning only in certain modes, otherwise force wasd movement bool canPan = (editor.currentMode == LevelEditorBehaviour.EditMode.Events || editor.currentMode == LevelEditorBehaviour.EditMode.Links); if (Settings.LoadFromMemory && Controller.obj.levelEventController.hasLoaded && Settings.FollowRaymanInMemoryMode) { StopLerp(); var rayman = LevelEditorData.Level.Rayman; if (rayman != null) { pos = new Vector3(rayman.XPosition / (float)LevelEditorData.Level.PixelsPerUnit, -(rayman.YPosition / (float)LevelEditorData.Level.PixelsPerUnit)); } } Vector3 mouseDeltaOrtho = Input.mousePosition - lastMousePosition; lastMousePosition = Input.mousePosition; if (LevelEditorData.Level != null) { // RMB scroling if (Input.GetMouseButton(1) && canPan) { StopLerp(); if (!panStart.HasValue) { panStart = Input.mousePosition; } Rect screenRect = new Rect(0, 0, Screen.width, Screen.height); if (panning) { float xFactor = Camera.main.orthographicSize * 2.0f / Camera.main.pixelHeight; float yFactor = Camera.main.orthographicSize * 2.0f / Camera.main.pixelHeight; /*vel = 0.8f * Vector3.Lerp(vel, Vector3.ClampMagnitude(mousePosPrev - mousePosition, 50) * fov, * inertia <= 0 ? 1 : Time.deltaTime * 1f / inertia);*/ friction = fricStart; pos += new Vector3(-mouseDeltaOrtho.x * xFactor, -mouseDeltaOrtho.y * yFactor); } else if (Input.GetMouseButtonDown(1) && screenRect.Contains(Input.mousePosition)) // Only start panning if within game window when you click { panning = true; } } else { panStart = null; panning = false; } // Mouse wheel zooming if (!EventSystem.current.IsPointerOverGameObject()) { if (Input.mouseScrollDelta.y != 0) { StopLerp(); } fov = Mathf.Clamp(fov - 0.25f * Input.mouseScrollDelta.y * fov, 3.75f, 50); } // WASD scrolling bool scrollLeft = Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A); bool scrollRight = Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D); bool scrollUp = Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W); bool scrollDown = Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S); bool scrolling = scrollLeft || scrollRight || scrollUp || scrollDown; if (scrolling || editor.scrolling) { StopLerp(); friction = 30; } float scr = friction * Camera.main.orthographicSize * WASDScrollSpeed * Time.deltaTime; if (scrollLeft) { vel.x -= scr; } if (scrollRight) { vel.x += scr; } if (scrollUp) { vel.y += scr; } if (scrollDown) { vel.y -= scr; } // Stuff vel /= 1f + (1f * friction) * Time.deltaTime; pos += vel * Time.deltaTime; // Lerp var cam = this; if (targetPos.HasValue) { if (Vector3.Distance(pos, targetPos.Value) < 0.4f) { targetPos = null; } else { pos = Vector3.Lerp(pos, targetPos.Value, Time.deltaTime * lerpFactor); } } if (targetOrthoSize.HasValue) { if (Mathf.Abs(targetOrthoSize.Value - cam.fov) < 0.04f) { targetOrthoSize = null; } else { cam.fov = Mathf.Lerp(cam.fov, targetOrthoSize.Value, Time.deltaTime * lerpFactor); } } // Limit position pos.x = Mathf.Clamp(pos.x, 0, levelTilemapController.camMaxX * levelTilemapController.CellSizeInUnits); pos.y = Mathf.Clamp(pos.y, -levelTilemapController.camMaxY * levelTilemapController.CellSizeInUnits, 0); pos.z = orthographicZPosition; // Apply position if (pixelSnap) { transform.position = PxlVec.SnapVec(pos); } else { transform.position = pos; } Camera.main.orthographicSize = Mathf.Lerp(Camera.main.orthographicSize, fov, Time.deltaTime * 8); camera2DOverlay.orthographicSize = Camera.main.orthographicSize; if (LevelEditorData.Level?.IsometricData != null) { // Update 3D camera float scl = 1f; Quaternion rot3D = LevelEditorData.Level.IsometricData.ViewAngle; camera3D.transform.rotation = rot3D; Vector3 v = rot3D * Vector3.back; float w = LevelEditorData.Level.IsometricData.TilesWidth * levelTilemapController.CellSizeInUnits; float h = (LevelEditorData.Level.IsometricData.TilesHeight) * levelTilemapController.CellSizeInUnits; float colYDisplacement = LevelEditorData.Level.IsometricData.CalculateYDisplacement(); float colXDisplacement = LevelEditorData.Level.IsometricData.CalculateXDisplacement(); /*if (!camera3D.gameObject.activeSelf) { * Debug.Log(LevelEditorData.Level.IsometricData.TilesWidth + "x" + LevelEditorData.Level.IsometricData.TilesHeight + " - " + LevelEditorData.Level.IsometricData.CollisionWidth + "x" + LevelEditorData.Level.IsometricData.CollisionHeight); + }*/ camera3D.orthographic = true; camera3D.transform.position = v * 300 + rot3D * ((pos - new Vector3((w - colXDisplacement) / 2f, -(h - colYDisplacement) / 2f, 0f)) / scl); // Move back 300 units camera3D.orthographicSize = Camera.main.orthographicSize / scl; // Activate if (!camera3D.gameObject.activeSelf) { camera3D.gameObject.SetActive(true); } camera3DOverlay.orthographicSize = camera3D.orthographicSize; camera3DOverlay.orthographic = true; camera2DOverlay.cullingMask &= ~(1 << LayerMask.NameToLayer("3D Overlay")); if (FreeCameraMode) { StopLerp(); _freeCameraMode = true; cullingMask = Camera.main.cullingMask; cullingMask2DOverlay = camera2DOverlay.cullingMask; } } } }