Skip to content

Commit

Permalink
fix: allow load import settings file independent to the default locat…
Browse files Browse the repository at this point in the history
…ion (#64, #68)

Co-authored-by: BuildMachine.Vince <[email protected]>
  • Loading branch information
favoyang and JVinceW authored Feb 6, 2022
1 parent bb76ed0 commit 8004b5c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
18 changes: 8 additions & 10 deletions Documentation~/AddressableImporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Table of Contents

## Setup the Importer

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`.
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 > Addressables > Import Settings`.

![AddressableImportSettings Create](AddressableImportSettings-Create.png)

Expand Down Expand Up @@ -95,18 +95,18 @@ In another word, if you are intending to manually change the address later, leav
You can add a label to your addressable asset.

You can choose between:
- `Label Refs`: use a static label already created in Unity project
- `Label Refs`: use a static label already created in Unity project
- `Dynamic Labels`: you can automatically create label in your Unity project and add it to your addressable asset.
You can use the same rules to create a dynamic name group explained in [Group Replacement](#group-replacement).
You can use the same rules to create a dynamic name group explained in [Group Replacement](#group-replacement).

| Asset Path | Rule Path | Label Replacement | Result |
|------------------------|-----------------------------------------------|-----------------------------------|------------------|
| `Assets/cat/cat01.png` | `Assets/(?<category>[^/]+)/(.*)\.png` | `${category}` | cat |


For an interactive example you can watch this video: https://youtu.be/r5bCKY6TvP0


The importer always overrides existing labels if `LabelMode = Replace`.

## Quick Assets Re-import
Expand Down Expand Up @@ -141,5 +141,3 @@ error CS0246: The type or namespace name 'ISearchFilterable' could not be found
```

Notice that the Odin support may be moved to an additional plugin or discontinued if the importer's UX gets improved in the future.


27 changes: 19 additions & 8 deletions Editor/AddressableImportSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
using Sirenix.OdinInspector;
#endif

[CreateAssetMenu(fileName = "AddressableImportSettings", menuName = "Addressable Assets/Import Settings", order = 50)]
[CreateAssetMenu(fileName = "AddressableImportSettings", menuName = "Addressables/Import Settings", order = 50)]
public class AddressableImportSettings : ScriptableObject
{
public const string kDefaultConfigObjectName = "addressableimportsettings";
public const string kConfigObjectName = "addressableimportsettings";
public const string kDefaultPath = "Assets/AddressableAssetsData/AddressableImportSettings.asset";

[Tooltip("Creates a group if the specified group doesn't exist.")]
Expand Down Expand Up @@ -63,14 +63,25 @@ public static AddressableImportSettings Instance
get
{
AddressableImportSettings so;
// Try to locate settings via EditorBuildSettings.
if (EditorBuildSettings.TryGetConfigObject(kDefaultConfigObjectName, out so))
// Try to locate settings from EditorBuildSettings
if (EditorBuildSettings.TryGetConfigObject(kConfigObjectName, out so))
return so;
// Try to locate settings via path.
// Try to locate settings from default path
so = AssetDatabase.LoadAssetAtPath<AddressableImportSettings>(kDefaultPath);
if (so != null)
EditorBuildSettings.AddConfigObject(kDefaultConfigObjectName, so, true);
return so;
if (so != null) {
EditorBuildSettings.AddConfigObject(kConfigObjectName, so, true);
return so;
}
// Try to locate settings from AssetDatabase
var path = AssetDatabase.FindAssets($"t:{nameof(AddressableImportSettings)}");
if (path.Length > 0) {
var assetPath = AssetDatabase.GUIDToAssetPath(path[0]);
so = AssetDatabase.LoadAssetAtPath<AddressableImportSettings>(assetPath);
EditorBuildSettings.AddConfigObject(kConfigObjectName, so, true);
return so;
}
return null;
}
}

}
2 changes: 1 addition & 1 deletion Editor/AddressableImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
var importSettings = AddressableImportSettings.Instance;
if (importSettings == null)
{
Debug.LogWarningFormat("[AddressableImporter] import settings file not found.\nPlease go to Assets/AddressableAssetsData folder, right click in the project window and choose 'Create > Addressable Assets > Import Settings'.");
Debug.LogWarningFormat("[AddressableImporter] import settings file not found.\nPlease go to Assets/AddressableAssetsData folder, right click in the project window and choose 'Create > Addressables > Import Settings'.");
return;
}
if (importSettings.rules == null || importSettings.rules.Count == 0)
Expand Down

0 comments on commit 8004b5c

Please sign in to comment.