Exemplo n.º 1
0
        private string GetBundleNodeDesc(BundleNode bundleNode, string prefix = "")
        {
            dynamic bundleNodeDynamic = bundleNode.AsDynamic();
            string  bundlePath        = bundleNodeDynamic.m_BundlePath;
            bool    isScene           = bundleNodeDynamic.IsScene();
            int     refCount          = bundleNodeDynamic.m_RefCount;

            return($"{prefix}Bundle Path:{bundlePath}\n{prefix}Ref Count:{refCount}\n{prefix}IsScene:{isScene}");
        }
Exemplo n.º 2
0
        /// <summary>
        /// 绘制BundleNode的详细信息
        /// </summary>
        /// <param name="bundleNode"></param>
        private void DrawBundleNode(BundleNode bundleNode)
        {
            dynamic bundleNodeDynamic = bundleNode.AsDynamic();
            string  bundlePath        = bundleNodeDynamic.m_BundlePath;
            bool    isDone            = bundleNodeDynamic.IsDone;
            int     refCount          = bundleNodeDynamic.m_RefCount;

            EditorGUILayout.LabelField($"Bundle Path:{bundlePath}{(isDone?"":"   (Loading)")}");
            if (isDone)
            {
                bool isScene = bundleNodeDynamic.IsScene;
                EditorGUILayout.LabelField($"IsScene:{isScene}");
            }
            EditorGUILayout.LabelField($"Ref Count:{refCount}");
        }
Exemplo n.º 3
0
        /// <summary>
        /// 导出文本到磁盘中
        /// </summary>
        /// <param name="fileDiskPath"></param>
        /// <param name="isAll"></param>
        private void ExportAssetNodes(string fileDiskPath, bool isAll)
        {
            StringBuilder    sb          = new StringBuilder();
            List <AssetNode> exportNodes = new List <AssetNode>();

            if (isAll)
            {
                exportNodes.AddRange(m_AssetNodeDic.Values.ToArray());
            }
            else
            {
                exportNodes.AddRange(m_AssetNodes);
            }
            foreach (var node in exportNodes)
            {
                dynamic    nodeDynamic    = node.AsDynamic();
                string     assetPath      = nodeDynamic.m_AssetPath;
                BundleNode mainBundleNode = nodeDynamic.m_BundleNode;
                int        loadCount      = nodeDynamic.m_LoadCount;

                sb.AppendLine($"Asset Path:{assetPath}");
                sb.AppendLine($"Load Count:{loadCount}");
                if (m_IsShowAssetNodeMainBundle)
                {
                    sb.AppendLine("Main Bundle:");
                    sb.AppendLine(GetBundleNodeDesc(mainBundleNode, "    "));
                }
                if (m_IsShowAssetNodeDependBundle)
                {
                    string   mainBundlePath = mainBundleNode.AsDynamic().m_BundlePath;
                    string[] depends        = m_AssetBundleManifest.GetAllDependencies(mainBundlePath);
                    sb.AppendLine("Depend Bundle:");
                    foreach (var depend in depends)
                    {
                        BundleNode dependNode = m_BundleNodeDic[depend];
                        sb.AppendLine(GetBundleNodeDesc(dependNode, "    "));
                    }
                }
                sb.AppendLine();
            }
            File.WriteAllText(fileDiskPath, sb.ToString());
        }
