fix the issue to load addressable on Editor
This commit is contained in:
@@ -210,6 +210,9 @@ namespace BrewMonster.Scripts
|
||||
if (handle.OperationException != null)
|
||||
{
|
||||
BMLogger.Log($"AddressableManager: Failed to load Prefab '{assetPath}': {handle.OperationException.Message} {handle.OperationException.StackTrace}");
|
||||
#if UNITY_EDITOR
|
||||
_invalidAssetPaths.Add(assetPath);
|
||||
#endif
|
||||
return null;
|
||||
}
|
||||
_loadedPrefabAssets[assetPath] = handle;
|
||||
@@ -218,6 +221,9 @@ namespace BrewMonster.Scripts
|
||||
catch (System.Exception e)
|
||||
{
|
||||
BMLogger.Log($"AddressableManager: Failed to load Prefab '{assetPath}': {e.Message} {e.StackTrace}");
|
||||
#if UNITY_EDITOR
|
||||
_invalidAssetPaths.Add(assetPath);
|
||||
#endif
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -367,6 +373,10 @@ namespace BrewMonster.Scripts
|
||||
return _loadedPrefabAssets.ContainsKey(assetPath) && _loadedPrefabAssets[assetPath].IsValid();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private HashSet<string> _invalidAssetPaths = new();
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given Addressable key or path exists in the current catalogs.
|
||||
/// </summary>
|
||||
@@ -375,6 +385,9 @@ namespace BrewMonster.Scripts
|
||||
/// <returns>True if the key exists, false otherwise.</returns>
|
||||
public static bool KeyExists(object key, System.Type type = null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
return !Instance._invalidAssetPaths.Contains(key.ToString());
|
||||
#else
|
||||
// Iterate through all loaded locators (catalogs)
|
||||
foreach (IResourceLocator locator in Addressables.ResourceLocators)
|
||||
{
|
||||
@@ -390,6 +403,7 @@ namespace BrewMonster.Scripts
|
||||
}
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user