public static void CollectFiles(string resolverPath, string folderPath) { if (string.IsNullOrEmpty(resolverPath)) { throw new ArgumentException("Value cannot be null or empty.", nameof(resolverPath)); } if (string.IsNullOrEmpty(folderPath)) { throw new ArgumentException("Value cannot be null or empty.", nameof(folderPath)); } var resolver = AssetInfoEditorUtility.LoadInfo <Utf8JsonResolverAssetInfo>(resolverPath); string[] paths = Directory.GetFiles(folderPath, $"*.{Utf8JsonExternalTypeEditorUtility.EXTERNAL_TYPE_ASSET_EXTENSION_NAME}", SearchOption.AllDirectories); resolver.Sources.Clear(); for (int i = 0; i < paths.Length; i++) { string path = paths[i]; var asset = AssetDatabase.LoadAssetAtPath <TextAsset>(path); if (asset != null) { resolver.Sources.Add(asset); } } AssetInfoEditorUtility.SaveInfo(resolverPath, resolver, false); }
public static void ClearResolver(string assetPath) { if (string.IsNullOrEmpty(assetPath)) { throw new ArgumentException("Value cannot be null or empty.", nameof(assetPath)); } var info = AssetInfoEditorUtility.LoadInfo <Utf8JsonResolverAssetInfo>(assetPath); string path = GetDestinationSourcePath(assetPath, info.ResolverName, info.DestinationSource); if (!string.IsNullOrEmpty(path)) { info.DestinationSource = null; AssetInfoEditorUtility.SaveInfo(assetPath, info); AssetDatabase.MoveAssetToTrash(path); } }
public static void GenerateResolver(string assetPath, ICodeGenerateContainerValidation validation = null, Compilation compilation = null, SyntaxGenerator generator = null) { if (string.IsNullOrEmpty(assetPath)) { throw new ArgumentException("Value cannot be null or empty.", nameof(assetPath)); } var info = AssetInfoEditorUtility.LoadInfo <Utf8JsonResolverAssetInfo>(assetPath); string source = GenerateResolver(info, validation, compilation, generator); string path = GetDestinationSourcePath(assetPath, info.ResolverName, info.DestinationSource); File.WriteAllText(path, source); AssetDatabase.ImportAsset(path); if (info.DestinationSource == null) { info.DestinationSource = AssetDatabase.LoadAssetAtPath <TextAsset>(path); AssetInfoEditorUtility.SaveInfo(assetPath, info); } }