Kinda ok ish looking transition!

This commit is contained in:
misabiko 2022-05-14 22:01:45 -04:00
parent 22204194d7
commit 20de27e0a4
2 changed files with 35 additions and 21 deletions

View File

@ -26,7 +26,7 @@ RenderSettings:
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_SkyboxMaterial: {fileID: 2100000, guid: 369b9ebe3a62b904dbc19bd332b44086, type: 2}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_IndirectSpecularColor: {r: 0.010486943, g: 0.05298245, b: 0.15319028, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@ -7656,7 +7656,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &813119609
Transform:
m_ObjectHideFlags: 0
@ -10750,7 +10750,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &1083674222
Transform:
m_ObjectHideFlags: 0
@ -13443,22 +13443,22 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 02e217105518e1f418b52195b8b328d7, type: 3}
m_Name:
m_EditorClassIdentifier:
transitionDuration: 1.5
transitionDuration: 0.84
transitionCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0.21012497
value: 0.023590088
inSlope: 0
outSlope: 0
time: 0
value: 0
inSlope: 2
outSlope: 2
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 0.82281494
value: 0.99056625
time: 1
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
@ -15814,7 +15814,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &1655426232
Transform:
m_ObjectHideFlags: 0

View File

@ -31,20 +31,23 @@ public class WorldSwitcher : MonoBehaviour {
for (int i = 0; i < worldInfos.Length; i++) {
worldInfos[i].material = worldInfos[i].renderQuad.GetComponent<Renderer>().material;
worldInfos[i].GenerateRenderTexture();
worldInfos[i].GenerateRenderTexture(quadOffset);
}
ResetQuadPositions();
}
public void SwitchWorld(bool right) {
if (transition != null)
return;
if (right ? currentWorldIndex == worldInfos.Length - 1 : currentWorldIndex == 0)
return;
//TODO Block window resize during transition?
foreach (WorldInfo worldInfo in worldInfos) {
if (Screen.width != worldInfo.texture.width || Screen.height != worldInfo.texture.height)
worldInfo.GenerateRenderTexture();
worldInfo.GenerateRenderTexture(quadOffset);
}
lastWorldIndex = currentWorldIndex;
@ -74,7 +77,7 @@ public class WorldSwitcher : MonoBehaviour {
float t = transitionCurve.Evaluate((Time.time - startTime) / transitionDuration);
newWorld.renderQuad.position = GetQuadOffset(lastCam, newWorld, currentWorldIndex, fromRight, t);
newWorld.material.SetFloat(UVOffset, fromRight ? 1f - t - tabWidth : -1f + t + tabWidth);
newWorld.material.SetFloat(UVOffset, GetUVOffset(t, fromRight, currentWorldIndex));
yield return null;
}
@ -85,12 +88,22 @@ public class WorldSwitcher : MonoBehaviour {
Vector3 GetQuadOffset(Camera cam, WorldInfo worldInfo, int index, bool fromRight, float t = 0f) {
float x = fromRight ?
Mathf.Lerp(1f - tabWidth * (worldInfos.Length - index), 0f, t) :
Mathf.Lerp(index * tabWidth, 1f, t);
Mathf.Lerp(1f - tabWidth * (worldInfos.Length - index), index * tabWidth, t) :
Mathf.Lerp((1 + index) * tabWidth, 1f - (worldInfos.Length - 1 - index) * tabWidth, t);
Vector3 quadHalfWidthOffset = Vector3.right * (fromRight ? worldInfo.renderQuad.localScale.x / 2f : -worldInfo.renderQuad.localScale.x / 2f);
//TODO Offset epsilon
return cam.ViewportToWorldPoint(new Vector3(x, .5f, quadOffset - (t != 0 ? .01f : 0f))) + quadHalfWidthOffset;
return cam.ViewportToWorldPoint(new Vector3(
x,
.5f,
quadOffset - Mathf.Abs(currentWorldIndex - index) * .01f)
) + quadHalfWidthOffset;
}
float GetUVOffset(float t, bool fromRight, int index) {
return fromRight ?
Mathf.Lerp(1f - tabWidth * (worldInfos.Length - index), index * tabWidth, t):
Mathf.Lerp(-1f + tabWidth * (index + 1), -(worldInfos.Length - 1 - index) * tabWidth, t);
}
void ResetQuadPositions() {
@ -103,7 +116,7 @@ public class WorldSwitcher : MonoBehaviour {
if (usingRenderTexture) {
bool fromRight = i - currentWorldIndex > 0;
worldInfos[i].renderQuad.position = GetQuadOffset(currCam, worldInfos[i], i, fromRight);
worldInfos[i].material.SetFloat(UVOffset, fromRight ? 1f - tabWidth : -1f + tabWidth);
worldInfos[i].material.SetFloat(UVOffset, GetUVOffset(0f, fromRight, i));
}
}
}
@ -127,11 +140,12 @@ struct WorldInfo {
}
}
public void GenerateRenderTexture() {
public void GenerateRenderTexture(float quadOffset) {
bool usingTexture = !ReferenceEquals(camera.targetTexture, null);
if (usingTexture)
camera.targetTexture = null;
//float height = 2f * Mathf.Atan(Mathf.Deg2Rad * camera.fieldOfView) * quadOffset;
renderQuad.localScale = new Vector3(camera.aspect, 1f, 1f);
texture = new RenderTexture(Screen.width, Screen.height, 32);
material.SetTexture(CameraTexture, texture);