public GameObjectResource get() { if (idle.Count <= 0) { GameObject g = gameObjectFactory.CreateGameObject(); add(g); } GameObjectResource r = idle.First().Value; r.getGameObject().SetActive(true); used.Add(r.getId(), r); idle.Remove(r.getId()); return(r); }
public void release(GameObjectResource r) { if (r.getPool() != this) { Debug.LogError("gameObjectPool must release gameObjectResource belong to it"); return; } if (!used.ContainsKey(r.getId())) { return; } r.getGameObject().SetActive(false); used.Remove(r.getId()); idle.Add(r.getId(), r); }
public IEnumerator getAsync(LoaderResult result) { result.isDone = false; result.asset = null; if (idle.Count <= 0) { LoaderResult r = new LoaderResult(); yield return(gameObjectFactory.CreateGameObjectAsync(r)); add(r.asset as GameObject); } GameObjectResource res = idle.First().Value; res.getGameObject().SetActive(true); used.Add(res.getId(), res); idle.Remove(res.getId()); result.asset = res; result.isDone = true; }
private void add(GameObject gameObject) { if (fatherTransform) { gameObject.transform.parent = fatherTransform; } idCounter += 1; GameObjectResource r = new GameObjectResource(idCounter, gameObject, this); idle.Add(r.getId(), r); }