public override void OnImportAsset(AssetImportContext ctx) { try { ctx.DependsOnCustomDependency("EntityBinaryFileFormatVersion"); var sceneWithBuildSettings = ReadSceneWithBuildSettings(ctx.assetPath); // Ensure we have as many dependencies as possible registered early in case an exception is thrown var scenePath = AssetDatabase.GUIDToAssetPath(sceneWithBuildSettings.SceneGUID.ToString()); ctx.DependsOnSourceAsset(scenePath); if (sceneWithBuildSettings.BuildSettings.IsValid) { var buildSettingPath = AssetDatabase.GUIDToAssetPath(sceneWithBuildSettings.BuildSettings.ToString()); ctx.DependsOnSourceAsset(buildSettingPath); var buildSettingDependencies = AssetDatabase.GetDependencies(buildSettingPath); foreach (var dependency in buildSettingDependencies) { ctx.DependsOnSourceAsset(dependency); } } var dependencies = AssetDatabase.GetDependencies(scenePath); foreach (var dependency in dependencies) { if (dependency.ToLower().EndsWith(".prefab")) { ctx.DependsOnSourceAsset(dependency); } } var buildSettings = BuildSettings.LoadAsset(sceneWithBuildSettings.BuildSettings); var scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive); try { var settings = new GameObjectConversionSettings(); settings.SceneGUID = sceneWithBuildSettings.SceneGUID; settings.BuildSettings = buildSettings; settings.AssetImportContext = ctx; EditorEntityScenes.WriteEntityScene(scene, settings); } finally { EditorSceneManager.CloseScene(scene, true); } } // Currently it's not acceptable to let the asset database catch the exception since it will create a default asset without any dependencies // This means a reimport will not be triggered if the scene is subsequently modified catch (Exception e) { Debug.Log($"Exception thrown during SubScene import: {e}"); } }
public LiveLinkConnection(Hash128 buildSettingsGuid) { _BuildSettingsGUID = buildSettingsGuid; if (buildSettingsGuid != default) { _BuildSettings = BuildSettings.LoadAsset(buildSettingsGuid); if (_BuildSettings == null) { Debug.LogError($"Unable to load build settings asset from guid {buildSettingsGuid}."); } } Undo.postprocessModifications += PostprocessModifications; Undo.undoRedoPerformed += GlobalDirtyLiveLink; _RemovedScenes = new NativeList <Hash128>(Allocator.Persistent); }