Skip to content

Commit

Permalink
feat: re-import API (close: #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
favoyang authored May 7, 2020
1 parent 9923f07 commit 8b00747
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions Editor/AddressableImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
return;

var dirty = false;

// Apply import rules.
var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
foreach (var importedAsset in importedAssets)
Expand All @@ -46,7 +46,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
if (prefabStage == null || prefabStage.prefabAssetPath != movedAsset) // Ignore current editing prefab asset.
dirty |= ApplyImportRule(movedAsset, movedFromAssetPath, settings, importSettings);
}

// Remove empty groups.
if (importSettings.removeEmtpyGroups)
{
Expand Down Expand Up @@ -105,7 +105,7 @@ static bool ApplyImportRule(

return dirty;
}

static AddressableAssetEntry CreateOrUpdateAddressableAssetEntry(
AddressableAssetSettings settings,
AddressableImportSettings importSettings,
Expand Down Expand Up @@ -213,29 +213,28 @@ static bool TryGetGroup(AddressableAssetSettings settings, string groupName, out
/// </summary>
public class FolderImporter
{
[MenuItem("Assets/AddressablesImporter: Check Folder(s)")]
private static void CheckFolders()
/// <summary>
/// Reimporter 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...");
Expand All @@ -247,9 +246,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 8b00747

Please sign in to comment.