コード例 #1
0
        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);
                }
            });
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public PoolItem(string prefabPath, DialogViewBase view)
 {
     this.prefabPath = prefabPath;
     this.view       = view;
 }