private void HandleImportSceneAsset(SceneAsset asset, PostprocessEventArgs args) { var assetGuid = args.AssetGuid; var sceneGuid = new SceneGuid { Guid = new Guid(asset.Guid) }; m_AssetGuidToSceneGuid.TryAdd(assetGuid, sceneGuid); m_SceneGuidToAssetGuid.TryAdd(sceneGuid, assetGuid); }
public void UnloadAllScenesByGuid(SceneGuid sceneGuid) { using (var scenes = GetAllLoadedScenesByGuid(sceneGuid)) { for (var i = 0; i < scenes.Length; i++) { UnloadScene(scenes[i]); } } }
internal static void SelectScene(SceneGuid guid) { if (Session == null) { return; } foreach (var window in s_ActiveHierarchies) { window.TransferSceneSelection.Add(guid); window.Repaint(); } }
public SceneGraph GetGraphForScene(SceneGuid sceneGuid) { var workspaceScenes = GetWorkspaceScenesRO(); for (var i = 0; i < workspaceScenes.Length; i++) { if (workspaceScenes[i].Scene.SceneGuid.Guid == sceneGuid.Guid) { return(GetGraphForScene(workspaceScenes[i].Scene)); } } return(null); }
/// <summary> /// Returns all loaded scenes with the given <see cref="SceneGuid"/>. /// </summary> private NativeList <Scene> GetAllLoadedScenesByGuid(SceneGuid sceneGuid, Allocator allocator = Allocator.Temp) { var workspaceScenes = GetWorkspaceScenesRO(); var list = new NativeList <Scene>(1, allocator); for (var i = 0; i < workspaceScenes.Length; i++) { if (workspaceScenes[i].Scene.SceneGuid.Guid == sceneGuid.Guid) { list.Add(workspaceScenes[i].Scene); } } return(list); }
public override void Load() { foreach (var guid in FindAllAssetGuid <SceneAsset>()) { var asset = AssetDatabase.LoadAssetAtPath <SceneAsset>(AssetDatabase.GUIDToAssetPath(guid)); var sceneGuid = new SceneGuid { Guid = new Guid(asset.Guid) }; m_AssetGuidToSceneGuid.Add(guid, sceneGuid); m_SceneGuidToAssetGuid.Add(sceneGuid, guid); } AssetPostprocessorCallbacks.RegisterAssetImportedHandlerForType <SceneAsset>(HandleImportSceneAsset); AssetPostprocessorCallbacks.RegisterAssetDeletedHandler(HandleDeleteAsset); }
private void HandleSceneImported(SceneAsset asset, PostprocessEventArgs args) { if (Entity.Null == m_WorldManager.GetConfigEntity()) { return; } if (m_SceneSaveScope > 0) { var sceneGuid = new SceneGuid { Guid = new Guid(asset.Guid) }; var workspaceScenes = GetWorkspaceScenesRW(); for (var i = 0; i < workspaceScenes.Length; i++) { var workspaceScene = workspaceScenes[i]; if (workspaceScene.Scene.SceneGuid == sceneGuid) { workspaceScene.ChangeVersion = 1; } workspaceScenes[i] = workspaceScene; } EntityHierarchyWindow.RepaintAll(); return; } if (!IsAnyInstanceOfSceneLoaded(new Guid(asset.Guid))) { return; } if (EditorUtility.DisplayDialog( $"Scene asset has been changed", $"'{args.AssetPath}' has been changed. Would you like to reload the file?", "Yes", "No")) { LoadScene(args.AssetPath); } }
/// <summary> /// Gets all the entities from a certain guid /// </summary> /// <param name="scene">The scene entity</param> /// <param name="entityManager">The EntityManger instance</param> /// <warning>Make sure the scene is loaded when called!</warning> /// <returns>All the entities in a scene as native array</returns> public static NativeArray <Entity> GetAllEntitiesFromGuid(Entity scene, EntityManager entityManager) { var counter = 0; try { NativeArray <Entity> entities = _allEntities; NativeArray <Entity> tempArray = new NativeArray <Entity>(entities.Length, Allocator.Temp); SceneGuid guid = new SceneGuid(); for (var i = 0; i < entities.Length; i++) { guid = entityManager.GetSharedComponentData <SceneGuid>(entities[i]); var loadedGuid = entityManager.GetSharedComponentData <SceneGuid>(scene); if (guid.Equals(loadedGuid) && !entityManager.HasComponent <IsNewScene>(entities[i])) { tempArray[counter] = entities[i]; counter++; } } if (counter != 0) { NativeArray <Entity> returnArray = new NativeArray <Entity>((counter), Allocator.Temp); for (int i = 0; i < counter; i++) { returnArray[i] = tempArray[i]; } return(returnArray); } else { throw new NoEntitiesFoundException(); } } catch (Exception exception) { Debug.Log(exception.ToString()); throw exception; } }
public Scene LoadScene(string path) { var sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(path); var sceneGuid = new SceneGuid { Guid = new Guid(sceneAsset.Guid) }; if (IsAnyInstanceOfSceneLoaded(sceneGuid.Guid)) { using (var scenes = GetAllLoadedScenesByGuid(sceneGuid)) { for (var i = 0; i < scenes.Length; i++) { UnloadScene(scenes[i]); } } } var scene = m_Persistence.LoadScene(m_WorldManager.EntityManager, path); LoadScene(scene); return(scene); }
private IEnumerable <Scene> GetScenesForCreatedEntities(WorldDiff diff) { var sharedSetCommands = diff.SharedSetCommands; for (var packedEntityIndex = 0; packedEntityIndex < diff.NewEntityCount; packedEntityIndex++) { var sceneGuid = new SceneGuid(); var sceneInstanceId = new SceneInstanceId(); for (var i = 0; i < sharedSetCommands.Length; i++) { var cmd = sharedSetCommands[i]; if (cmd.EntityIndex != packedEntityIndex) { continue; } var stableTypeHash = diff.TypeHashes[cmd.TypeHashIndex]; if (stableTypeHash == TypeManager.GetTypeInfo <SceneGuid>().StableTypeHash) { sceneGuid = (SceneGuid)cmd.BoxedSharedValue; } if (stableTypeHash == TypeManager.GetTypeInfo <SceneInstanceId>().StableTypeHash) { sceneInstanceId = (SceneInstanceId)cmd.BoxedSharedValue; } } if (sceneGuid.Guid != Guid.Empty) { yield return(new Scene(sceneGuid, sceneInstanceId)); } } }