Example #1
0
        /// <summary>
        /// 裁剪缓存池
        /// </summary>
        /// <param name="deltaTime"></param>
        internal void CullPool(float deltaTime)
        {
            for (int i = m_UsedItemList.Count - 1; i >= 0; i--)
            {
                if (m_UsedItemList[i].TryGetTarget(out GameObject target))
                {
                    if (!UnityObjectExtension.IsNull(target))
                    {
                        continue;
                    }
                }
                m_UsedItemList.RemoveAt(i);
            }

            if (!IsCull)
            {
                return;
            }

            m_CurTime += deltaTime;
            if (m_CurTime - m_PreCullTime < CullDelayTime)
            {
                return;
            }

            int cullAmout = 0;

            if (m_UsedItemList.Count + m_UnusedItemQueue.Count <= LimitMinAmount)
            {
                cullAmout = 0;
            }
            else
            {
                cullAmout = m_UsedItemList.Count + m_UnusedItemQueue.Count - LimitMinAmount;
                if (cullAmout > m_UnusedItemQueue.Count)
                {
                    cullAmout = m_UnusedItemQueue.Count;
                }
            }

            if (CullOnceAmount > 0 && CullOnceAmount < cullAmout)
            {
                cullAmout = CullOnceAmount;
            }

            for (int i = 0; i < cullAmout && m_UnusedItemQueue.Count > 0; i++)
            {
                UnityObject.Destroy(m_UnusedItemQueue.Dequeue());
            }

            m_PreCullTime = m_CurTime;
        }
Example #2
0
        /// <summary>
        /// 回收GameObject,如果此GameObject不带有GameObjectPoolItem组件,则无法回收到池中,将会直接删除
        /// </summary>
        /// <param name="item"></param>
        public void ReleasePoolItem(GameObject item)
        {
            if (item == null)
            {
                DebugUtility.LogError(LOG_TAG, "GameObjectPool::ReleaseItem->Item is Null");
                return;
            }

            GameObjectPoolItem pItem = item.GetComponent <GameObjectPoolItem>();

            if (pItem != null)
            {
                pItem.DoDespawned();
            }

            item.transform.SetParent(m_SpawnPool.CachedTransform, false);
            item.SetActive(false);
            m_UnusedItemQueue.Enqueue(item);

            for (int i = m_UsedItemList.Count - 1; i >= 0; i--)
            {
                if (m_UsedItemList[i].TryGetTarget(out GameObject target))
                {
                    if (!UnityObjectExtension.IsNull(target))
                    {
                        if (target != item)
                        {
                            continue;
                        }
                        else
                        {
                            m_UsedItemList.RemoveAt(i);
                            break;
                        }
                    }
                }

                m_UsedItemList.RemoveAt(i);
            }
        }
        /// <summary>
        /// 绘制AssetNode的详细信息
        /// </summary>
        /// <param name="assetNode">AssetNode数据</param>
        /// <param name="showMainBundle">是否显示其所在的Bundle</param>
        /// <param name="showDependBundle">是否显示依赖的Bundle</param>
        private void DrawAssetNode(AssetNode assetNode, bool showMainBundle = false, bool showDependBundle = false)
        {
            dynamic assetNodeDynamic        = assetNode.AsDynamic();
            string  assetPath               = assetNodeDynamic.m_AssetPath;
            bool    isDone                  = assetNodeDynamic.IsDone;
            bool    isAlive                 = assetNodeDynamic.IsAlive();
            int     loadCount               = assetNodeDynamic.m_LoadCount;
            List <WeakReference> weakAssets = assetNodeDynamic.m_WeakAssets;

            EditorGUIUtil.BeginGUIBackgroundColor(m_NodeBGColor);
            {
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                {
                    EditorGUIUtil.BeginGUIColor(Color.white);
                    {
                        EditorGUIUtil.BeginIndent();
                        {
                            EditorGUILayout.LabelField("Asset Node:");
                            EditorGUIUtil.BeginIndent();
                            {
                                EditorGUILayout.LabelField($"Asset Path:{assetPath}{(isDone?"":"  (Loading)")}");
                                EditorGUILayout.LabelField($"Is Alive:{isAlive}");
                                EditorGUILayout.LabelField($"Load Count:{loadCount}");
                                if (weakAssets.Count > 0)
                                {
                                    EditorGUILayout.LabelField("Weak Ref:");
                                    EditorGUIUtil.BeginIndent();
                                    {
                                        foreach (var weakRef in weakAssets)
                                        {
                                            if (!UnityObjectExtension.IsNull(weakRef.Target))
                                            {
                                                UnityObject uObj = weakRef.Target as UnityObject;
                                                EditorGUILayout.LabelField($"Name:{uObj.name}");
                                            }
                                        }
                                    }
                                    EditorGUIUtil.EndIndent();
                                }
                            }
                            EditorGUIUtil.EndIndent();

                            if (showMainBundle || showDependBundle)
                            {
                                BundleNode mainBundleNode = assetNodeDynamic.m_BundleNode;
                                string     mainBundlePath = mainBundleNode.AsDynamic().m_BundlePath;
                                EditorGUILayout.LabelField("Bundle Node:");
                                EditorGUIUtil.BeginIndent();
                                {
                                    if (showMainBundle)
                                    {
                                        EditorGUILayout.LabelField("Main Bundle:");
                                        EditorGUIUtil.BeginIndent();
                                        {
                                            DrawBundleNode(mainBundleNode);
                                        }
                                        EditorGUIUtil.EndIndent();
                                    }
                                    if (showDependBundle)
                                    {
                                        EditorGUILayout.LabelField("Depend Bundle:");
                                        string[] depends = m_AssetBundleManifest.GetAllDependencies(mainBundlePath);
                                        EditorGUIUtil.BeginIndent();
                                        {
                                            foreach (var depend in depends)
                                            {
                                                BundleNode dependNode = m_BundleNodeDic[depend];
                                                DrawBundleNode(dependNode);
                                                EditorGUILayout.Space();
                                            }
                                        }
                                        EditorGUIUtil.EndIndent();
                                    }
                                }
                                EditorGUIUtil.EndIndent();
                            }
                        }
                        EditorGUIUtil.EndIndent();
                    }
                    EditorGUIUtil.EndGUIColor();
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUIUtil.EndGUIBackgroundColor();
        }