Skip to content

Commit

Permalink
fix: avoid applying rules to current editing prefab asset (close: #19)
Browse files Browse the repository at this point in the history
  • Loading branch information
favoyang committed Apr 13, 2020
1 parent 2582142 commit 9c4df8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Documentation~/AddressableImporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Table of Contents
- [Address Replacement](#address-replacement)
- [Notice for moved or re-imported assets](#notice-for-moved-or-re-imported-assets)
- [Quick assets import](#quick-assets-import)
- [About prefab mode](#about-prefab-mode)

## Setup the Importer

Expand Down Expand Up @@ -74,6 +75,10 @@ Similar to [Group Replacement](#group-replacement), address replacement is also

## Quick assets import

You may have lots existing assets before using the importer. To quickly apply importer rules, right click the target folders and click context menu `AddressablesImporter: Check Folder(s)`. This is more efficient than reimport asset.
The importer will apply your rules whenever an asset being imported, moved or deleted. However you may want to apply new or modified rules to existing assets. To quickly apply importer rules, select target folder(s) in project view, right click to open the context menu, and click `AddressablesImporter: Check Folder(s)`. The action is more efficient than reimport asset(s).

![AddressableImport Context Menu](AddressableImportSettings-ContextMenu.png)

## About prefab mode

When both prefab mode (the preview scene for editing a prefab) and the auto save feature are enabled, every modification will cause the asset to be saved and trigger the importer, leads to slow response. For performance reason, the importer will ignore current editing asset.
5 changes: 5 additions & 0 deletions Editor/AddressableImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor.AddressableAssets.Settings.GroupSchemas;
using UnityEditor.Experimental.SceneManagement;

public class AddressableImporter : AssetPostprocessor
{
Expand All @@ -28,8 +29,12 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
else if (importSettings.rules == null || importSettings.rules.Count == 0)
return;
var entriesAdded = new List<AddressableAssetEntry>();
var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
foreach (string assetPath in importedAssets)
{
// Ignore current editing prefab asset.
if (prefabStage != null && prefabStage.prefabAssetPath == assetPath)
continue;
foreach (var rule in importSettings.rules)
{
if (rule.Match(assetPath))
Expand Down

0 comments on commit 9c4df8b

Please sign in to comment.