diff --git a/Runtime/AddresssablesExtensions/LifetimeManagement.cs b/Runtime/AddresssablesExtensions/LifetimeManagement.cs index 32171d4..c6dfbca 100644 --- a/Runtime/AddresssablesExtensions/LifetimeManagement.cs +++ b/Runtime/AddresssablesExtensions/LifetimeManagement.cs @@ -61,7 +61,7 @@ private static ReleaseHandleOnDestroy AddAutoReleaseTrigger(AsyncOperationHandle { _ = targetGO ?? throw new ArgumentNullException(nameof(targetGO)); - var trigger = targetGO.AddComponent(); + var trigger = targetGO.GetComponent() ?? targetGO.AddComponent(); trigger.OnDestroyEvent += () => Addressables.Release(operationHandle); diff --git a/Runtime/ManageAddressables.BaseMethods.cs b/Runtime/ManageAddressables.BaseMethods.cs index 76cff4b..51fbea1 100644 --- a/Runtime/ManageAddressables.BaseMethods.cs +++ b/Runtime/ManageAddressables.BaseMethods.cs @@ -236,7 +236,7 @@ public static void Instantiate(AssetReference reference, /// The object to which the trigger will be attached. public static void AddAutoReleaseAssetTrigger(string key, GameObject targetGO) { - targetGO.AddComponent().OnDestroyEvent += + (targetGO.GetComponent() ?? targetGO.AddComponent()).OnDestroyEvent += () => ReleaseAsset(key); } @@ -248,7 +248,7 @@ public static void AddAutoReleaseAssetTrigger(string key, GameObject targetGO) /// The object to which the trigger will be attached. public static void AddAutoReleaseAssetTrigger(AssetReference assetReference, GameObject targetGO) { - targetGO.AddComponent().OnDestroyEvent += + (targetGO.GetComponent() ?? targetGO.AddComponent()).OnDestroyEvent += () => ReleaseAsset(assetReference); } @@ -261,7 +261,7 @@ public static void AddAutoReleaseAssetTrigger(AssetReference assetReference, Gam /// The object to which the trigger will be attached. public static void AddAutoReleaseInstanceTrigger(string key, GameObject targetGO) { - targetGO.AddComponent().OnDestroyEvent += + (targetGO.GetComponent() ?? targetGO.AddComponent()).OnDestroyEvent += () => ReleaseInstance(key, targetGO); } @@ -274,7 +274,7 @@ public static void AddAutoReleaseInstanceTrigger(string key, GameObject targetGO /// The object to which the trigger will be attached. public static void AddAutoReleaseInstanceTrigger(AssetReference assetReference, GameObject targetGO) { - targetGO.AddComponent().OnDestroyEvent += + (targetGO.GetComponent() ?? targetGO.AddComponent()).OnDestroyEvent += () => ReleaseInstance(assetReference, targetGO); } } diff --git a/Runtime/ManageAddressables.cs b/Runtime/ManageAddressables.cs index f87ab06..55ede56 100644 --- a/Runtime/ManageAddressables.cs +++ b/Runtime/ManageAddressables.cs @@ -302,7 +302,7 @@ private static void ReleaseInstanceInternal(string key, GameObject instance) return; } - var index = instanceList.FindIndex(x => x.GetInstanceID() == instance.GetInstanceID()); + var index = instanceList.FindIndex(x => x == instance); if (index < 0) { diff --git a/Runtime/ReleaseHandleOnDestroy.cs b/Runtime/ReleaseHandleOnDestroy.cs index f005abf..5d4e7f8 100644 --- a/Runtime/ReleaseHandleOnDestroy.cs +++ b/Runtime/ReleaseHandleOnDestroy.cs @@ -3,6 +3,7 @@ namespace AddressablesMaster { + [DisallowMultipleComponent] public class ReleaseHandleOnDestroy : MonoBehaviour { public void OnDestroy() diff --git a/package.json b/package.json index 1e506a6..3d35cfd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.inc8877.addressables-master", - "version": "1.0.2", + "version": "1.0.3", "displayName": "AddressablesMaster", "description": "Use Sync, Async(.NET / UniTask), Coroutine, Lifetime management tools for addressables assets with caching support", "homepage": "https://github.com/inc8877/AddressablesMaster#readme", @@ -18,7 +18,7 @@ "url": "https://github.com/inc8877/AddressablesMaster.git" }, "dependencies": { - "com.unity.addressables": "1.6.0" + "com.unity.addressables": "2.9.1" }, "author": { "name": "Volodymyr Bozhko",