-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add multiple AddressableImportSettings support (#77)
- Loading branch information
Showing
9 changed files
with
298 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using UnityEngine; | ||
using UnityEditor; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.IO; | ||
using UnityAddressableImporter.Helper; | ||
|
||
public class AddressableImportSettingsList : ScriptableObject | ||
{ | ||
public const string kConfigObjectName = "addressableimportsettingslist"; | ||
public const string kDefaultPath = "Assets/AddressableAssetsData/AddressableImportSettingsList.asset"; | ||
public List<AddressableImportSettings> SettingList; | ||
public List<AddressableImportSettings> EnabledSettingsList => SettingList.Where((s) => s?.rulesEnabled == true).ToList(); | ||
|
||
public static AddressableImportSettingsList Instance | ||
{ | ||
get | ||
{ | ||
AddressableImportSettingsList so; | ||
|
||
// Try to locate settings from EditorBuildSettings | ||
if (EditorBuildSettings.TryGetConfigObject(kConfigObjectName, out so)) | ||
{ | ||
return so; | ||
} | ||
// Try to locate settings from default path | ||
so = AssetDatabase.LoadAssetAtPath<AddressableImportSettingsList>(kDefaultPath); | ||
if (so != null) | ||
{ | ||
EditorBuildSettings.AddConfigObject(kConfigObjectName, so, true); | ||
return so; | ||
} | ||
// Try to locate settings from AssetDatabase | ||
var guidList = AssetDatabase.FindAssets($"t:{nameof(AddressableImportSettingsList)}"); | ||
if (guidList.Length > 0) | ||
{ | ||
var assetPath = AssetDatabase.GUIDToAssetPath(guidList[0]); | ||
so = AssetDatabase.LoadAssetAtPath<AddressableImportSettingsList>(assetPath); | ||
EditorBuildSettings.AddConfigObject(kConfigObjectName, so, true); | ||
return so; | ||
} | ||
|
||
// If AddressableImportSettingsList doesn't exist but AddressableImportSettings exists. create automatically. | ||
var importSettingsGuidList = AssetDatabase.FindAssets($"t:{nameof(AddressableImportSettings)}"); | ||
if (importSettingsGuidList.Length > 0) | ||
{ | ||
var settingList = importSettingsGuidList.Select((guid) => AssetDatabase.LoadAssetAtPath<AddressableImportSettings>(AssetDatabase.GUIDToAssetPath(guid))).ToList(); | ||
var asset = ScriptableObject.CreateInstance<AddressableImportSettingsList>(); | ||
asset.SettingList = settingList; | ||
var path = Path.Combine(Path.GetDirectoryName(AssetDatabase.GUIDToAssetPath(importSettingsGuidList[0])), | ||
nameof(AddressableImportSettingsList) + ".asset"); | ||
Debug.LogFormat("AddressableImportSettingsList doesn't exist. so it is created automatically. path : {0}", path); | ||
AssetDatabase.CreateAsset(asset, path); | ||
AssetDatabase.SaveAssets(); | ||
so = asset; | ||
EditorBuildSettings.AddConfigObject(kConfigObjectName, so, true); | ||
return so; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
public bool RemoveMissingImportSettings() | ||
{ | ||
bool removedAnySettings = false; | ||
for (int i = SettingList.Count - 1; i >= 0; --i) | ||
{ | ||
if (SettingList[i] == null) | ||
{ | ||
SettingList.RemoveAt(i); | ||
removedAnySettings = true; | ||
} | ||
} | ||
|
||
return removedAnySettings; | ||
} | ||
|
||
[ButtonMethod] | ||
public void Reset() | ||
{ | ||
var importSettingsGuidList = AssetDatabase.FindAssets($"t:{nameof(AddressableImportSettings)}"); | ||
SettingList = importSettingsGuidList.Select((guid) => AssetDatabase.LoadAssetAtPath<AddressableImportSettings>(AssetDatabase.GUIDToAssetPath(guid))).ToList(); | ||
AssetDatabase.SaveAssets(); | ||
} | ||
|
||
[ButtonMethod] | ||
public void Documentation() | ||
{ | ||
Application.OpenURL("https://github.com/favoyang/unity-addressable-importer/blob/master/Documentation~/AddressableImporter.md"); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// <summary> | ||
/// ButtonMethodAttribute, | ||
/// modified from https://github.com/Deadcows/MyBox/blob/master/Attributes/ButtonMethodAttribute.cs | ||
/// </summary> | ||
namespace UnityAddressableImporter.Helper.Internal | ||
{ | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using UnityEditor; | ||
|
||
#if ODIN_INSPECTOR | ||
using Sirenix.OdinInspector; | ||
using Sirenix.OdinInspector.Editor; | ||
#endif | ||
|
||
[CustomEditor(typeof(AddressableImportSettingsList), true), CanEditMultipleObjects] | ||
public class AddressableImportSettingsListEditor : ScriptableObjectEditor<AddressableImportSettingsList> | ||
{ | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.