public virtual Hash128 GetGuidForAssetExport(UnityObject uobject)
        {
            if (uobject == null)
            {
                throw new ArgumentNullException(nameof(uobject));
            }
#if UNITY_EDITOR
            if (!m_ExportedAssets.TryGetValue(uobject, out var found))
            {
                var guid = GetGuidForUnityObject(uobject);
                if (guid.IsValid)
                {
                    //Use the guid as an extension and retrieve the path to where to save in the AssetDataBase
                    if (AssetImportContext != null)
                    {
                        var exportFileInfo = AssetImportContext.GetResultPath(guid.ToString());
                        var assetPath      = AssetDatabase.GetAssetPath(uobject);
                        m_ExportedAssets.Add(uobject, found = new ExportedAsset
                        {
                            Guid           = guid,
                            AssetPath      = assetPath,
                            ExportFileInfo = new FileInfo(exportFileInfo),
                        });
                    }
                    //TODO: Set the exported asset path for LiveLink case because AssetImportContext might still be null
                }
            }
            if (found != null)
            {
                return(found.Guid);
            }
#endif
            return(new Hash128());
        }
        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);
            }
        }
Beispiel #3
0
        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();
            }
        }
Beispiel #4
0
        static void WriteAssetDependencyGUIDs(List <ReferencedUnityObjects> referencedUnityObjects, SceneSectionData[] sectionData, AssetImportContext ctx)
        {
            for (var index = 0; index < referencedUnityObjects.Count; index++)
            {
                var sectionIndex = sectionData[index].SubSectionIndex;

                var objRefs = referencedUnityObjects[index];
                if (objRefs == null)
                {
                    continue;
                }

                var path = ctx.GetResultPath($"{sectionIndex}.{EntityScenesPaths.GetExtension(EntityScenesPaths.PathType.EntitiesAssetDependencyGUIDs)}");
                var assetDependencyGUIDs = ReferencedUnityObjectsToGUIDs(objRefs, ctx);

                using (var writer = new StreamBinaryWriter(path))
                {
                    writer.Write(assetDependencyGUIDs.Length);
                    writer.WriteArray(assetDependencyGUIDs.AsArray());
                }

                assetDependencyGUIDs.Dispose();
            }
        }
Beispiel #5
0
    public override void OnImportAsset(AssetImportContext ctx)
    {
        var scene = EditorSceneManager.OpenScene(ctx.assetPath, OpenSceneMode.Additive);

        try
        {
            var dependencies = AssetDatabase.GetDependencies(scene.path).Where(x => x.ToLower().EndsWith(".prefab"));
            foreach (var dependency in dependencies)
            {
                ctx.DependsOnSourceAsset(dependency);
            }

            var metaPath   = ctx.GetResultPath("scenemeta");
            var subScenes  = SubScene.AllSubScenes;
            var sceneGuids = subScenes.Where(x => x.SceneGUID != default(Hash128)).Select(x => x.SceneGUID).Distinct().ToArray();

            var     builder  = new BlobBuilder(Allocator.Temp);
            ref var metaData = ref builder.ConstructRoot <SceneMetaData>();

            builder.Construct(ref metaData.SubScenes, sceneGuids);
            BlobAssetReference <SceneMetaData> .Write(builder, metaPath, SceneMetaDataImporter.CurrentFileFormatVersion);

            builder.Dispose();
        }
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var path = ctx.GetResultPath("output");

            File.WriteAllBytes(path, File.ReadAllBytes(ctx.assetPath));
        }