Exemplo n.º 4
0
        private void OnGUI()
        {
            if (!InitLoader())
            {
                return;
            }
            if (m_SearchField == null)
            {
                m_SearchField = new SearchField();
                m_SearchField.autoSetFocusOnFindCommand = true;
            }
            EditorGUILayout.BeginHorizontal("toolbar", GUILayout.ExpandWidth(true));
            {
                int selectedIndex = GUILayout.Toolbar(m_ToolbarSelectIndex, m_ToolbarTitle, EditorStyles.toolbarButton, GUILayout.MaxWidth(200));
                if (selectedIndex != m_ToolbarSelectIndex)
                {
                    m_SearchText         = "";
                    m_ToolbarSelectIndex = selectedIndex;
                    m_IsChanged          = true;
                    m_ScrollPos          = Vector2.zero;
                }
                GUILayout.FlexibleSpace();
                //强制进行资源的清理回收
                if (GUILayout.Button("GC", EditorStyles.toolbarButton, GUILayout.Width(40)))
                {
                    m_BundleLoader.UnloadUnusedAssets(null);
                }
                //将当前显示的内容存储到磁盘中
                if (GUILayout.Button("Export", EditorStyles.toolbarButton, GUILayout.Width(60)))
                {
                    ExportToDisk(false);
                }
                //将所在的内容存储到磁盘中
                if (GUILayout.Button("Export All", EditorStyles.toolbarButton, GUILayout.Width(60)))
                {
                    ExportToDisk(true);
                }

                string tempSearchText = m_SearchField.OnToolbarGUI(m_SearchText);
                if (tempSearchText != m_SearchText)
                {
                    m_IsChanged  = true;
                    m_SearchText = tempSearchText;
                }
            }
            EditorGUILayout.EndHorizontal();
            if (m_IsChanged)
            {
                if (m_ToolbarSelectIndex == 0)//显示AssetNode的标签页
                {
                    m_AssetNodes.Clear();
                    foreach (var nodeKVP in m_AssetNodeDic)
                    {
                        AssetNode node = nodeKVP.Value;
                        if (!m_IsShowLoadingAssetNode)
                        {
                            bool isDone = node.AsDynamic().IsDone;
                            if (!isDone)
                            {
                                continue;
                            }
                        }
                        if (string.IsNullOrEmpty(m_SearchText) || nodeKVP.Key.ToLower().Contains(m_SearchText.ToLower()))
                        {
                            m_AssetNodes.Add(node);
                        }
                    }
                    m_AssetNodes.Sort((item1, item2) =>
                    {
                        string path1 = item1.AsDynamic().m_AssetPath;
                        string path2 = item2.AsDynamic().m_AssetPath;
                        return(path1.CompareTo(path2));
                    });
                }
                else if (m_ToolbarSelectIndex == 1)//显示BundleNode的标签页
                {
                    m_BundleNodes.Clear();
                    foreach (var nodeKVP in m_BundleNodeDic)
                    {
                        BundleNode node = nodeKVP.Value;
                        if (!m_IsShowLoadingBundleNode)
                        {
                            bool isDone = node.AsDynamic().IsDone;
                            if (!isDone)
                            {
                                continue;
                            }
                        }
                        if (string.IsNullOrEmpty(m_SearchText) || nodeKVP.Key.ToLower().Contains(m_SearchText.ToLower()))
                        {
                            m_BundleNodes.Add(node);
                        }
                    }
                    m_BundleNodes.Sort((item1, item2) =>
                    {
                        string path1 = item1.AsDynamic().m_BundlePath;
                        string path2 = item2.AsDynamic().m_BundlePath;
                        return(path1.CompareTo(path2));
                    });
                }
            }

            if (m_ToolbarSelectIndex == 0)
            {
                bool isShowLoading = EditorGUILayout.Toggle("Show Loading Node:", m_IsShowLoadingAssetNode);
                if (isShowLoading != m_IsShowLoadingAssetNode)
                {
                    m_IsChanged = true;
                    m_IsShowLoadingAssetNode = isShowLoading;
                }
                m_IsShowAssetNodeMainBundle   = EditorGUILayout.Toggle("Show Main Bundle:", m_IsShowAssetNodeMainBundle);
                m_IsShowAssetNodeDependBundle = EditorGUILayout.Toggle("Show Depend Bundle:", m_IsShowAssetNodeDependBundle);
            }
            else if (m_ToolbarSelectIndex == 1)
            {
                bool isShowLoading = EditorGUILayout.Toggle("Show Loading Node:", m_IsShowLoadingBundleNode);
                if (isShowLoading != m_IsShowLoadingBundleNode)
                {
                    m_IsChanged = true;
                    m_IsShowLoadingBundleNode = isShowLoading;
                }
                m_IsShowBundleNodeDirect = EditorGUILayout.Toggle("Show Depend Bundle:", m_IsShowBundleNodeDirect);
            }

            m_ScrollPos = EditorGUILayout.BeginScrollView(m_ScrollPos, EditorStyles.helpBox);
            {
                if (m_ToolbarSelectIndex == 0)
                {
                    DrawAssetNodes();
                }
                else if (m_ToolbarSelectIndex == 1)
                {
                    DrawBundleNodes();
                }
            }
            EditorGUILayout.EndScrollView();
        }
Exemplo n.º 5
0
        /// <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();
        }