public static bool ResolveSceneSections(EntityManager EntityManager, Entity sceneEntity, Hash128 sceneGUID, RequestSceneLoaded requestSceneLoaded, Hash128 artifactHash) { // Resolve first (Even if the file doesn't exist we want to stop continously trying to load the section) EntityManager.AddBuffer <ResolvedSectionEntity>(sceneEntity); #if UNITY_EDITOR && !USE_SUBSCENE_EDITORBUNDLES EntityManager.AddComponentData(sceneEntity, new ResolvedSceneHash { ArtifactHash = artifactHash }); AssetDatabaseCompatibility.GetArtifactPaths(artifactHash, out var paths); var sceneHeaderPath = EntityScenesPaths.GetLoadPathFromArtifactPaths(paths, EntityScenesPaths.PathType.EntitiesHeader); #else var sceneHeaderPath = EntityScenesPaths.GetLoadPath(sceneGUID, EntityScenesPaths.PathType.EntitiesHeader, -1); #endif // @TODO: AsyncReadManager currently crashes with empty path. // It should be possible to remove this after that is fixed. if (String.IsNullOrEmpty(sceneHeaderPath)) { Debug.LogError($"Loading Entity Scene failed because the entity header file couldn't be resolved: guid={sceneGUID}."); return(false); } if (!BlobAssetReference <SceneMetaData> .TryRead(sceneHeaderPath, SceneMetaDataSerializeUtility.CurrentFileFormatVersion, out var sceneMetaDataRef)) { #if UNITY_EDITOR Debug.LogError($"Loading Entity Scene failed because the entity header file was an old version or doesn't exist: guid={sceneGUID} path={sceneHeaderPath}"); #else Debug.LogError($"Loading Entity Scene failed because the entity header file was an old version or doesn't exist: {sceneGUID}\nNOTE: In order to load SubScenes in the player you have to use the new BuildConfiguration asset based workflow to build & run your player.\n{sceneHeaderPath}"); #endif return(false); } ref var sceneMetaData = ref sceneMetaDataRef.Value;
public unsafe static bool ResolveSceneSections(EntityManager EntityManager, Entity sceneEntity, Hash128 sceneGUID, RequestSceneLoaded requestSceneLoaded, Hash128 artifactHash) { // Resolve first (Even if the file doesn't exist we want to stop continously trying to load the section) var bufLen = EntityManager.AddBuffer <ResolvedSectionEntity>(sceneEntity).Length; Assert.AreEqual(0, bufLen); var sceneHeaderPath = ""; #if UNITY_EDITOR string[] paths = null; #endif bool useStreamingAssetPath = true; #if !UNITY_DOTSRUNTIME useStreamingAssetPath = SceneBundleHandle.UseAssetBundles; #endif if (useStreamingAssetPath) { sceneHeaderPath = EntityScenesPaths.GetLoadPath(sceneGUID, EntityScenesPaths.PathType.EntitiesHeader, -1); } else { #if UNITY_EDITOR AssetDatabaseCompatibility.GetArtifactPaths(artifactHash, out paths); sceneHeaderPath = EntityScenesPaths.GetLoadPathFromArtifactPaths(paths, EntityScenesPaths.PathType.EntitiesHeader); #endif } EntityManager.AddComponentData(sceneEntity, new ResolvedSceneHash { ArtifactHash = artifactHash }); var group = EntityManager.AddBuffer <LinkedEntityGroup>(sceneEntity); Assert.AreEqual(0, group.Length); group.Add(sceneEntity); // @TODO: AsyncReadManager currently crashes with empty path. // It should be possible to remove this after that is fixed. if (String.IsNullOrEmpty(sceneHeaderPath)) { #if UNITY_EDITOR var scenePath = AssetDatabaseCompatibility.GuidToPath(sceneGUID); var logPath = System.IO.Path.GetFullPath(System.IO.Path.Combine(UnityEngine.Application.dataPath, "../Logs")); Debug.LogError($"Loading Entity Scene failed because the entity header file couldn't be resolved. This might be caused by a failed import of the entity scene. Please take a look at the SubScene MonoBehaviour that references this scene or at the asset import worker log in {logPath}. scenePath={scenePath} guid={sceneGUID}"); #else Debug.LogError($"Loading Entity Scene failed because the entity header file couldn't be resolved: guid={sceneGUID}."); #endif return(false); } #if !UNITY_DOTSRUNTIME if (!BlobAssetReference <SceneMetaData> .TryRead(sceneHeaderPath, SceneMetaDataSerializeUtility.CurrentFileFormatVersion, out var sceneMetaDataRef)) { #if UNITY_EDITOR Debug.LogError($"Loading Entity Scene failed because the entity header file was an old version or doesn't exist: guid={sceneGUID} path={sceneHeaderPath}"); #else Debug.LogError($"Loading Entity Scene failed because the entity header file was an old version or doesn't exist: {sceneGUID}\nNOTE: In order to load SubScenes in the player you have to use the new BuildConfiguration asset based workflow to build & run your player.\n{sceneHeaderPath}"); #endif return(false); } #else Assert.IsTrue(EntityManager.HasComponent <RequestSceneHeader>(sceneEntity), "You may only resolve a scene if the entity has a RequestSceneHeader component"); Assert.IsTrue(EntityManager.HasComponent <SceneMetaDataLoaded>(sceneEntity), "You may only resolve a scene if the entity has a SceneMetaDataLoaded component"); var sceneMetaDataLoaded = EntityManager.GetComponentData <SceneMetaDataLoaded>(sceneEntity); if (!sceneMetaDataLoaded.Success) { return(false); } var requestSceneHeader = EntityManager.GetComponentData <RequestSceneHeader>(sceneEntity); var sceneMetaDataRef = default(BlobAssetReference <SceneMetaData>); var asyncOp = new AsyncOp() { m_Handle = requestSceneHeader.IOHandle }; using (asyncOp) { unsafe { asyncOp.GetData(out var sceneData, out var sceneDataSize); if (!BlobAssetReference <SceneMetaData> .TryRead(sceneData, SceneMetaDataSerializeUtility.CurrentFileFormatVersion, out sceneMetaDataRef)) { Debug.LogError($"Loading Entity Scene failed because the entity header file was an old version or doesn't exist: {sceneGUID}\nNOTE: In order to load SubScenes in the player you have to use the new BuildConfiguration asset based workflow to build & run your player.\n{sceneHeaderPath}"); return(false); } } } #endif ref var sceneMetaData = ref sceneMetaDataRef.Value;