private bool ResolveArtifactPaths(IList <IndexArtifact> artifacts, out List <IndexArtifact> unresolvedArtifacts, Task task, ref int completed) { task.Report($"Resolving {artifacts.Count} artifacts..."); var artifactIndexSuffix = GetIndexTypeSuffix(); var indexImporterType = SearchIndexEntryImporter.GetIndexImporterType(settings.type, settings.options.GetHashCode()); unresolvedArtifacts = new List <IndexArtifact>(); foreach (var a in artifacts) { if (a == null || !string.IsNullOrEmpty(a.path) || string.IsNullOrWhiteSpace(a.guid)) { ++completed; continue; } // Make sure the asset is still valid at this stage, otherwise ignore it // It could be a temporary file that was created since import. var assetPath = AssetDatabase.GUIDToAssetPath(a.guid); var invalidAsset = string.IsNullOrEmpty(assetPath); if (invalidAsset) { Debug.LogWarning($"Cannot resolve index artifact for {a.guid}"); continue; } if (!a.valid) { a.key = ProduceArtifact(new GUID(a.guid), indexImporterType, ImportMode.NoImport, out var availableState); if (!a.valid) { if (availableState == OnDemandState.Unavailable) { ProduceArtifact(a.guid, indexImporterType, ImportMode.Asynchronous); } unresolvedArtifacts.Add(a); continue; } } if (GetArtifactPaths(a.key, out var paths)) { var resultPath = "." + artifactIndexSuffix; a.path = paths.LastOrDefault(p => p.EndsWith(resultPath, StringComparison.Ordinal)); if (a.path == null) { Debug.LogFormat(LogType.Warning, LogOption.NoStacktrace, this, $"Cannot find index artifact {resultPath} for {assetPath} ({a.guid})\n\t- {String.Join("\n\t- ", paths)}"); } ++completed; } } task.Report(++completed); return(unresolvedArtifacts.Count == 0); }
private IndexArtifact[] ProduceArtifacts(IList <string> assetPaths) { var artifacts = InitializeIndexArtifacts(assetPaths); var indexImporterType = SearchIndexEntryImporter.GetIndexImporterType(settings.type, settings.options.GetHashCode()); #if UNITY_2020_2_OR_NEWER var artifactIds = AssetDatabaseExperimental.ProduceArtifactsAsync(artifacts.Select(a => new GUID(a.guid)).ToArray(), indexImporterType); for (int i = 0; i < artifactIds.Length; ++i) { artifacts[i].key = artifactIds[i].value; } #else for (int i = 0; i < artifacts.Length; ++i) { if (String.IsNullOrEmpty(artifacts[i].guid)) { continue; } artifacts[i].key = ProduceArtifact(artifacts[i].guid, indexImporterType, ImportMode.Asynchronous); } #endif return(artifacts); }