public static void RegisterPrefab(HybridPrefab prefab) { if (prefab == null) { Debug.LogError("Cannot register null prefab"); return; } if (_prefabLookup.ContainsKey(prefab.Id)) { var registered = _prefabLookup[prefab.Id]; if (registered == prefab) { Debug.LogWarning($"{prefab.Id}:{prefab.name} dual registration ignored", prefab); } else { Debug.LogError("HybridPrefab.Id collision!"); Debug.LogError($"{registered.name} - registered", registered); Debug.LogError($"{prefab.name} - conflict", prefab); } return; } _prefabLookup.Add(prefab.Id, prefab); // pre-allocate pool var pool = new Queue <HybridPrefab>(prefab.PrePoolSize); _poolLookup.Add(prefab.Id, pool); for (int i = 0; i < prefab.PrePoolSize; i++) { var instance = Object.Instantiate(prefab); #if UNITY_EDITOR instance.gameObject.hideFlags = HideFlags.HideInHierarchy; #endif instance.gameObject.SetActive(false); pool.Enqueue(instance); } }
public static bool TryGetActiveInstance(int instanceId, out HybridPrefab instance) { return(_activeInstanceLookup.TryGetValue(instanceId, out instance)); }