Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Assets/UnityScreenNavigator/Runtime/Core/Modal/ModalContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ namespace UnityScreenNavigator.Runtime.Core.Modal
[RequireComponent(typeof(RectMask2D))]
public sealed class ModalContainer : MonoBehaviour, IScreenContainer
{
#if UNITY_6000_5_OR_NEWER
private static readonly Dictionary<EntityId, ModalContainer> InstanceCacheByTransform = new();
#else
private static readonly Dictionary<int, ModalContainer> InstanceCacheByTransform = new();
#endif

private static readonly Dictionary<string, ModalContainer> InstanceCacheByName = new();

Expand Down Expand Up @@ -101,7 +105,11 @@ private void OnDestroy()
_orderedModalIds.Clear();

InstanceCacheByName.Remove(_name);
#if UNITY_6000_5_OR_NEWER
var keysToRemove = new List<EntityId>();
#else
var keysToRemove = new List<int>();
#endif
foreach (var cache in InstanceCacheByTransform)
if (Equals(cache.Value))
keysToRemove.Add(cache.Key);
Expand Down Expand Up @@ -141,7 +149,11 @@ public static ModalContainer Of(Transform transform, bool useCache = true)
/// <returns></returns>
public static ModalContainer 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;

container = rectTransform.GetComponentInParent<ModalContainer>();
Expand Down Expand Up @@ -462,4 +474,4 @@ Action<Modal, AssetLoadHandle<GameObject>> onLoaded
onLoaded?.Invoke(modal, assetLoadHandle);
}
}
}
}
14 changes: 13 additions & 1 deletion Assets/UnityScreenNavigator/Runtime/Core/Page/PageContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ namespace UnityScreenNavigator.Runtime.Core.Page
[RequireComponent(typeof(RectMask2D))]
public sealed class PageContainer : MonoBehaviour, IScreenContainer
{
#if UNITY_6000_5_OR_NEWER
private static readonly Dictionary<EntityId, PageContainer> InstanceCacheByTransform = new();
#else
private static readonly Dictionary<int, PageContainer> InstanceCacheByTransform = new();
#endif

private static readonly Dictionary<string, PageContainer> InstanceCacheByName = new();

Expand Down Expand Up @@ -90,7 +94,11 @@ private void OnDestroy()
_orderedPageIds.Clear();

InstanceCacheByName.Remove(_name);
#if UNITY_6000_5_OR_NEWER
var keysToRemove = new List<EntityId>();
#else
var keysToRemove = new List<int>();
#endif
foreach (var cache in InstanceCacheByTransform)
if (Equals(cache.Value))
keysToRemove.Add(cache.Key);
Expand Down Expand Up @@ -130,7 +138,11 @@ public static PageContainer Of(Transform transform, bool useCache = true)
/// <returns></returns>
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;

container = rectTransform.GetComponentInParent<PageContainer>();
Expand Down Expand Up @@ -483,4 +495,4 @@ Action<Page, AssetLoadHandle<GameObject>> onLoaded
onLoaded?.Invoke(page, assetLoadHandle);
}
}
}
}
13 changes: 13 additions & 0 deletions Assets/UnityScreenNavigator/Runtime/Core/Sheet/SheetContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ namespace UnityScreenNavigator.Runtime.Core.Sheet
[RequireComponent(typeof(RectMask2D))]
public sealed class SheetContainer : MonoBehaviour, IScreenContainer
{
#if UNITY_6000_5_OR_NEWER
private static readonly Dictionary<EntityId, SheetContainer> InstanceCacheByTransform =
new Dictionary<EntityId, SheetContainer>();
#else
private static readonly Dictionary<int, SheetContainer> InstanceCacheByTransform =
new Dictionary<int, SheetContainer>();
#endif

private static readonly Dictionary<string, SheetContainer> InstanceCacheByName =
new Dictionary<string, SheetContainer>();
Expand Down Expand Up @@ -94,7 +99,11 @@ private void OnDestroy()
UnregisterAll();

InstanceCacheByName.Remove(_name);
#if UNITY_6000_5_OR_NEWER
var keysToRemove = new List<EntityId>();
#else
var keysToRemove = new List<int>();
#endif
foreach (var cache in InstanceCacheByTransform)
if (Equals(cache.Value))
keysToRemove.Add(cache.Key);
Expand Down Expand Up @@ -123,7 +132,11 @@ public static SheetContainer Of(Transform transform, bool useCache = true)
/// <returns></returns>
public static SheetContainer Of(RectTransform rectTransform, bool useCache = true)
{
#if UNITY_6000_5_OR_NEWER
var hashCode = rectTransform.GetEntityId();
#else
var hashCode = rectTransform.GetInstanceID();
#endif

if (useCache && InstanceCacheByTransform.TryGetValue(hashCode, out var container)) return container;

Expand Down