Skip to content

Commit

Permalink
feat: reimport api (refs: #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
favoyang committed Apr 24, 2020
1 parent 4691b84 commit 82cf7bd
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions Editor/AddressableImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,32 +157,31 @@ static bool TryGetGroup(AddressableAssetSettings settings, string groupName, out
/// </summary>
public class FolderImporter
{
[MenuItem("Assets/AddressablesImporter: Check Folder(s)")]
private static void CheckFolders()
/// <summary>
/// Remporter folders.
/// </summary>
/// <param name="settings">Reference to the <see cref="AddressableAssetSettings"/></param>
public static void ReimportFolders(IEnumerable<String> assetPaths)
{
HashSet<string> filesToImport = new HashSet<string>();
// Folders comes up as Object.
foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
foreach (var assetPath in assetPaths)
{
var assetPath = AssetDatabase.GetAssetPath(obj);
// Other assets may appear as Object, so a Directory Check filters directories from folders.
if (Directory.Exists(assetPath))
{
var filesToAdd = Directory.GetFiles(assetPath, "*", SearchOption.AllDirectories);
foreach (var file in filesToAdd)
{
// If Directory.GetFiles accepted Regular Expressions, we could filter the metas before iterating.
// Filter out meta and DS_Store files.
if (!file.EndsWith(".meta") && !file.EndsWith(".DS_Store"))
{
filesToImport.Add(file.Replace('\\', '/'));
}
}
}
}

if (filesToImport.Count > 0)
{
Debug.Log($"AddressablesImporter: Found {filesToImport.Count} assets...");
Debug.Log($"AddressablesImporter: reimport {filesToImport.Count} assets...");
OnPostprocessAllAssets(filesToImport.ToArray(), null, null, null);
}
else
Expand All @@ -191,9 +190,29 @@ private static void CheckFolders()
}
}

/// <summary>
/// Allows assets within the selected folder to be checked agains the Addressable Importer rules.
/// </summary>
[MenuItem("Assets/AddressablesImporter: Check Folder(s)")]
private static void CheckFoldersFromSelection()
{
List<string> assetPaths = new List<string>();
// Folders comes up as Object.
foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
{
var assetPath = AssetDatabase.GetAssetPath(obj);
// Other assets may appear as Object, so a Directory Check filters directories from folders.
if (Directory.Exists(assetPath))
{
assetPaths.Add(assetPath);
}
}
ReimportFolders(assetPaths);
}

// Note that we pass the same path, and also pass "true" to the second argument.
[MenuItem("Assets/AddressablesImporter: Check Folder(s)", true)]
private static bool ValidateCheckFolders()
private static bool ValidateCheckFoldersFromSelection()
{
foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
{
Expand Down

0 comments on commit 82cf7bd

Please sign in to comment.