public void CreateDialog(string prefabPath, System.Action <DialogViewBase> callback, Transform parent = null) { if (parent == null) { parent = UIRoot.Instance.MainCanvas.transform; } DialogViewBase dialogViewBase = UIRoot.Instance.DialogViewPool.TryGetDialogViewFromPool(prefabPath, parent); if (dialogViewBase != null) { callback(dialogViewBase); return; } PrefabLoader.Instance.InstantiateAsynchronous(prefabPath, parent, (loadedGO) => { dialogViewBase = loadedGO.GetComponent <DialogViewBase>(); if (dialogViewBase != null) { dialogViewBase.Init(prefabPath); callback(dialogViewBase); } else { DebugLog.LogWarningColor("Prefab at " + prefabPath + " is not a dialog", LogColor.orange); } }); }
public void AddDialogViewToPool(string prefabPath, DialogViewBase view) { if (this.GetMaxPrefabsInPool == 0) { GameObject.Destroy(view.gameObject); return; } if (this._pool.Count >= this.GetMaxPrefabsInPool) { // Remove the item at the beginning of the pool PoolItem poolItem = this._pool[0]; this._pool.RemoveAt(0); GameObject.Destroy(poolItem.view.gameObject); } view.gameObject.SetActive(false); view.transform.SetParent(this.transform); this._pool.Add(new PoolItem(prefabPath, view)); }
public DialogViewBase TryGetDialogViewFromPool(string prefabPath, Transform parent) { int index = 0; var enumerator = this._pool.GetEnumerator(); while (enumerator.MoveNext()) { PoolItem poolItem = enumerator.Current; if (poolItem.prefabPath == prefabPath) { this._pool.RemoveAt(index); DialogViewBase view = poolItem.view; view.gameObject.SetActive(true); view.transform.SetParent(parent); return(view); } ++index; } return(null); }
public PoolItem(string prefabPath, DialogViewBase view) { this.prefabPath = prefabPath; this.view = view; }