Skip to content

Commit

Permalink
Add Cold Startup prefab to play directly from gameplay scenes
Browse files Browse the repository at this point in the history
Add a prefab EditorInitializer that can be place in any gameplay scene to load the persistenceManger Scene additively first.

Separate logic for initialization in a different Scene, that is actually the only one present in the Build Settings. This scene will be responsible to load PersistenceManager Scene, ask it to load Main Menu and finally unload itself.
  • Loading branch information
fontinixxl committed Apr 8, 2022
1 parent 92e6b42 commit c2d750f
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 21 deletions.
5 changes: 0 additions & 5 deletions Assets/AddressableAssetsData/AssetGroups/Scenes.asset
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ MonoBehaviour:
m_SerializedData: []
m_GUID: bac5601ae92444b72ae1617a4cd087b2
m_SerializeEntries:
- m_GUID: 78a510c781f19db4da14f78ebb30946a
m_Address: Assets/Scenes/Main.unity
m_ReadOnly: 0
m_SerializedLabels:
- Scene
- m_GUID: ae666798a74d3a5488e0c0ec42a1265d
m_Address: Assets/Scenes/Menu.unity
m_ReadOnly: 0
Expand Down
184 changes: 184 additions & 0 deletions Assets/Scenes/Initialization.unity
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.12731689, g: 0.13414702, b: 0.1210784, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 12
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 12
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 512
m_PVRBounces: 2
m_PVREnvironmentSampleCount: 256
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 1
m_PVRDenoiserTypeDirect: 1
m_PVRDenoiserTypeIndirect: 1
m_PVRDenoiserTypeAO: 1
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVREnvironmentMIS: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_LightingSettings: {fileID: 0}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &864492825
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 864492827}
- component: {fileID: 864492826}
m_Layer: 0
m_Name: Initializer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &864492826
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 864492825}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 93cf6573ba6c4efda55231b436915501, type: 3}
m_Name:
m_EditorClassIdentifier:
managersScene:
m_AssetGUID: 84e8448b215c74f4d804a0bab678864c
m_SubObjectName:
m_SubObjectType:
m_EditorAssetChanged: 0
menuToLoad:
m_AssetGUID: ae666798a74d3a5488e0c0ec42a1265d
m_SubObjectName:
m_SubObjectType:
m_EditorAssetChanged: 0
menuLoadChannel:
m_AssetGUID: 76d253de60ff54ff79408772ae93a495
m_SubObjectName:
m_SubObjectType:
m_EditorAssetChanged: 0
--- !u!4 &864492827
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 864492825}
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: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
7 changes: 7 additions & 0 deletions Assets/Scenes/Initialization.unity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Assets/Scenes/PersistenceManagers.unity
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 422.5, y: 336, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
Expand Down Expand Up @@ -199,6 +200,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
loadLocation: {fileID: 11400000, guid: 24ce03a187e86403d8e43e9654dc84d8, type: 2}
_loadMenu: {fileID: 11400000, guid: 76d253de60ff54ff79408772ae93a495, type: 2}
onSceneReady: {fileID: 11400000, guid: 3aeb7acc06a894d9b90ddefb9c1df0bc, type: 2}
mainMenuScene:
m_AssetGUID: ae666798a74d3a5488e0c0ec42a1265d
Expand All @@ -215,6 +217,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 527.4459, y: 157.6221, z: -128.78427}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
Expand All @@ -229,6 +232,7 @@ GameObject:
m_Component:
- component: {fileID: 1143283467}
- component: {fileID: 1143283466}
- component: {fileID: 1143283468}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
Expand Down Expand Up @@ -308,10 +312,31 @@ Transform:
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!114 &1143283468
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1143283465}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 474bcb49853aa07438625e644c072ee6, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Version: 1
m_UsePipelineSettings: 1
m_AdditionalLightsShadowResolutionTier: 2
m_LightLayerMask: 1
m_CustomShadowLayers: 0
m_ShadowLayerMask: 1
m_LightCookieSize: {x: 1, y: 1}
m_LightCookieOffset: {x: 0, y: 0}
--- !u!1 &1478477332
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -374,6 +399,7 @@ Transform:
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: 0
Expand Down
17 changes: 17 additions & 0 deletions Assets/ScriptableObjects/Events/LoadMenuEvent_Channel.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f2a125052f9a345d997c717978996487, type: 3}
m_Name: LoadMenuEvent_Channel
m_EditorClassIdentifier:
description: Raised to request the loading of a new Menu scene, when going back
to Main Menu or when the game moves from initiatlization to Main Menu at the
beginning

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Assets/Scripts/Persistence/PersistenceManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Fontinixxl.Shared.ScriptableObjects;
using Fontinixxl.Shared.ScriptableObjects.EventChannels;
using UnityEngine;

Expand Down
42 changes: 42 additions & 0 deletions Assets/Scripts/SceneManagement/InitializationLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Fontinixxl.Shared.ScriptableObjects.EventChannels;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.SceneManagement;

namespace Fontinixxl.SceneManagement
{
/// <summary>
/// This class is responsible for starting the game by loading the persistent managers scene
/// and raising the event to load the Main Menu
/// </summary>

public class InitializationLoader : MonoBehaviour
{
[SerializeField] private AssetReference managersScene = default;
[SerializeField] private AssetReference menuToLoad = default;

[Header("Broadcasting on")]
[SerializeField] private AssetReference menuLoadChannel = default;

private void Start()
{
//Load the persistent managers scene
managersScene.LoadSceneAsync(LoadSceneMode.Additive).Completed += LoadEventChannel;
}

private void LoadEventChannel(AsyncOperationHandle<SceneInstance> obj)
{
menuLoadChannel.LoadAssetAsync<LoadEventChannelSO>().Completed += LoadMainMenu;
}

private void LoadMainMenu(AsyncOperationHandle<LoadEventChannelSO> obj)
{
obj.Result.RaiseEvent(menuToLoad);

SceneManager.UnloadSceneAsync(0); //Initialization is the only scene in BuildSettings, thus it has index 0
}
}

}
3 changes: 3 additions & 0 deletions Assets/Scripts/SceneManagement/InitializationLoader.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c2d750f

Please sign in to comment.