Among else, fixed determined aspect ratio

This commit is contained in:
misabiko 2022-05-14 19:55:14 -04:00
parent 43f2114a49
commit 22204194d7
2 changed files with 33 additions and 18 deletions

View File

@ -1063,7 +1063,7 @@ Camera:
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_FOVAxisMode: 1
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
@ -1075,7 +1075,7 @@ Camera:
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
field of view: 58.727467
orthographic: 0
orthographic size: 5
m_Depth: -1
@ -3001,6 +3001,7 @@ MonoBehaviour:
cannonForce: 1000
fireRate: 0.5
fireTimer: 0
damage: 1
--- !u!65 &290013269
BoxCollider:
m_ObjectHideFlags: 0
@ -9368,7 +9369,7 @@ Camera:
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_FOVAxisMode: 1
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
@ -9380,7 +9381,7 @@ Camera:
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
field of view: 58.727467
orthographic: 0
orthographic size: 5
m_Depth: -1
@ -11657,6 +11658,7 @@ MonoBehaviour:
cannonForce: 1000
fireRate: 0.5
fireTimer: 0
damage: 1
--- !u!65 &1157167103
BoxCollider:
m_ObjectHideFlags: 0
@ -13441,22 +13443,22 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 02e217105518e1f418b52195b8b328d7, type: 3}
m_Name:
m_EditorClassIdentifier:
transitionDuration: 5
transitionDuration: 1.5
transitionCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 2
outSlope: 2
time: 0.21012497
value: 0.023590088
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 1
value: 1
time: 0.82281494
value: 0.99056625
inSlope: 0
outSlope: 0
tangentMode: 0
@ -13479,8 +13481,8 @@ MonoBehaviour:
texture: {fileID: 0}
renderQuad: {fileID: 2080936950}
material: {fileID: 0}
quadOffset: 0.84
tabWidth: 0.1
quadOffset: 0.87
--- !u!1 &1390568200
GameObject:
m_ObjectHideFlags: 0
@ -18553,6 +18555,7 @@ MonoBehaviour:
cannonForce: 1000
fireRate: 0.5
fireTimer: 0
damage: 1
--- !u!65 &1935451042
BoxCollider:
m_ObjectHideFlags: 0

View File

@ -8,17 +8,20 @@ public class WorldSwitcher : MonoBehaviour {
[SerializeField] AnimationCurve transitionCurve;
[SerializeField] WorldInfo[] worldInfos;
[SerializeField] float quadOffset;
[Range(0, 1)]
[SerializeField] float tabWidth;
//TODO Hardcode
[SerializeField]
float quadOffset;
int lastWorldIndex;
int currentWorldIndex;
Coroutine transition;
static readonly int UVOffset = Shader.PropertyToID("_UVOffset");
void Start() {
void Awake() {
if (worldInfos.Length != 3)
Debug.LogWarning("For now, WorldSwitcher should have 3 worlds.");
@ -66,8 +69,6 @@ public class WorldSwitcher : MonoBehaviour {
float startTime = Time.time;
Camera lastCam = lastWorld.camera;
//float startX = currentWorldIndex - lastWorldIndex > 0 ? -newWorld.texture.width / 2f + tabWidth * Screen.width : newWorld.texture.width / 2f - tabWidth * Screen.width + Screen.width;
while (Time.time < startTime + transitionDuration) {
float t = transitionCurve.Evaluate((Time.time - startTime) / transitionDuration);
@ -83,10 +84,13 @@ public class WorldSwitcher : MonoBehaviour {
}
Vector3 GetQuadOffset(Camera cam, WorldInfo worldInfo, int index, bool fromRight, float t = 0f) {
float x = fromRight ? 1f - tabWidth * (worldInfos.Length - index) - t : tabWidth * (1 + index) + t;
float x = fromRight ?
Mathf.Lerp(1f - tabWidth * (worldInfos.Length - index), 0f, t) :
Mathf.Lerp(index * tabWidth, 1f, t);
Vector3 quadHalfWidthOffset = Vector3.right * (fromRight ? worldInfo.renderQuad.localScale.x / 2f : -worldInfo.renderQuad.localScale.x / 2f);
return cam.ViewportToWorldPoint(new Vector3(x, .5f, quadOffset)) + quadHalfWidthOffset;
//TODO Offset epsilon
return cam.ViewportToWorldPoint(new Vector3(x, .5f, quadOffset - (t != 0 ? .01f : 0f))) + quadHalfWidthOffset;
}
void ResetQuadPositions() {
@ -124,8 +128,16 @@ struct WorldInfo {
}
public void GenerateRenderTexture() {
bool usingTexture = !ReferenceEquals(camera.targetTexture, null);
if (usingTexture)
camera.targetTexture = null;
renderQuad.localScale = new Vector3(camera.aspect, 1f, 1f);
texture = new RenderTexture(Screen.width, Screen.height, 32);
material.SetTexture(CameraTexture, texture);
if (usingTexture)
camera.targetTexture = texture;
}
}