private void ensureCameraBounds() { Vector3 position = camera.transform.localPosition; Vector3 translation = new Vector3(); if (!bounds.isIn(position)) // scroll into bounds, if camera get out on scrolling { if (position.x < bounds.minX) { translation.x = bounds.minX - position.x; } if (position.x > bounds.maxX) { translation.x = bounds.maxX - position.x; } if (position.y < bounds.minY) { translation.y = bounds.minY - position.y; } if (position.y > bounds.maxY) { translation.y = bounds.maxY - position.y; } camera.transform.Translate(translation, Space.Self); } }
private void moveSelectorIntoVisibleArea() { FloatBounds2 bounds = cameraWithEsMovementSystem.visibleArea; if (!bounds.isIn(selector.position)) { bounds.putInto(selector.position); } }
public void update() { // move target to selector layer if (Math.Abs(cameraTarget.z - (selectorSprite.localPosition.z - 0.4f)) > 0.01f) { moveCameraTargetZ(selectorSprite.localPosition.z - 0.4f - cameraTarget.z); } // move camera target to see selector Vector2Int overlook = GameView.get().selectorOverlook; if (!visibleArea.isIn(selectorSprite.localPosition) || overlook.magnitude != 0) { moveCameraTarget(visibleArea.getDirectionVector(selectorSprite.localPosition) + overlook * overlookTiles); } moveCamera(); }