Is there a way to use the Normalized View Port Rect but maintain its size? When I adjust the x and y at the, the viewport shrinks. I need to be able to keep it at Screen.width and Screen.height, but move it.
Is this possible?
Thanks
Is there a way to use the Normalized View Port Rect but maintain its size? When I adjust the x and y at the, the viewport shrinks. I need to be able to keep it at Screen.width and Screen.height, but move it.
Is this possible?
Thanks
Sorted this now. For anyone wanting to do similar in the future, I did it using this:
CamScript.cs:
void OnPreCull()
{
var r = new Rect(0f, 0f, 1f, 1f);
var alignFactor = Vector2.one;
if (viewportOffset.y >= 0f)
{
// Sliding down
r.height = 1f - viewportOffset.y;
alignFactor.y = 1f;
}
else
{
// Sliding up
r.y = -viewportOffset.y;
r.height = 1f + viewportOffset.y;
alignFactor.y = -1f;
}
if (viewportOffset.x >= 0f)
{
// Sliding right
r.width = 1f - viewportOffset.x;
alignFactor.x = 1f;
}
else
{
// Sliding left
r.x = -viewportOffset.x;
r.width = 1f + viewportOffset.x;
alignFactor.x = -1f;
}
// Avoid division by zero
if (r.width == 0f)
{
r.width = 0.001f;
}
if (r.height == 0f)
{
r.height = 0.001f;
}
camera.rect = new Rect(0, 0, 1, 1);
camera.ResetProjectionMatrix();
Matrix4x4 m = camera.projectionMatrix;
camera.rect = r;
Matrix4x4 m2 = Matrix4x4.TRS(
new Vector3(alignFactor.x * (-1 / r.width + 1), alignFactor.y * (-1 / r.height + 1), 0),
Quaternion.identity,
new Vector3(1 / r.width, 1 / r.height, 1));
camera.projectionMatrix = m2 * m;
}
Usage:
Vector2 screenPos = gameCamera.WorldToScreenPoint (new Vector3 (transform.position.x, transform.position.y, _dartDistance));
screenPos = gameCamera.ScreenToViewportPoint (screenPos);
screenPos = new Vector2 (-Utils.NewRangeCalc (0.0f, 1.0f, -0.5f, 0.5f, screenPos.x), -Utils.NewRangeCalc (0.0f, 1.0f, -0.5f, 0.5f, screenPos.y));
CamScript.viewportOffset = screenPos;
The OnPreCull method has its origin in the centre so I had to scale the screenPos from 0-1 to -0.5-0.5 to get it to work right.
It’s possible, there is a user script of a minimap camera where you can specify the dimensions as well as the position on screen. I can’T remember it’s name, you just have to search a bit for it.