Skip to content

Commit

Permalink
Import rule supports simplifying address to filename without extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
favoyang committed Jun 29, 2019
1 parent 630f8ee commit 6b89e79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion AddressableImporter/Editor/AddressableImportRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public class AddressableImportRule
/// </summary>
public List<AssetLabelReference> labelRefs;

// public bool simplified;
/// <summary>
/// Simplify address
/// </summary>
[Tooltip("Simplify address to filename without extension")]
public bool simplified;

public bool HasLabel
{
Expand Down
9 changes: 7 additions & 2 deletions AddressableImporter/Editor/AddressableImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using UnityEditor.AddressableAssets;
using UnityEditor.AddressableAssets.Settings;
using System;
using System.IO;

public class AddressableImporter : AssetPostprocessor
{
Expand All @@ -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);
Expand All @@ -40,7 +41,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
}
}

static AddressableAssetEntry CreateOrUpdateAddressableAssetEntry(AddressableAssetSettings settings, string path, string groupName, IEnumerable<string> labels)
static AddressableAssetEntry CreateOrUpdateAddressableAssetEntry(AddressableAssetSettings settings, string path, string groupName, IEnumerable<string> labels, bool simplified)
{
var group = GetGroup(settings, groupName);
if (group == null)
Expand All @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.

0 comments on commit 6b89e79

Please sign in to comment.