From 6b89e7925004682a60fd2006d8b095709cfe779a Mon Sep 17 00:00:00 2001 From: Favo Yang Date: Sat, 29 Jun 2019 16:44:24 +0800 Subject: [PATCH] Import rule supports simplifying address to filename without extension. --- AddressableImporter/Editor/AddressableImportRule.cs | 6 +++++- AddressableImporter/Editor/AddressableImporter.cs | 9 +++++++-- README.md | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/AddressableImporter/Editor/AddressableImportRule.cs b/AddressableImporter/Editor/AddressableImportRule.cs index 8249c04..e478bfd 100644 --- a/AddressableImporter/Editor/AddressableImportRule.cs +++ b/AddressableImporter/Editor/AddressableImportRule.cs @@ -43,7 +43,11 @@ public class AddressableImportRule /// public List labelRefs; - // public bool simplified; + /// + /// Simplify address + /// + [Tooltip("Simplify address to filename without extension")] + public bool simplified; public bool HasLabel { diff --git a/AddressableImporter/Editor/AddressableImporter.cs b/AddressableImporter/Editor/AddressableImporter.cs index 8723e0e..b8f0134 100644 --- a/AddressableImporter/Editor/AddressableImporter.cs +++ b/AddressableImporter/Editor/AddressableImporter.cs @@ -5,6 +5,7 @@ using UnityEditor.AddressableAssets; using UnityEditor.AddressableAssets.Settings; using System; +using System.IO; public class AddressableImporter : AssetPostprocessor { @@ -21,7 +22,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse { if (rule.Match(path)) { - var entry = CreateOrUpdateAddressableAssetEntry(settings, path, rule.groupName, rule.labels); + var entry = CreateOrUpdateAddressableAssetEntry(settings, path, rule.groupName, rule.labels, rule.simplified); if (entry != null) { entriesAdded.Add(entry); @@ -40,7 +41,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse } } - static AddressableAssetEntry CreateOrUpdateAddressableAssetEntry(AddressableAssetSettings settings, string path, string groupName, IEnumerable labels) + static AddressableAssetEntry CreateOrUpdateAddressableAssetEntry(AddressableAssetSettings settings, string path, string groupName, IEnumerable labels, bool simplified) { var group = GetGroup(settings, groupName); if (group == null) @@ -52,7 +53,11 @@ static AddressableAssetEntry CreateOrUpdateAddressableAssetEntry(AddressableAsse var entry = settings.CreateOrMoveEntry(guid, group); // Override address if address is a path if (string.IsNullOrEmpty(entry.address) || entry.address.StartsWith("Assets/")) + { + if (simplified) + path = Path.GetFileNameWithoutExtension(path); entry.address = path; + } // Add labels foreach (var label in labels) { diff --git a/README.md b/README.md index 316a3e0..1744fd7 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Create a rule - Regex - Group name, leaves blank for the default group - Labels, the labels to add +- Simplified, simplify address to filename without extension Rule Examples @@ -31,4 +32,4 @@ Rule Examples 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, then reimport or move it, 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 or simplified the address, then reimport or move it, the address remains no change.