diff --git a/Assets/Scenes/Jason.unity b/Assets/Scenes/Jason.unity index f97c7a0..9f3fda7 100644 --- a/Assets/Scenes/Jason.unity +++ b/Assets/Scenes/Jason.unity @@ -123,6 +123,82 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &99834112 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 99834113} + - component: {fileID: 99834115} + - component: {fileID: 99834114} + m_Layer: 5 + m_Name: WorldTab3 + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!224 &99834113 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 99834112} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1076402456} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0} + m_AnchorMax: {x: 0.5, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 25, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &99834114 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 99834112} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &99834115 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 99834112} + m_CullTransparentMesh: 1 --- !u!1 &260114732 GameObject: m_ObjectHideFlags: 0 @@ -648,6 +724,337 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &903224217 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 903224218} + - component: {fileID: 903224220} + - component: {fileID: 903224219} + m_Layer: 5 + m_Name: WorldTab1 + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &903224218 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 903224217} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1076402456} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 25, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &903224219 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 903224217} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &903224220 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 903224217} + m_CullTransparentMesh: 1 +--- !u!1 &1006226459 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1006226460} + - component: {fileID: 1006226462} + - component: {fileID: 1006226461} + m_Layer: 5 + m_Name: WorldTab2 + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1006226460 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1006226459} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1076402456} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 1, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: -14, y: 0} + m_SizeDelta: {x: 29, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1006226461 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1006226459} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &1006226462 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1006226459} + m_CullTransparentMesh: 1 +--- !u!1 &1076402452 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1076402456} + - component: {fileID: 1076402455} + - component: {fileID: 1076402454} + - component: {fileID: 1076402453} + m_Layer: 5 + m_Name: Canvas + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!114 &1076402453 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1076402452} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3} + m_Name: + m_EditorClassIdentifier: + m_IgnoreReversedGraphics: 1 + m_BlockingObjects: 0 + m_BlockingMask: + serializedVersion: 2 + m_Bits: 4294967295 +--- !u!114 &1076402454 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1076402452} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} + m_Name: + m_EditorClassIdentifier: + m_UiScaleMode: 0 + m_ReferencePixelsPerUnit: 100 + m_ScaleFactor: 1 + m_ReferenceResolution: {x: 800, y: 600} + m_ScreenMatchMode: 0 + m_MatchWidthOrHeight: 0 + m_PhysicalUnit: 3 + m_FallbackScreenDPI: 96 + m_DefaultSpriteDPI: 96 + m_DynamicPixelsPerUnit: 1 + m_PresetInfoIsWorld: 0 +--- !u!223 &1076402455 +Canvas: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1076402452} + m_Enabled: 1 + serializedVersion: 3 + m_RenderMode: 0 + m_Camera: {fileID: 0} + m_PlaneDistance: 100 + m_PixelPerfect: 0 + m_ReceivesEvents: 1 + m_OverrideSorting: 0 + m_OverridePixelPerfect: 0 + m_SortingBucketNormalizedSize: 0 + m_AdditionalShaderChannelsFlag: 0 + m_SortingLayerID: 0 + m_SortingOrder: 0 + m_TargetDisplay: 0 +--- !u!224 &1076402456 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1076402452} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0, y: 0, z: 0} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 903224218} + - {fileID: 1006226460} + - {fileID: 99834113} + m_Father: {fileID: 0} + m_RootOrder: 8 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0, y: 0} +--- !u!1 &1118408972 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1118408975} + - component: {fileID: 1118408974} + - component: {fileID: 1118408976} + m_Layer: 0 + m_Name: EventSystem + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1118408974 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1118408972} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3} + m_Name: + m_EditorClassIdentifier: + m_FirstSelected: {fileID: 0} + m_sendNavigationEvents: 1 + m_DragThreshold: 10 +--- !u!4 &1118408975 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1118408972} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 9 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1118408976 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1118408972} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 01614664b831546d2ae94a42149d80ac, type: 3} + m_Name: + m_EditorClassIdentifier: + m_MoveRepeatDelay: 0.5 + m_MoveRepeatRate: 0.1 + m_XRTrackingOrigin: {fileID: 0} + m_ActionsAsset: {fileID: -944628639613478452, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3} + m_PointAction: {fileID: -1654692200621890270, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3} + m_MoveAction: {fileID: -8784545083839296357, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3} + m_SubmitAction: {fileID: 392368643174621059, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3} + m_CancelAction: {fileID: 7727032971491509709, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3} + m_LeftClickAction: {fileID: 3001919216989983466, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3} + m_MiddleClickAction: {fileID: -2185481485913320682, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3} + m_RightClickAction: {fileID: -4090225696740746782, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3} + m_ScrollWheelAction: {fileID: 6240969308177333660, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3} + m_TrackedDevicePositionAction: {fileID: 6564999863303420839, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3} + m_TrackedDeviceOrientationAction: {fileID: 7970375526676320489, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3} + m_DeselectOnBackgroundClick: 1 + m_PointerBehavior: 0 --- !u!1 &1171096952 GameObject: m_ObjectHideFlags: 0 @@ -972,7 +1379,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 02e217105518e1f418b52195b8b328d7, type: 3} m_Name: m_EditorClassIdentifier: - transitionDuration: 0.5 + transitionDuration: 5 transitionCurve: serializedVersion: 2 m_Curve: @@ -997,11 +1404,18 @@ MonoBehaviour: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 - cameras: - - {fileID: 646706616} - - {fileID: 2087698543} + worldInfos: + - camera: {fileID: 646706616} + worldTab: {fileID: 903224218} + indexFromSide: 0 + side: 0 + - camera: {fileID: 2087698543} + worldTab: {fileID: 1006226460} + indexFromSide: 0 + side: 1 renderQuad: {fileID: 817274629} quadOffset: 0.84 + tabWidth: 12.5 --- !u!1 &1566262316 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/WorldSwitcher.cs b/Assets/Scripts/WorldSwitcher.cs index d2efead..94c7f73 100644 --- a/Assets/Scripts/WorldSwitcher.cs +++ b/Assets/Scripts/WorldSwitcher.cs @@ -6,9 +6,10 @@ public class WorldSwitcher : MonoBehaviour { [Range(0, 5)] [SerializeField] float transitionDuration; [SerializeField] AnimationCurve transitionCurve; - [SerializeField] Camera[] cameras; + [SerializeField] WorldInfo[] worldInfos; [SerializeField] Transform renderQuad; [SerializeField] float quadOffset; + [SerializeField] float tabWidth; int lastWorldIndex; int currentWorldIndex; Coroutine transition; @@ -16,7 +17,7 @@ public class WorldSwitcher : MonoBehaviour { Material renderMaterial; void Awake() { - if (cameras.Length <= 1) + if (worldInfos.Length <= 1) Debug.LogWarning("WorldSwitcher should have multiple cameras"); currentWorldIndex = 0; @@ -24,19 +25,28 @@ public class WorldSwitcher : MonoBehaviour { renderMaterial = renderQuad.GetComponent().material; GenerateRenderTexture(); + + for (int i = 0; i < worldInfos.Length; i++) { + WorldInfo worldInfo = worldInfos[i]; + worldInfo.camera.enabled = i == 0; + + Vector3 tabPos = worldInfo.worldTab.position; + float tabX = worldInfo.side == TabSide.Left ? 0 : ((RectTransform)worldInfo.worldTab.parent).rect.width; + worldInfo.worldTab.position = new Vector3(tabX, tabPos.y, tabPos.z); + } } public void SwitchWorld(int index) { if (index == currentWorldIndex) return; - if (index < 0 || index >= cameras.Length) + if (index < 0 || index >= worldInfos.Length) throw new IndexOutOfRangeException($"{index} is not an available world."); lastWorldIndex = currentWorldIndex; currentWorldIndex = index; - Camera currCam = cameras[currentWorldIndex]; + Camera currCam = worldInfos[currentWorldIndex].camera; currCam.enabled = true; //TODO Block window resize during transition? @@ -45,13 +55,16 @@ public class WorldSwitcher : MonoBehaviour { currCam.targetTexture = renderTexture; - renderQuad.localScale = new Vector3(cameras[lastWorldIndex].aspect, 1f, 1f); + renderQuad.localScale = new Vector3(worldInfos[lastWorldIndex].camera.aspect, 1f, 1f); + + Vector3 oldPos = worldInfos[lastWorldIndex].worldTab.position; + worldInfos[lastWorldIndex].worldTab.position = new Vector3(worldInfos[lastWorldIndex].TabBaseX, oldPos.y, oldPos.z); transition = StartCoroutine(TransitionCamera()); } void OnGUI() { - for (int i = 0; i < cameras.Length; ++i) { + for (int i = 0; i < worldInfos.Length; ++i) { if (i == currentWorldIndex) continue; @@ -61,19 +74,28 @@ public class WorldSwitcher : MonoBehaviour { } IEnumerator TransitionCamera() { + WorldInfo lastWorld = worldInfos[lastWorldIndex]; + WorldInfo newWorld = worldInfos[currentWorldIndex]; + float startTime = Time.time; - Transform lastCam = cameras[lastWorldIndex].transform; + Transform lastCam = lastWorld.camera.transform; + Vector3 tabStartPosition = newWorld.worldTab.position; + float tabParentWidth = newWorld.TabParentWidth; + while (Time.time < startTime + transitionDuration) { float t = transitionCurve.Evaluate((Time.time - startTime) / transitionDuration); + t *= (tabParentWidth + tabWidth) / tabParentWidth; - renderQuad.position = lastCam.position + Vector3.forward * quadOffset + Vector3.right * (2f * t - 2f); + renderQuad.position = lastCam.position + Vector3.forward * quadOffset + Vector3.right * (2f * Mathf.Clamp01(t) - 2f); + //float tabX = newWorld.side == TabSide.Left ? t * (tabParentWidth + tabWidth) : t * -(tabParentWidth + tabWidth) + tabParentWidth; + newWorld.worldTab.position = new Vector3(tabParentWidth * t, tabStartPosition.y, tabStartPosition.z); yield return null; } - cameras[currentWorldIndex].targetTexture = null; - cameras[lastWorldIndex].enabled = false; + newWorld.camera.targetTexture = null; + lastWorld.camera.enabled = false; transition = null; } @@ -81,4 +103,21 @@ public class WorldSwitcher : MonoBehaviour { renderTexture = new RenderTexture(Screen.width, Screen.height, 32); renderMaterial.mainTexture = renderTexture; } -} \ No newline at end of file +} + +[Serializable] +struct WorldInfo { + public Camera camera; + public RectTransform worldTab; + public ushort indexFromSide; + public TabSide side; + + public float TabParentWidth => ((RectTransform)worldTab.parent).rect.width; + + public float TabBaseX => side == TabSide.Left ? + indexFromSide * 6.25f : + TabParentWidth - indexFromSide * 6.25f; +} + +[Serializable] +enum TabSide { Left, Right } \ No newline at end of file