Pull request #25: Jason

Merge in CEGJ/creative-jam-20 from jason to main

* commit 'ec52c18cef44ababca2a71c1227cf8350af2c87a':
  Can jump through multiple dimensions
  Fixed quad height
This commit is contained in:
Jason Durand 01 2022-05-15 17:37:07 +00:00
commit 5089aa9feb
3 changed files with 237 additions and 56 deletions

View File

@ -3183,8 +3183,8 @@ MonoBehaviour:
renderQuad: {fileID: 2080936950} renderQuad: {fileID: 2080936950}
material: {fileID: 0} material: {fileID: 0}
layer: 9 layer: 9
tabWidth: 0.05 tabWidth: 0.2
quadOffset: 0.87 quadOffset: 1
--- !u!1 &1385339222 --- !u!1 &1385339222
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -9,8 +9,11 @@ public class IntEvent : UnityEvent<int> { }
public class WorldSwitcher : MonoBehaviour { public class WorldSwitcher : MonoBehaviour {
[Range(0, 5)] [Range(0, 5)]
[SerializeField] float transitionDuration; [SerializeField] float transitionDuration;
/*[Range(0, 5)]
[SerializeField] float fadeDuration;*/
[SerializeField] AnimationCurve transitionCurve; [SerializeField] AnimationCurve transitionCurve;
//[SerializeField] AnimationCurve fadeCurve;
[SerializeField] WorldInfo[] worldInfos; [SerializeField] WorldInfo[] worldInfos;
[Range(0, 1)] [Range(0, 1)]
@ -24,10 +27,11 @@ public class WorldSwitcher : MonoBehaviour {
int currentWorldIndex; int currentWorldIndex;
Coroutine transition; Coroutine transition;
static readonly int UVOffset = Shader.PropertyToID("_UVOffset"); static readonly int UVOffset = Shader.PropertyToID("_UVOffset");
//static readonly int Opacity = Shader.PropertyToID("_Opacity");
public IntEvent OnChangeWorld; public IntEvent OnChangeWorld;
public int CurrentWorldIndex { get { return currentWorldIndex; } } public int CurrentWorldIndex => currentWorldIndex;
void Awake() { void Awake() {
if (worldInfos.Length != 3) if (worldInfos.Length != 3)
@ -45,11 +49,11 @@ public class WorldSwitcher : MonoBehaviour {
ResetQuadPositions(); ResetQuadPositions();
} }
public void SwitchWorld(bool right) { public void SwitchWorld(int index) {
if (transition != null) if (transition != null)
return; return;
if (right ? currentWorldIndex == worldInfos.Length - 1 : currentWorldIndex == 0) if (index == currentWorldIndex || index < 0 || index > worldInfos.Length - 1)
return; return;
//TODO Block window resize during transition? //TODO Block window resize during transition?
@ -59,26 +63,22 @@ public class WorldSwitcher : MonoBehaviour {
} }
lastWorldIndex = currentWorldIndex; lastWorldIndex = currentWorldIndex;
if (right) currentWorldIndex = index;
currentWorldIndex++;
else
currentWorldIndex--;
OnChangeWorld.Invoke(currentWorldIndex); OnChangeWorld.Invoke(currentWorldIndex);
transition = StartCoroutine(TransitionCamera(right)); transition = StartCoroutine(TransitionCamera(currentWorldIndex - lastWorldIndex < 0));
} }
void OnGUI() { /*void OnGUI() {
if (GUILayout.Button("Left world")) for (int i = 0; i < worldInfos.Length; ++i) {
SwitchWorld(false); if (GUILayout.Button($"World {i}"))
if (GUILayout.Button("Right world")) SwitchWorld(i);
SwitchWorld(true); }
} }*/
IEnumerator TransitionCamera(bool fromRight) { IEnumerator TransitionCamera(bool fromRight) {
WorldInfo lastWorld = worldInfos[lastWorldIndex]; WorldInfo lastWorld = worldInfos[lastWorldIndex];
WorldInfo newWorld = worldInfos[currentWorldIndex];
float startTime = Time.time; float startTime = Time.time;
Camera lastCam = lastWorld.camera; Camera lastCam = lastWorld.camera;
@ -86,34 +86,60 @@ public class WorldSwitcher : MonoBehaviour {
while (Time.time < startTime + transitionDuration) { while (Time.time < startTime + transitionDuration) {
float t = transitionCurve.Evaluate((Time.time - startTime) / transitionDuration); float t = transitionCurve.Evaluate((Time.time - startTime) / transitionDuration);
newWorld.renderQuad.position = GetQuadOffset(lastCam, newWorld, currentWorldIndex, fromRight, t); if (fromRight) {
newWorld.material.SetFloat(UVOffset, GetUVOffset(t, fromRight, currentWorldIndex)); for (int i = lastWorldIndex - 1; i >= currentWorldIndex; --i) {
worldInfos[i].renderQuad.position = GetQuadOffset(lastCam, worldInfos[i], i, fromRight, true, t);
worldInfos[i].material.SetFloat(UVOffset, GetUVOffset(t, fromRight, i));
}
} else {
for (int i = lastWorldIndex + 1; i <= currentWorldIndex; ++i) {
worldInfos[i].renderQuad.position = GetQuadOffset(lastCam, worldInfos[i], i, fromRight, true, t);
worldInfos[i].material.SetFloat(UVOffset, GetUVOffset(t, fromRight, i));
}
}
yield return null; yield return null;
} }
/*startTime = Time.time;
while (Time.time < startTime + fadeDuration) {
worldInfos[currentWorldIndex].material.SetFloat(
Opacity,
1f - fadeCurve.Evaluate((Time.time - startTime) / fadeDuration)
);
yield return null;
}*/
ResetQuadPositions(); ResetQuadPositions();
transition = null; transition = null;
} }
Vector3 GetQuadOffset(Camera cam, WorldInfo worldInfo, int index, bool fromRight, float t = 0f) { Vector3 GetQuadOffset(Camera cam, WorldInfo worldInfo, int index, bool fromRight, bool moving, float t = 0f) {
float x = fromRight ? float x = fromRight ?
Mathf.Lerp(1f - tabWidth * (worldInfos.Length - index), index * tabWidth, t) : Mathf.Lerp((1 + index) * tabWidth, 1f - (worldInfos.Length - 1 - index) * tabWidth, t) :
Mathf.Lerp((1 + index) * tabWidth, 1f - (worldInfos.Length - 1 - index) * tabWidth, t); Mathf.Lerp(1f - tabWidth * (worldInfos.Length - index), index * tabWidth, t);
Vector3 quadHalfWidthOffset = Vector3.right * (fromRight ? worldInfo.renderQuad.localScale.x / 2f : -worldInfo.renderQuad.localScale.x / 2f); Vector3 quadHalfWidthOffset = Vector3.right * (fromRight ? -worldInfo.renderQuad.localScale.x / 2f : worldInfo.renderQuad.localScale.x / 2f);
float depthOffset = moving ?
Mathf.Abs(currentWorldIndex - index) * .0001f :
-Mathf.Abs(currentWorldIndex - index) * .0001f;
//TODO Offset epsilon //TODO Offset epsilon
return cam.ViewportToWorldPoint(new Vector3( return cam.ViewportToWorldPoint(
x, new Vector3(
.5f, x,
quadOffset - Mathf.Abs(currentWorldIndex - index) * .01f) .5f,
quadOffset + depthOffset
)
) + quadHalfWidthOffset; ) + quadHalfWidthOffset;
} }
float GetUVOffset(float t, bool fromRight, int index) { float GetUVOffset(float t, bool fromRight, int index) {
return fromRight ? return fromRight ?
Mathf.Lerp(1f - tabWidth * (worldInfos.Length - index), index * tabWidth, t): Mathf.Lerp(-1f + tabWidth * (index + 1), -(worldInfos.Length - 1 - index) * tabWidth, t):
Mathf.Lerp(-1f + tabWidth * (index + 1), -(worldInfos.Length - 1 - index) * tabWidth, t); Mathf.Lerp(1f - tabWidth * (worldInfos.Length - index), index * tabWidth, t);
} }
void ResetQuadPositions() { void ResetQuadPositions() {
@ -123,10 +149,11 @@ public class WorldSwitcher : MonoBehaviour {
for (int i = 0; i < worldInfos.Length; ++i) { for (int i = 0; i < worldInfos.Length; ++i) {
bool usingRenderTexture = i != currentWorldIndex; bool usingRenderTexture = i != currentWorldIndex;
worldInfos[i].SetUsingRenderTexture(usingRenderTexture, currLayer); worldInfos[i].SetUsingRenderTexture(usingRenderTexture, currLayer);
//worldInfos[i].material.SetFloat(Opacity, 1f);
if (usingRenderTexture) { if (usingRenderTexture) {
bool fromRight = i - currentWorldIndex > 0; bool fromRight = i - currentWorldIndex < 0;
worldInfos[i].renderQuad.position = GetQuadOffset(currCam, worldInfos[i], i, fromRight); worldInfos[i].renderQuad.position = GetQuadOffset(currCam, worldInfos[i], i, fromRight, false);
worldInfos[i].material.SetFloat(UVOffset, GetUVOffset(0f, fromRight, i)); worldInfos[i].material.SetFloat(UVOffset, GetUVOffset(0f, fromRight, i));
} }
} }
@ -158,7 +185,7 @@ struct WorldInfo {
if (usingTexture) if (usingTexture)
camera.targetTexture = null; camera.targetTexture = null;
float height = 2f * Mathf.Atan(Mathf.Deg2Rad * camera.fieldOfView) * quadOffset; float height = 2f * Mathf.Tan(Mathf.Deg2Rad * camera.fieldOfView / 2f) * quadOffset;
renderQuad.localScale = new Vector3(camera.aspect * height, height, 1f); renderQuad.localScale = new Vector3(camera.aspect * height, height, 1f);
texture = new RenderTexture(Screen.width, Screen.height, 32); texture = new RenderTexture(Screen.width, Screen.height, 32);
material.SetTexture(CameraTexture, texture); material.SetTexture(CameraTexture, texture);

View File

@ -8,6 +8,9 @@
}, },
{ {
"m_Id": "cbfe1aee551744acbc894c463a2c188f" "m_Id": "cbfe1aee551744acbc894c463a2c188f"
},
{
"m_Id": "50c3dc18fed24b0ba806f3b83bce4de9"
} }
], ],
"m_Keywords": [], "m_Keywords": [],
@ -50,6 +53,12 @@
}, },
{ {
"m_Id": "3d343fd3994f4c97a20f5be920ca830b" "m_Id": "3d343fd3994f4c97a20f5be920ca830b"
},
{
"m_Id": "5d4cc1151f9b494c91b07e7e4356e4b0"
},
{
"m_Id": "2225cdf0601c41978fd6e9bd600dbee4"
} }
], ],
"m_GroupDatas": [], "m_GroupDatas": [],
@ -83,6 +92,20 @@
"m_SlotId": 2 "m_SlotId": 2
} }
}, },
{
"m_OutputSlot": {
"m_Node": {
"m_Id": "5d4cc1151f9b494c91b07e7e4356e4b0"
},
"m_SlotId": 0
},
"m_InputSlot": {
"m_Node": {
"m_Id": "2225cdf0601c41978fd6e9bd600dbee4"
},
"m_SlotId": 0
}
},
{ {
"m_OutputSlot": { "m_OutputSlot": {
"m_Node": { "m_Node": {
@ -193,6 +216,9 @@
"m_Blocks": [ "m_Blocks": [
{ {
"m_Id": "17bc1a70f130474d866390b817919cc0" "m_Id": "17bc1a70f130474d866390b817919cc0"
},
{
"m_Id": "2225cdf0601c41978fd6e9bd600dbee4"
} }
] ]
}, },
@ -253,6 +279,21 @@
"m_Labels": [] "m_Labels": []
} }
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "08c468a3a96e4f6da858f4fceb5579f5",
"m_Id": 0,
"m_DisplayName": "Alpha",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Alpha",
"m_StageCapability": 2,
"m_Value": 1.0,
"m_DefaultValue": 1.0,
"m_Labels": []
}
{ {
"m_SGVersion": 0, "m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.UVNode", "m_Type": "UnityEditor.ShaderGraph.UVNode",
@ -265,10 +306,10 @@
"m_Expanded": true, "m_Expanded": true,
"m_Position": { "m_Position": {
"serializedVersion": "2", "serializedVersion": "2",
"x": -1338.0, "x": -1559.0,
"y": 429.0, "y": 415.0000305175781,
"width": 208.0, "width": 208.0,
"height": 313.0 "height": 313.0000305175781
} }
}, },
"m_Slots": [ "m_Slots": [
@ -373,6 +414,39 @@
"m_DefaultType": 0 "m_DefaultType": 0
} }
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "2225cdf0601c41978fd6e9bd600dbee4",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Alpha",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "08c468a3a96e4f6da858f4fceb5579f5"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Alpha"
}
{ {
"m_SGVersion": 0, "m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
@ -465,10 +539,10 @@
"m_Expanded": true, "m_Expanded": true,
"m_Position": { "m_Position": {
"serializedVersion": "2", "serializedVersion": "2",
"x": -653.0, "x": -874.0,
"y": 429.0, "y": 415.0000305175781,
"width": 128.0, "width": 128.0,
"height": 101.0 "height": 100.99996948242188
} }
}, },
"m_Slots": [ "m_Slots": [
@ -554,6 +628,33 @@
"m_ObjectId": "48b7e5faffd240328766c5ac7e1557ee" "m_ObjectId": "48b7e5faffd240328766c5ac7e1557ee"
} }
{
"m_SGVersion": 1,
"m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty",
"m_ObjectId": "50c3dc18fed24b0ba806f3b83bce4de9",
"m_Guid": {
"m_GuidSerialized": "77ede6a2-703f-4bc7-ba52-ed484dcc0d5a"
},
"m_Name": "Opacity",
"m_DefaultRefNameVersion": 1,
"m_RefNameGeneratedByDisplayName": "Opacity",
"m_DefaultReferenceName": "_Opacity",
"m_OverrideReferenceName": "",
"m_GeneratePropertyBlock": true,
"m_UseCustomSlotLabel": false,
"m_CustomSlotLabel": "",
"m_Precision": 0,
"overrideHLSLDeclaration": false,
"hlslDeclarationOverride": 0,
"m_Hidden": false,
"m_Value": 1.0,
"m_FloatType": 0,
"m_RangeValues": {
"x": 0.0,
"y": 1.0
}
}
{ {
"m_SGVersion": 0, "m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
@ -608,6 +709,41 @@
} }
} }
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.PropertyNode",
"m_ObjectId": "5d4cc1151f9b494c91b07e7e4356e4b0",
"m_Group": {
"m_Id": ""
},
"m_Name": "Property",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -423.9999694824219,
"y": 482.0,
"width": 115.99996948242188,
"height": 34.0
}
},
"m_Slots": [
{
"m_Id": "6afe25286d2a403c9b750ba22c97a754"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_Property": {
"m_Id": "50c3dc18fed24b0ba806f3b83bce4de9"
}
}
{ {
"m_SGVersion": 0, "m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot", "m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot",
@ -656,6 +792,21 @@
"m_DefaultType": 0 "m_DefaultType": 0
} }
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "6afe25286d2a403c9b750ba22c97a754",
"m_Id": 0,
"m_DisplayName": "Opacity",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "Out",
"m_StageCapability": 3,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}
{ {
"m_SGVersion": 0, "m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode", "m_Type": "UnityEditor.ShaderGraph.BlockNode",
@ -701,10 +852,10 @@
"m_Expanded": true, "m_Expanded": true,
"m_Position": { "m_Position": {
"serializedVersion": "2", "serializedVersion": "2",
"x": -1078.0, "x": -1299.0,
"y": 429.0, "y": 415.0000305175781,
"width": 120.0, "width": 120.0,
"height": 149.0 "height": 148.99996948242188
} }
}, },
"m_Slots": [ "m_Slots": [
@ -897,8 +1048,8 @@
"m_Expanded": true, "m_Expanded": true,
"m_Position": { "m_Position": {
"serializedVersion": "2", "serializedVersion": "2",
"x": -948.0, "x": -1169.0,
"y": 496.0, "y": 482.0,
"width": 124.0, "width": 124.0,
"height": 34.0 "height": 34.0
} }
@ -956,10 +1107,10 @@
"m_Expanded": true, "m_Expanded": true,
"m_Position": { "m_Position": {
"serializedVersion": "2", "serializedVersion": "2",
"x": -496.0000305175781, "x": -717.0,
"y": 406.0, "y": 392.0,
"width": 207.99993896484376, "width": 208.00003051757813,
"height": 435.00006103515627 "height": 435.0
} }
}, },
"m_Slots": [ "m_Slots": [
@ -990,7 +1141,7 @@
], ],
"synonyms": [], "synonyms": [],
"m_Precision": 0, "m_Precision": 0,
"m_PreviewExpanded": true, "m_PreviewExpanded": false,
"m_PreviewMode": 0, "m_PreviewMode": 0,
"m_CustomColors": { "m_CustomColors": {
"m_SerializableColors": [] "m_SerializableColors": []
@ -1117,10 +1268,10 @@
"m_Expanded": true, "m_Expanded": true,
"m_Position": { "m_Position": {
"serializedVersion": "2", "serializedVersion": "2",
"x": -690.0000610351563, "x": -911.0,
"y": 372.0000305175781, "y": 358.0,
"width": 164.99993896484376, "width": 165.0,
"height": 33.999969482421878 "height": 34.0
} }
}, },
"m_Slots": [ "m_Slots": [
@ -1152,10 +1303,10 @@
"m_Expanded": true, "m_Expanded": true,
"m_Position": { "m_Position": {
"serializedVersion": "2", "serializedVersion": "2",
"x": -809.0, "x": -1030.0,
"y": 429.0, "y": 415.0000305175781,
"width": 126.0, "width": 126.0,
"height": 118.0 "height": 117.99996948242188
} }
}, },
"m_Slots": [ "m_Slots": [
@ -1206,6 +1357,9 @@
}, },
{ {
"m_Id": "cbfe1aee551744acbc894c463a2c188f" "m_Id": "cbfe1aee551744acbc894c463a2c188f"
},
{
"m_Id": "50c3dc18fed24b0ba806f3b83bce4de9"
} }
] ]
} }