diff --git a/AddressableImporter/Editor/AddressableImportRule.cs b/AddressableImporter/Editor/AddressableImportRule.cs
index 817cb70..8249c04 100644
--- a/AddressableImporter/Editor/AddressableImportRule.cs
+++ b/AddressableImporter/Editor/AddressableImportRule.cs
@@ -32,6 +32,12 @@ public class AddressableImportRule
///
public AddressableImportRuleMatchType matchType;
+ ///
+ /// Addressable group name
+ ///
+ [Tooltip("Leaves blank for the default group.")]
+ public string groupName;
+
///
/// Label reference list
///
diff --git a/AddressableImporter/Editor/AddressableImporter.cs b/AddressableImporter/Editor/AddressableImporter.cs
index 94a2eba..e2cf830 100644
--- a/AddressableImporter/Editor/AddressableImporter.cs
+++ b/AddressableImporter/Editor/AddressableImporter.cs
@@ -10,7 +10,6 @@ public class AddressableImporter : AssetPostprocessor
{
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
- var type = typeof(AddressableImporter);
var settings = AddressableAssetSettingsDefaultObject.Settings;
var importSettings = AddressableImportSettings.Instance;
if (importSettings.rules == null || importSettings.rules.Count == 0)
@@ -22,12 +21,15 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
{
if (rule.Match(path))
{
- var entry = CreateOrUpdateAddressableAssetEntry(settings, path, rule.labels);
- entriesAdded.Add(entry);
- if (rule.HasLabel)
- Debug.LogFormat("[{0}] Entry created for {1} with labels {2}", type, path, string.Join(", ", entry.labels));
- else
- Debug.LogFormat("[{0}] Entry created for {1}", type, path);
+ var entry = CreateOrUpdateAddressableAssetEntry(settings, path, rule.groupName, rule.labels);
+ if (entry != null)
+ {
+ entriesAdded.Add(entry);
+ if (rule.HasLabel)
+ Debug.LogFormat("[AddressableImporter] Entry created for {0} with labels {1}", path, string.Join(", ", entry.labels));
+ else
+ Debug.LogFormat("[AddressableImporter] Entry created for {0}", path);
+ }
}
}
}
@@ -35,9 +37,14 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesAdded, true);
}
- static AddressableAssetEntry CreateOrUpdateAddressableAssetEntry(AddressableAssetSettings settings, string path, IEnumerable labels)
+ static AddressableAssetEntry CreateOrUpdateAddressableAssetEntry(AddressableAssetSettings settings, string path, string groupName, IEnumerable labels)
{
- var group = settings.DefaultGroup;
+ var group = GetGroup(settings, groupName);
+ if (group == null)
+ {
+ Debug.LogErrorFormat("[AddressableImporter] Failed to find group {0} when importing {1}. Please check the group exists, then reimport the asset.", groupName, path);
+ return null;
+ }
var guid = AssetDatabase.AssetPathToGUID(path);
var entry = settings.CreateOrMoveEntry(guid, group);
// Override address if address is a path
@@ -51,5 +58,18 @@ static AddressableAssetEntry CreateOrUpdateAddressableAssetEntry(AddressableAsse
}
return entry;
}
+
+ ///
+ /// Find asset group by given name. Return default group if given name is null.
+ ///
+ static AddressableAssetGroup GetGroup(AddressableAssetSettings settings, string groupName)
+ {
+ if (groupName != null)
+ groupName.Trim();
+ if (string.IsNullOrEmpty(groupName))
+ return settings.DefaultGroup;
+ return settings.groups.Find(g => g.Name == groupName);
+ }
+
}
diff --git a/LICENSE.meta b/LICENSE.meta
new file mode 100644
index 0000000..d08e332
--- /dev/null
+++ b/LICENSE.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 625fa35101860bf4f8c1d4903253c9ce
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/README.md b/README.md
index 8deb03b..316a3e0 100644
--- a/README.md
+++ b/README.md
@@ -5,20 +5,21 @@ The importer marks assets as addressable, by applying to files having a path mat
## Usage
-You should create a single AddressableImportSettings file located at `Assets/AddressableAssetsData/AddressableImportSettings.asset` in your project. To create it, go to `Assets/AddressableAssetsData` folder, right click in your project window and choose `Create > Addressable Assets > Import Settings`.
+You should create a single AddressableImportSettings file located at `Assets/AddressableAssetsData/AddressableImportSettings.asset`. To create it, go to `Assets/AddressableAssetsData` folder, right click in your project window and choose `Create > Addressable Assets > Import Settings`.
-If no settings file exists, an empty one will be created for you, when import any new asset.
+If no settings file exists, an empty one will be created when importing any new asset.
-Once the settings file selected, you can edit rules in the inspector window.
+Once the settings file selected, you can edit rules in the inspector window. Then click `File > Save Project` to apply the changes.
![AddressableImportSettings Insepctor](./Documentation~/AddressableImportSettings-Insepctor.png)
-Rule properties
+Create a rule
- Path, the path pattern
- Match type
- Wildcard, `*` matches any number of characters, `?` matches a single character
- Regex
-- Label references, the labels to add
+- Group name, leaves blank for the default group
+- Labels, the labels to add
Rule Examples
@@ -28,6 +29,6 @@ Rule Examples
| Wildcard | Asset/Sprites/Level??/*.asset |
| Regex | ^Assets/Models/.*\\.fbx |
-Notice for moved or re-imported assets
+Notices for moved or re-imported assets
- The importer will not override existing labels.
-- The importer will only override address if it looks like a path (starts with `Assets/`). In another word, if you changed the address, and reimport or move it later, the address remains no change.
+- The importer will only override address if it looks like a path (starts with `Assets/`). In another word, if you changed the address, then reimport or move it, the address remains no change.
diff --git a/README.md.meta b/README.md.meta
new file mode 100644
index 0000000..a2f58d1
--- /dev/null
+++ b/README.md.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 3e1da7b09b11d4844b7b157b4a914f4e
+TextScriptImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant: