Commit ffc18d2a authored by Tommé Nöll's avatar Tommé Nöll
Browse files

made camera zones work with perspective camera

parent de19f7d8
......@@ -2439,40 +2439,6 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 345354280}
m_PrefabAsset: {fileID: 0}
--- !u!84 &978874468
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 945
m_Height: 539
m_AntiAliasing: 1
m_DepthFormat: 0
m_ColorFormat: 21
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
--- !u!1001 &1071197050
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -2947,7 +2913,7 @@ PrefabInstance:
- target: {fileID: 6098262288883245936, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_LocalPosition.y
value: 2.94
value: 2.92
objectReference: {fileID: 0}
- target: {fileID: 6098262288883245936, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
......@@ -2957,7 +2923,52 @@ PrefabInstance:
- target: {fileID: 6098262288883245936, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_LocalPosition.x
value: -6.37
value: -6.292
objectReference: {fileID: 0}
- target: {fileID: 2336311380627323382, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2336311380627323382, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_Positions.Array.data[1].y
value: 0.6164981
objectReference: {fileID: 0}
- target: {fileID: 2336311380627323382, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_Positions.Array.data[1].z
value: -31.39397
objectReference: {fileID: 0}
- target: {fileID: 2336311380627323382, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_Positions.Array.data[0].y
value: 0.8136338
objectReference: {fileID: 0}
- target: {fileID: 2336311380627323382, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_Positions.Array.data[0].z
value: -31.066984
objectReference: {fileID: 0}
- target: {fileID: 6210609790981217034, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6675650529808371554, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3080924021400073710, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 794876769408629547, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: a1e0107a2375e1140a669c1da0647f9a, type: 3}
......@@ -4015,6 +4026,40 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 1549918673}
m_PrefabAsset: {fileID: 0}
--- !u!84 &1550108567
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 945
m_Height: 539
m_AntiAliasing: 1
m_DepthFormat: 0
m_ColorFormat: 21
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
--- !u!1001 &1551787235
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -4435,12 +4480,12 @@ PrefabInstance:
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
propertyPath: m_LocalPosition.x
value: 5.19
value: 3.49
objectReference: {fileID: 0}
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
propertyPath: m_LocalPosition.y
value: 1.47
value: 2.09
objectReference: {fileID: 0}
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
......@@ -5508,15 +5553,20 @@ PrefabInstance:
propertyPath: m_Name
value: CameraZone
objectReference: {fileID: 0}
- target: {fileID: 4291257553622459129, guid: 991b856519736f02eb11713b4d01251d,
type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4291257553622459127, guid: 991b856519736f02eb11713b4d01251d,
type: 3}
propertyPath: m_LocalPosition.x
value: 0.19
value: 2.13
objectReference: {fileID: 0}
- target: {fileID: 4291257553622459127, guid: 991b856519736f02eb11713b4d01251d,
type: 3}
propertyPath: m_LocalPosition.y
value: 2.62
value: 2.51
objectReference: {fileID: 0}
- target: {fileID: 4291257553622459127, guid: 991b856519736f02eb11713b4d01251d,
type: 3}
......@@ -5563,6 +5613,16 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4291257553622459127, guid: 991b856519736f02eb11713b4d01251d,
type: 3}
propertyPath: m_LocalScale.y
value: 11.770312
objectReference: {fileID: 0}
- target: {fileID: 4291257553622459126, guid: 991b856519736f02eb11713b4d01251d,
type: 3}
propertyPath: fitMode
value: 4
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 991b856519736f02eb11713b4d01251d, type: 3}
--- !u!1001 &4809852221727672545
......@@ -5720,7 +5780,7 @@ PrefabInstance:
type: 3}
propertyPath: m_TargetTexture
value:
objectReference: {fileID: 978874468}
objectReference: {fileID: 1550108567}
- target: {fileID: 8811539148413200178, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: orthographic size
......
......@@ -70,6 +70,7 @@ public class CameraController : MonoBehaviour
public void ResetTarget()
{
Debug.Log("Resetting");
targetPos = null;
targetSize = defaultSize;
}
......@@ -79,6 +80,16 @@ public class CameraController : MonoBehaviour
return camera.aspect;
}
public bool GetOrthographic()
{
return camera.orthographic;
}
public float GetFov()
{
return camera.fieldOfView;
}
void LateUpdate()
{
if (!player)
......@@ -114,7 +125,13 @@ public class CameraController : MonoBehaviour
float moveSpeedMultiplier;
if (targetPos != null)
{
targetMove = ((Vector3)targetPos) + offset - transform.position;
targetMove = ((Vector3)targetPos);
Debug.Log(targetMove);
if (targetMove.z == 0)
{
targetMove.z = offset.z;
}
targetMove = targetMove - transform.position;
moveSpeedMultiplier = panSpeed;
}
else
......
......@@ -7,7 +7,9 @@ public class CameraZone : MonoBehaviour
public enum FitMode {
grow,
shrink,
average
average,
useWidth,
useHeight
}
[Tooltip("How to scale the zone if the cameras aspect ration doesn't match")]
public FitMode fitMode;
......@@ -45,6 +47,7 @@ public class CameraZone : MonoBehaviour
{
Vector3 scaledPos = camera.player.transform.position;
scaledPos = bounds.center + (scaledPos - bounds.center) / triggerArea;
Debug.Log(scaledPos + ", " + bounds.Contains(scaledPos));
ApplyTarget(bounds.Contains(scaledPos));
}
......@@ -52,10 +55,18 @@ public class CameraZone : MonoBehaviour
{
if (apply)
{
if (!playerWasInZone)
//if (!playerWasInZone)
CalculateBounds();
{
camera.targetPos = transform.position;
camera.targetSize = CalculateCameraSize(bounds, fitMode);
if (camera.GetOrthographic())
{
camera.targetPos = transform.position;
camera.targetSize = CalculateCameraSize(bounds, fitMode);
}
else
{
camera.targetPos = VecZ(transform.position, -(CalculateCameraSize(bounds, fitMode) / 2) / Mathf.Tan(camera.GetFov() / 2 * Mathf.PI / 180));
}
}
}
else
......@@ -76,6 +87,10 @@ public class CameraZone : MonoBehaviour
float cameraHeightScaled = bounds.size.x / aspect;
switch (fitMode)
{
case FitMode.useWidth :
return cameraHeightScaled;
case FitMode.useHeight :
return bounds.size.y;
case FitMode.grow :
return Mathf.Max(bounds.size.y, cameraHeightScaled);
case FitMode.shrink :
......@@ -95,9 +110,14 @@ public class CameraZone : MonoBehaviour
Gizmos.color = Color.blue;
Gizmos.DrawLine(bounds.max, corner1);
Gizmos.DrawLine(bounds.max, corner2);
Gizmos.DrawLine(bounds.min, corner1);
Gizmos.DrawLine(bounds.min, corner2);
Gizmos.DrawLine(VecZ(bounds.max, 0), corner1);
Gizmos.DrawLine(VecZ(bounds.max, 0), corner2);
Gizmos.DrawLine(VecZ(bounds.min, 0), corner1);
Gizmos.DrawLine(VecZ(bounds.min, 0), corner2);
}
private static Vector3 VecZ(Vector3 vec, float z)
{
return new Vector3(vec.x, vec.y, z);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment