adjust how syncable cache works

This commit is contained in:
2025-03-24 17:34:48 +02:00
parent 8edfcff56f
commit f5ad619ed5
2 changed files with 6 additions and 6 deletions

View File

@@ -61,9 +61,9 @@ namespace BoneSync.Sync.Components
{
public const int OBJECT_SYNC_FPS = 20;
public static Dictionary<GameObject, Syncable> syncablesCache = new Dictionary<GameObject, Syncable>();
public static Dictionary<int, Syncable> syncablesCache = new Dictionary<int, Syncable>();
public Syncable(IntPtr intPtr) : base(intPtr) {
syncablesCache[gameObject] = this;
syncablesCache[gameObject.GetHashCode()] = this;
}
private bool _syncCoroutineRunning;
@@ -166,7 +166,7 @@ namespace BoneSync.Sync.Components
public void OnEnable()
{
syncablesCache[gameObject] = this;
syncablesCache[gameObject.GetHashCode()] = this;
FindAndUpdateComponents();
@@ -321,7 +321,7 @@ namespace BoneSync.Sync.Components
}
if (gameObject) syncablesCache.Remove(gameObject);
if (gameObject) syncablesCache.Remove(gameObject.GetHashCode());
ObjectSyncCache.RemoveSyncable(this);

View File

@@ -154,7 +154,7 @@ namespace BoneSync.Sync
private static Syncable _GetSyncableFromCache(GameObject gameObject)
{
bool success = Syncable.syncablesCache.TryGetValue(gameObject, out Syncable syncable);
bool success = Syncable.syncablesCache.TryGetValue(gameObject.GetHashCode(), out Syncable syncable);
if (!success)
{
return null;
@@ -173,7 +173,7 @@ namespace BoneSync.Sync
}
public static Syncable MakeOrGetSyncable(GameObject gameObject)
{
Syncable syncable = _GetSyncableFromCache(gameObject); // buttons must never be a sub syncable
Syncable syncable = _GetSyncableFromCache(gameObject);
if (syncable == null)
{
syncable = _MakeOrGetSyncable(gameObject);