private void OnEnable() { if (!_database) { _database = target as GameObjectPoolDefinitionDatabase; } }
public static void UnloadDatabase(GameObjectPoolDefinitionDatabase database) { if (!database) { return; } if (!_loadedDatabases.Contains(database)) { return; } foreach (var def in database.ObjectPoolDefinitions) { var id = def.Id; GameObjectPool pool; if (!ActiveObjectPools.TryGetValue(id, out pool)) { // No pool for this object exists to unload. continue; } ActiveObjectPools[id] = pool.ModifyMaxCount(-def.Count); if (pool.MaxCount <= 0) { if (pool.MaxCount < 0) { Debug.LogErrorFormat("[ObjectPoolManager] Max pool count for object \'{0}\' was less than zero after unloading database \'{1}\'", pool, database); } // Pool count equals zero...proceed to unload the pool. } else if (pool.MaxCount == pool.OverflowCount) { // Only overflow remain...proceed to unload the pool. } else { continue; } _unloadingObjectPools.Add(pool); ActiveObjectPools.Remove(id); } _loadedDatabases.Remove(database); }
public static void LoadDatabase(GameObjectPoolDefinitionDatabase database) { if (!database) { return; } if (_loadedDatabases.Contains(database)) { return; } _loadedDatabases.Add(database); foreach (var def in database.ObjectPoolDefinitions) { var id = def.Id; GameObjectPool duplicate; if (ActiveObjectPools.TryGetValue(id, out duplicate)) { ActiveObjectPools[id] = duplicate.ModifyMaxCount(def.Count); continue; } var p = new GameObjectPool(def); ActiveObjectPools.Add(id, p); } }
public static bool IsLoaded(GameObjectPoolDefinitionDatabase database) { return(_loadedDatabases.Contains(database)); }