diff --git a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugPageBase.cs b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugPageBase.cs index 89b870b..f506e9e 100644 --- a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugPageBase.cs +++ b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugPageBase.cs @@ -4,6 +4,11 @@ using UnityDebugSheet.Runtime.Foundation.PageNavigator.Modules; using UnityDebugSheet.Runtime.Foundation.TinyRecyclerView; using UnityEngine; +#if UNITY_6000_5_OR_NEWER +using ObjectId = UnityEngine.EntityId; +#else +using ObjectId = System.Int32; +#endif namespace UnityDebugSheet.Runtime.Core.Scripts { @@ -12,7 +17,7 @@ public abstract class DebugPageBase : Page, IRecyclerViewCellProvider, IRecycler private readonly PriorityList _itemIds = new PriorityList(); private readonly Dictionary _itemIdToDataIndexMap = new Dictionary(); private readonly List _itemInfos = new List(); - private readonly Dictionary _objIdToPrefabKeyMap = new Dictionary(); + private readonly Dictionary _objIdToPrefabKeyMap = new Dictionary(); private readonly Dictionary> _prefabPools = new Dictionary>(); @@ -73,6 +78,15 @@ protected virtual void OnDestroy() pool.Clear(); } + private static ObjectId GetObjectId(Object obj) + { +#if UNITY_6000_5_OR_NEWER + return obj.GetEntityId(); +#else + return obj.GetInstanceID(); +#endif + } + GameObject IRecyclerViewCellProvider.GetCell(int dataIndex) { var prefabKey = _itemInfos[dataIndex].PrefabKey; @@ -87,14 +101,14 @@ GameObject IRecyclerViewCellProvider.GetCell(int dataIndex) } var obj = pool.Use(); - _objIdToPrefabKeyMap[obj.GetInstanceID()] = prefabKey; + _objIdToPrefabKeyMap[GetObjectId(obj)] = prefabKey; obj.SetActive(true); return obj; } void IRecyclerViewCellProvider.ReleaseCell(GameObject obj) { - var prefabKey = _objIdToPrefabKeyMap[obj.GetInstanceID()]; + var prefabKey = _objIdToPrefabKeyMap[GetObjectId(obj)]; var pool = _prefabPools[prefabKey]; pool.Release(obj); obj.SetActive(false); diff --git a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs index a2d2f69..980c960 100644 --- a/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs +++ b/Assets/UnityDebugSheet/Runtime/Core/Scripts/DebugSheet.cs @@ -9,6 +9,11 @@ using UnityEngine; using UnityEngine.Serialization; using UnityEngine.UI; +#if UNITY_6000_5_OR_NEWER +using ObjectId = UnityEngine.EntityId; +#else +using ObjectId = System.Int32; +#endif namespace UnityDebugSheet.Runtime.Core.Scripts { @@ -17,8 +22,8 @@ public sealed class DebugSheet : MonoBehaviour, IPageContainerCallbackReceiver { private const float ThresholdInch = 0.24f; - private static readonly Dictionary InstanceCacheByTransform = - new Dictionary(); + private static readonly Dictionary InstanceCacheByTransform = + new Dictionary(); [SerializeField] private bool _singleton = true; @@ -197,7 +202,11 @@ public static DebugSheet Of(Transform transform, bool useCache = true) /// public static DebugSheet Of(RectTransform rectTransform, bool useCache = true) { +#if UNITY_6000_5_OR_NEWER + var id = rectTransform.GetEntityId(); +#else var id = rectTransform.GetInstanceID(); +#endif if (useCache && InstanceCacheByTransform.TryGetValue(id, out var container)) return container; diff --git a/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs b/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs index ce80be1..6b96517 100644 --- a/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs +++ b/Assets/UnityDebugSheet/Runtime/Foundation/PageNavigator/PageContainer.cs @@ -6,6 +6,11 @@ using UnityEngine; using UnityEngine.Assertions; using UnityEngine.UI; +#if UNITY_6000_5_OR_NEWER +using ObjectId = UnityEngine.EntityId; +#else +using ObjectId = System.Int32; +#endif namespace UnityDebugSheet.Runtime.Foundation.PageNavigator { @@ -13,8 +18,8 @@ namespace UnityDebugSheet.Runtime.Foundation.PageNavigator [RequireComponent(typeof(RectMask2D))] public sealed class PageContainer : MonoBehaviour { - private static readonly Dictionary InstanceCacheByTransform = - new Dictionary(); + private static readonly Dictionary InstanceCacheByTransform = + new Dictionary(); private static readonly Dictionary InstanceCacheByName = new Dictionary(); @@ -99,7 +104,7 @@ private void OnDestroy() _orderedPageIds.Clear(); InstanceCacheByName.Remove(_name); - var keysToRemove = new List(); + var keysToRemove = new List(); foreach (var cache in InstanceCacheByTransform) if (Equals(cache.Value)) keysToRemove.Add(cache.Key); @@ -127,7 +132,11 @@ public static PageContainer Of(Transform transform, bool useCache = true) /// public static PageContainer Of(RectTransform rectTransform, bool useCache = true) { +#if UNITY_6000_5_OR_NEWER + var id = rectTransform.GetEntityId(); +#else var id = rectTransform.GetInstanceID(); +#endif if (useCache && InstanceCacheByTransform.TryGetValue(id, out var container)) return container;