public override void OnImportAsset(AssetImportContext ctx) { var settings = new SearchDatabase.Settings { type = "asset", options = GetOptions() }; var indexer = SearchDatabase.CreateIndexer(settings); try { indexer.IndexDocument(ctx.assetPath, false); indexer.Finish(removedDocuments: null); var indexArtifactPath = ctx.GetOutputArtifactFilePath($"{(int)options:X}.index".ToLowerInvariant()); using (var fileStream = new FileStream(indexArtifactPath, FileMode.CreateNew, FileAccess.Write, FileShare.None)) indexer.Write(fileStream); ctx.DependsOnSourceAsset(ctx.assetPath); ctx.DependsOnCustomDependency(GetType().GUID.ToString("N")); ctx.DependsOnCustomDependency(nameof(CustomObjectIndexerAttribute)); } catch (Exception ex) { ctx.LogImportError($"Failed to build search index for {ctx.assetPath}\n{ex}"); } }
public override void OnImportAsset(AssetImportContext ctx) { var settings = new SearchDatabase.Settings { type = "asset", options = GetOptions() }; try { var indexer = SearchDatabase.CreateIndexer(settings); try { ctx.DependsOnCustomDependency(GetType().GUID.ToString("N")); ctx.DependsOnCustomDependency(nameof(CustomObjectIndexerAttribute)); indexer.IndexDocument(ctx.assetPath, false); indexer.ApplyUnsorted(); } catch (Exception ex) { ctx.LogImportError($"Failed to build search index for {ctx.assetPath}\n{ex}"); } #if USE_SEARCH_MODULE var indexArtifactPath = ctx.GetOutputArtifactFilePath($"{(int)options:X}.index".ToLowerInvariant()); #else var indexArtifactPath = ctx.GetResultPath($"{(int)options:X}.index".ToLowerInvariant()); #endif using (var fileStream = new FileStream(indexArtifactPath, FileMode.CreateNew, FileAccess.Write, FileShare.Read)) indexer.Write(fileStream); } catch (Exception ex) { ctx.LogImportError(ex.Message); } }
public override void OnImportAsset(AssetImportContext ctx) { try { if (Utils.IsUsingADBV1()) { ctx.LogImportWarning("Search indexes are not supported with the Asset Database V1"); return; } var db = ScriptableObject.CreateInstance <SearchDatabase>(); db.Import(ctx.assetPath); ctx.AddObjectToAsset("index", db); ctx.SetMainObject(db); #if UNITY_2020_1_OR_NEWER ctx.DependsOnCustomDependency(nameof(CustomObjectIndexerAttribute)); #endif hideFlags |= HideFlags.HideInInspector; } catch (SearchDatabaseException ex) { ctx.LogImportError(ex.Message, AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(ex.guid))); } }
public override void OnImportAsset(AssetImportContext ctx) { var settings = new SearchDatabase.Settings { guid = null, root = null, roots = null, source = null, name = null, baseScore = 0, excludes = null, includes = null, type = type, options = GetOptions(), }; EditorApplication.LockReloadAssemblies(); try { var indexer = SearchDatabase.CreateIndexer(settings); indexer.IndexDocument(ctx.assetPath, false); indexer.ApplyUnsorted(); var indexArtifactPath = ctx.GetResultPath($"{type}.{(int)options:X}.index".ToLowerInvariant()); using (var fileStream = new FileStream(indexArtifactPath, FileMode.CreateNew, FileAccess.Write, FileShare.Read)) indexer.Write(fileStream); Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, $"\nGenerated {type} ({GetType().Name}) {indexArtifactPath} for {ctx.assetPath} with {options}"); ctx.DependsOnSourceAsset(Path.GetDirectoryName(ctx.assetPath).Replace("\\", "/")); ctx.DependsOnCustomDependency(GetType().GUID.ToString("N")); #if UNITY_2020_1_OR_NEWER ctx.DependsOnCustomDependency(nameof(CustomObjectIndexerAttribute)); #endif } catch (Exception ex) { Debug.LogException(ex); ctx.LogImportError(ex.Message); } finally { EditorApplication.UnlockReloadAssemblies(); } }
static void PostprocessSprites(Texture2D tex, string pathName, Sprite[] sprites, AssetImportContext context) { if (context != null) { context.DependsOnCustomDependency(kTextureSpritePostprocessorDependencyName); } object[] args = { tex, sprites }; CallPostProcessMethods("OnPostprocessSprites", args); }
static void PostprocessTexture2DArray(Texture2DArray tex, string pathName, AssetImportContext context) { if (context != null) { context.DependsOnCustomDependency(kTexture2DArrayPostprocessorDependencyName); } object[] args = { tex }; CallPostProcessMethods("OnPostprocessTexture2DArray", args); }
static void PreprocessTexture(string pathName, AssetImportContext context) { if (context != null) { context.DependsOnCustomDependency(kTexturePreprocessorDependencyName); } CallPostProcessMethods("OnPreprocessTexture", null); }
public override void OnImportAsset(AssetImportContext ctx) { ctx.DependsOnCustomDependency(EditorUserBuildSettings.activeBuildTarget.ToString()); if (ctx.assetPath.ToLower().EndsWith(k_SceneExtension)) { ImportSceneBundle(ctx); } else { ImportAssetBundle(ctx); } }
public override void OnImportAsset(AssetImportContext ctx) { try { var db = ScriptableObject.CreateInstance <SearchDatabase>(); db.Import(ctx.assetPath); ctx.AddObjectToAsset("index", db); ctx.SetMainObject(db); ctx.DependsOnCustomDependency(nameof(CustomObjectIndexerAttribute)); hideFlags |= HideFlags.HideInInspector; } catch (SearchDatabaseException ex) { ctx.LogImportError(ex.Message, AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(ex.guid))); } }
public override void OnImportAsset(AssetImportContext ctx) { try { ctx.DependsOnCustomDependency("EntityBinaryFileFormatVersion"); ctx.DependsOnCustomDependency("SceneMetaDataFileFormatVersion"); ctx.DependsOnSourceAsset(EntitiesCacheUtility.globalEntitySceneDependencyPath); var sceneWithBuildConfiguration = SceneWithBuildConfigurationGUIDs.ReadFromFile(ctx.assetPath); // Ensure we have as many dependencies as possible registered early in case an exception is thrown var scenePath = AssetDatabase.GUIDToAssetPath(sceneWithBuildConfiguration.SceneGUID.ToString()); ctx.DependsOnSourceAsset(scenePath); if (sceneWithBuildConfiguration.BuildConfiguration.IsValid) { var buildConfigurationPath = AssetDatabase.GUIDToAssetPath(sceneWithBuildConfiguration.BuildConfiguration.ToString()); ctx.DependsOnSourceAsset(buildConfigurationPath); var buildConfigurationDependencies = AssetDatabase.GetDependencies(buildConfigurationPath); foreach (var dependency in buildConfigurationDependencies) { ctx.DependsOnSourceAsset(dependency); } } var dependencies = AssetDatabase.GetDependencies(scenePath); foreach (var dependency in dependencies) { if (dependency.ToLower().EndsWith(".prefab")) { ctx.DependsOnSourceAsset(dependency); } } var config = BuildConfiguration.LoadAsset(sceneWithBuildConfiguration.BuildConfiguration); var scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive); try { var settings = new GameObjectConversionSettings(); settings.SceneGUID = sceneWithBuildConfiguration.SceneGUID; settings.BuildConfiguration = config; settings.AssetImportContext = ctx; settings.FilterFlags = WorldSystemFilterFlags.HybridGameObjectConversion; WriteEntitySceneSettings writeEntitySettings = new WriteEntitySceneSettings(); if (config != null && config.TryGetComponent <DotsRuntimeBuildProfile>(out var profile)) { if (config.TryGetComponent <DotsRuntimeRootAssembly>(out var rootAssembly)) { ctx.DependsOnSourceAsset(AssetDatabase.GetAssetPath(rootAssembly.RootAssembly.asset)); EditorSceneManager.SetActiveScene(scene); writeEntitySettings.Codec = Codec.LZ4; writeEntitySettings.IsDotsRuntime = true; writeEntitySettings.BuildAssemblyCache = new BuildAssemblyCache() { BaseAssemblies = rootAssembly.RootAssembly.asset, PlatformName = profile.Target.UnityPlatformName }; settings.FilterFlags = WorldSystemFilterFlags.DotsRuntimeGameObjectConversion; } } var sectionRefObjs = new List <ReferencedUnityObjects>(); var sectionData = EditorEntityScenes.ConvertAndWriteEntitySceneInternal(scene, settings, sectionRefObjs, writeEntitySettings); WriteAssetDependencyGUIDs(sectionRefObjs, sectionData, ctx); } 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 static void AddAllSystemsDependency(AssetImportContext ctx) { ctx.DependsOnCustomDependency(SystemsVersion); }
public static void AddDependency(AssetImportContext ctx, ComponentType type) { var typeString = TypeString(type.GetManagedType()); ctx.DependsOnCustomDependency(typeString); }
static void PreprocessLightDescription(AssetImportContext assetImportContext, LightDescription description, Light light, AnimationClip[] animations) { assetImportContext.DependsOnCustomDependency(kLightPostprocessorDependencyName); object[] args = { description, light, animations }; CallPostProcessMethods("OnPreprocessLightDescription", args); }
static void PreprocessCameraDescription(AssetImportContext assetImportContext, CameraDescription description, Camera camera, AnimationClip[] animations) { assetImportContext.DependsOnCustomDependency(kCameraPostprocessorDependencyName); object[] args = { description, camera, animations }; CallPostProcessMethods("OnPreprocessCameraDescription", args); }
public override void OnImportAsset(AssetImportContext ctx) { ctx.DependsOnCustomDependency("HLODSystemPlatform"); var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(ctx.selectedBuildTarget); try { UpdateProgress(ctx.assetPath, 0, 1); using (Stream stream = new FileStream(ctx.assetPath, FileMode.Open, FileAccess.Read)) { HLODData data = HLODDataSerializer.Read(stream); RootData rootData = RootData.CreateInstance <RootData>(); TextureFormat compressFormat = GetCompressFormat(data, buildTargetGroup); int currentProgress = 0; int maxProgress = 0; if (data.GetMaterials() != null) { maxProgress += data.GetMaterials().Count; } if (data.GetObjects() != null) { maxProgress += data.GetObjects().Count; } if (data.GetColliders() != null) { maxProgress += data.GetColliders().Count; } rootData.name = "Root"; var serializableMaterials = data.GetMaterials(); var loadedMaterials = new Dictionary <string, Material>(); if (serializableMaterials != null) { for (int mi = 0; mi < serializableMaterials.Count; ++mi) { UpdateProgress(ctx.assetPath, currentProgress++, maxProgress); var sm = serializableMaterials[mi]; if (loadedMaterials.ContainsKey(sm.ID)) { continue; } Material mat = sm.To(); loadedMaterials.Add(sm.ID, mat); if (string.IsNullOrEmpty(AssetDatabase.GetAssetPath(mat)) == false) { continue; } ctx.AddObjectToAsset(mat.name, mat); for (int ti = 0; ti < sm.GetTextureCount(); ++ti) { HLODData.SerializableTexture st = sm.GetTexture(ti); Texture2D texture = st.To(); EditorUtility.CompressTexture(texture, compressFormat, TextureCompressionQuality.Normal); mat.SetTexture(st.Name, texture); ctx.AddObjectToAsset(texture.name, texture); } mat.EnableKeyword("_NORMALMAP"); } } var serializableObjects = data.GetObjects(); var serializableColliders = data.GetColliders(); Dictionary <string, List <GameObject> > createdGameObjects = new Dictionary <string, List <GameObject> >(); Dictionary <string, GameObject> createdColliders = new Dictionary <string, GameObject>(); if (serializableObjects != null) { for (int oi = 0; oi < serializableObjects.Count; ++oi) { UpdateProgress(ctx.assetPath, currentProgress++, maxProgress); var so = serializableObjects[oi]; GameObject go = new GameObject(); go.name = so.Name; MeshFilter mf = go.AddComponent <MeshFilter>(); MeshRenderer mr = go.AddComponent <MeshRenderer>(); List <string> materialIds = so.GetMaterialIds(); List <Material> materials = new List <Material>(); for (int mi = 0; mi < materialIds.Count; ++mi) { string id = materialIds[mi]; if (loadedMaterials.ContainsKey(id)) { materials.Add(loadedMaterials[id]); } else { string path = AssetDatabase.GUIDToAssetPath(id); if (string.IsNullOrEmpty(path) == false) { materials.Add(AssetDatabase.LoadAssetAtPath <Material>(path)); } else { materials.Add(null); } } } Mesh mesh = so.GetMesh().To(); mf.sharedMesh = mesh; mr.sharedMaterials = materials.ToArray(); mr.lightProbeUsage = so.LightProbeUsage; ctx.AddObjectToAsset(mesh.name, mesh); if (createdGameObjects.ContainsKey(go.name) == false) { createdGameObjects.Add(go.name, new List <GameObject>()); } createdGameObjects[go.name].Add(go); } } if (serializableColliders != null) { for (int ci = 0; ci < serializableColliders.Count; ++ci) { UpdateProgress(ctx.assetPath, currentProgress++, maxProgress); var sc = serializableColliders[ci]; GameObject go; if (createdColliders.ContainsKey(sc.Name) == false) { createdColliders[sc.Name] = new GameObject("Collider"); } go = createdColliders[sc.Name]; var collider = sc.CreateGameObject(); if (collider != null) { collider.name = "Collider" + ci; collider.transform.SetParent(go.transform, true); } } } foreach (var objects in createdGameObjects.Values) { GameObject root; if (objects.Count > 1) { root = new GameObject(); root.name = objects[0].name; for (int i = 0; i < objects.Count; ++i) { objects[i].name = objects[i].name + "_" + i; objects[i].transform.SetParent(root.transform, true); } } else { root = objects[0]; } if (createdColliders.ContainsKey(root.name)) { createdColliders[root.name].transform.SetParent(root.transform, true); } rootData.SetRootObject(root.name, root); ctx.AddObjectToAsset(root.name, root); } ctx.AddObjectToAsset("Root", rootData); ctx.SetMainObject(rootData); } } finally { EditorUtility.ClearProgressBar(); } }