示例#1
0
    private static void GetDependencies(BundleNode main_node, string bundle_name)
    {
        string[] dependency_names = dependence_.GetDirectDependencies(bundle_name);
        for (int i = 0, count = dependency_names.Length; i < count; i++)
        {
            string dependency_name = dependency_names[i];
            if (string.IsNullOrEmpty(dependency_name))
            {
                Debug.LogError(bundle_name + " has empty dependency." + i + " " + count);
                continue;
            }

            BundleNode dependency_node;
            if (bundles_.TryGetValue(dependency_name, out dependency_node) == false)
            {
                dependency_node = new BundleNode(null, dependency_name);
                GetDependencies(dependency_node, dependency_name);

                AssetBundle ab = LoadBundle(dependency_name);
                if (ab != null)
                {
                    dependency_node.bundle_ = ab;
                    //mru_.Add(main_node);
                    bundles_.Add(dependency_name, dependency_node);
                }
            }

            if (dependency_node != null && dependency_node.bundle_ != null)
            {
                main_node.AddDependency(dependency_node);
            }
        }
    }
示例#2
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}");
        }
示例#3
0
        /// <summary>
        /// 绘制当前使用的BundleNode的信息
        /// </summary>
        private void DrawBundleNodes()
        {
            foreach (var node in m_BundleNodes)
            {
                string bundlePath = node.AsDynamic().m_BundlePath;
                if (!m_BundleNodeFoldoutDic.TryGetValue(bundlePath, out bool isFoldout))
                {
                    isFoldout = false;
                    m_BundleNodeFoldoutDic.Add(bundlePath, isFoldout);
                }

                bool isDone = node.AsDynamic().IsDone;
                if (!isDone)
                {
                    bundlePath += "(Loading)";
                }

                m_BundleNodeFoldoutDic[bundlePath] = EditorGUILayout.Foldout(isFoldout, bundlePath);
                if (isFoldout)
                {
                    EditorGUIUtil.BeginGUIBackgroundColor(m_NodeBGColor);
                    {
                        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                        {
                            EditorGUIUtil.BeginIndent();
                            {
                                EditorGUILayout.LabelField("Bundle Node:");
                                EditorGUIUtil.BeginIndent();
                                {
                                    DrawBundleNode(node);
                                }
                                EditorGUIUtil.EndIndent();

                                if (m_IsShowBundleNodeDirect)
                                {
                                    EditorGUILayout.LabelField("Direct Bundle:");
                                    string[] depends = m_AssetBundleManifest.GetDirectDependencies(bundlePath);
                                    EditorGUIUtil.BeginIndent();
                                    {
                                        foreach (var depend in depends)
                                        {
                                            BundleNode dependNode = m_BundleNodeDic[depend];
                                            DrawBundleNode(dependNode);
                                            EditorGUILayout.Space();
                                        }
                                    }
                                    EditorGUIUtil.EndIndent();
                                }
                            }
                            EditorGUIUtil.EndIndent();
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUIUtil.EndGUIBackgroundColor();
                }
            }
        }
示例#4
0
    public static BundleNode AddBundleNode(AssetBundle ab, string name, bool unloadable = true)
    {
        BundleNode node = new BundleNode(ab, name);

        node.unloadable_ = unloadable;
        bundles_.Add(name, node);

        return(node);
    }
示例#5
0
 public static bool CheckBundle(string name)
 {
     if (bundles_.ContainsKey(name))
     {
         BundleNode node = bundles_[name];
         return(true);
     }
     return(false);
 }
示例#6
0
        public void Dispose()
        {
            if (bundle_ != null)
            {
                bundle_.UnloadAsset(name_);
                bundle_ = null;
            }

            assets_.Remove(name_);
            asset_ = null;
        }
示例#7
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}");
        }
示例#8
0
    private static void AddAsset(string name, BundleNode bundle, Object asset)
    {
        AssetNode asset_node;

        if (assets_.TryGetValue(name, out asset_node) == true)
        {
            asset_node.Asset = asset;
        }
        else
        {
            asset_node = new AssetNode(name, bundle, asset);
            assets_.Add(name, asset_node);
            bundle.loadedAsset_count_++;
        }
    }
示例#9
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());
        }
示例#10
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();
        }
示例#11
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();
        }
示例#12
0
 public void AddDependency(BundleNode dependency)
 {
     dependency.Retain();
     dependencies_.Add(dependency);
 }
示例#13
0
    // Load asset bundle or Resources.Load
    // auto_unload: load the asset and release the bundles
    public static Object Load(string name)
    {
#if ASSETBUNDLE
        if (dependence_ == null)
        {
#if DEBUG
            Debug.Log("ResLoader is not initialized. Please Call its Init method first.");
#endif
            return(null);
        }

        name = name.ToLower();
        if (string.IsNullOrEmpty(name))
        {
            Debug.LogError("name is empty");
            return(null);
        }

        Object asset = GetAsset(name);
        if (asset != null)
        {
            return(asset);
        }
        else
        {
            string bundle_name = name;
            string asset_name  = string.Empty;

            AssetNameNode asset_name_node;
            if (asset_dependence_.TryGetValue(bundle_name, out asset_name_node))
            {
                bundle_name = asset_name_node.bundle_name_;
                asset_name  = asset_name_node.name_;
            }

            BundleNode main_node  = null;
            Object     asset_main = null;

            if (bundles_.TryGetValue(bundle_name, out main_node))
            {
                asset_main = main_node.LoadAsset(asset_name);
            }
            else
            {
                // load bundles
                main_node = new BundleNode(null, bundle_name);

                //Load dependencies.
                GetDependencies(main_node, bundle_name);

                AssetBundle ab_main = LoadBundle(bundle_name);
                if (ab_main != null)
                {
                    main_node.bundle_ = ab_main;
                    //mru_.Add(main_node);
                    bundles_.Add(bundle_name, main_node);

                    asset_main = main_node.LoadAsset(asset_name);
                }
            }

            if (asset_main != null)
            {
                AddAsset(name, main_node, asset_main);
            }

            return(asset_main);
        }
#else
#if DEBUG
        System.Diagnostics.Stopwatch st = new System.Diagnostics.Stopwatch();
        st.Start();
        Object obj = Resources.Load(name);
        st.Stop();

        if (obj == null)
        {
            Debug.LogError(name);
        }

        return(obj);
#else
        return(Resources.Load(name));
#endif
#endif
    }
示例#14
0
 public AssetNode(string name, BundleNode bundle, Object asset)
 {
     name_   = name;
     bundle_ = bundle;
     asset_  = new System.WeakReference(asset);
 }