//设置Bundle是否多资源封包
        public bool SetAssetBundlePacked(string assetBundleName, string assetBundleVariant, bool assetBundlePacked)
        {
            if (!IsValidAssetBundleName(assetBundleName, assetBundleVariant))
            {
                return(false);
            }

            AssetBundleInfo assetBundle = GetAssetBundleInfo(assetBundleName, assetBundleVariant);

            if (assetBundle == null)
            {
                return(false);
            }

            assetBundle.SetPacked(assetBundlePacked);

            return(true);
        }
        //设置Bundle资源的加载模式
        public bool SetAssetBundleLoadType(string assetBundleName, string assetBundleVariant, AssetBundleLoadType assetBundleLoadType)
        {
            if (!IsValidAssetBundleName(assetBundleName, assetBundleVariant))
            {
                return(false);
            }

            AssetBundleInfo assetBundle = GetAssetBundleInfo(assetBundleName, assetBundleVariant);  //获取Bundle信息

            if (assetBundle == null)
            {
                return(false);
            }

            assetBundle.SetLoadType(assetBundleLoadType);   //修改加载模式

            return(true);
        }
        //移除Bundle信息
        public bool RemoveAssetBundle(string assetBundleName, string assetBundleVariant)
        {
            if (!IsValidAssetBundleName(assetBundleName, assetBundleVariant))
            {
                return(false);
            }

            AssetBundleInfo assetBundle = GetAssetBundleInfo(assetBundleName, assetBundleVariant);  //获取Bundle信息

            if (assetBundle == null)
            {
                return(false);
            }

            AssetInfo[] assets = assetBundle.AssetInfos;           //BundleInfo关联的资源信息
            assetBundle.Clear();                                   //清空BundleInfo中的数据
            m_AssetBundles.Remove(assetBundle.FullName.ToLower()); //从列表中移除
            foreach (AssetInfo asset in assets)
            {
                m_Assets.Remove(asset.Guid);    //收集器中移除这些资源信息
            }

            return(true);
        }
Beispiel #4
0
        //绘制资源文件夹菜单按钮
        private void DrawSourceAssetsMenu()
        {
            HashSet <SourceAsset> selectedSourceAssets = GetSelectedSourceAssets();

            EditorGUI.BeginDisabledGroup(m_SelectedAssetBundleInfo == null || selectedSourceAssets.Count <= 0);
            {
                if (GUILayout.Button(Utility.Text.Format("<< {0}", selectedSourceAssets.Count.ToString()), GUILayout.Width(80f)))
                {
                    foreach (SourceAsset sourceAsset in selectedSourceAssets)
                    {
                        AssignAsset(sourceAsset, m_SelectedAssetBundleInfo);    //分配资源
                    }

                    m_SelectedSourceAssets.Clear();
                    m_CachedSelectedSourceFolders.Clear();
                }
            }
            EditorGUI.EndDisabledGroup();
            EditorGUI.BeginDisabledGroup(selectedSourceAssets.Count <= 0);
            {
                if (GUILayout.Button(Utility.Text.Format("<<< {0}", selectedSourceAssets.Count.ToString()), GUILayout.Width(80f)))
                {
                    int index = 0;
                    int count = selectedSourceAssets.Count;
                    foreach (SourceAsset sourceAsset in selectedSourceAssets)
                    {
                        EditorUtility.DisplayProgressBar("Add AssetBundles", Utility.Text.Format("{0}/{1} processing...", (++index).ToString(), count.ToString()), (float)index / count);
                        int    dotIndex        = sourceAsset.FromRootPath.IndexOf('.');
                        string assetBundleName = dotIndex > 0 ? sourceAsset.FromRootPath.Substring(0, dotIndex) : sourceAsset.FromRootPath;
                        AddAssetBundleInfo(assetBundleName, null, false);   //每一个资源都添加一个Bundle
                        AssetBundleInfo assetBundle = m_Controller.GetAssetBundleInfo(assetBundleName, null);
                        if (assetBundle == null)
                        {
                            continue;
                        }

                        AssignAsset(sourceAsset, assetBundle);  //分配资源到指定Bundle中
                    }

                    EditorUtility.DisplayProgressBar("Add AssetBundles", "Complete processing...", 1f);
                    RefreshAssetBundleTree();              //刷新树状列表
                    EditorUtility.ClearProgressBar();
                    m_SelectedSourceAssets.Clear();        //清空选中资源
                    m_CachedSelectedSourceFolders.Clear(); //清空选中资源文件夹
                }
            }
            EditorGUI.EndDisabledGroup();
            bool hideAssignedSourceAssets = EditorGUILayout.ToggleLeft("Hide Assigned", m_HideAssignedSourceAssets, GUILayout.Width(100f));

            if (hideAssignedSourceAssets != m_HideAssignedSourceAssets)
            {
                m_HideAssignedSourceAssets = hideAssignedSourceAssets;
                m_CachedSelectedSourceFolders.Clear();
                m_CachedUnselectedSourceFolders.Clear();
                m_CachedAssignedSourceFolders.Clear();
                m_CachedUnassignedSourceFolders.Clear();
            }

            GUILayout.Label(string.Empty);
            //清理无效资源和资源包
            if (GUILayout.Button("Clean", GUILayout.Width(80f)))
            {
                EditorUtility.DisplayProgressBar("Clean", "Processing...", 0f);
                CleanAssetBundle();
                EditorUtility.ClearProgressBar();
            }

            //保存
            if (GUILayout.Button("Save", GUILayout.Width(80f)))
            {
                EditorUtility.DisplayProgressBar("Save", "Processing...", 0f);
                SaveConfiguration();
                EditorUtility.ClearProgressBar();
            }
        }
Beispiel #5
0
 private int DependencyAssetBundlesComparer(AssetBundleInfo a, AssetBundleInfo b)
 {
     return(a.FullName.CompareTo(b.FullName));
 }
        //检查Bundle是否一致
        private bool IsAvailableBundleName(string assetBundleName, string assetBundleVariant, AssetBundleInfo selfAssetBundle)
        {
            AssetBundleInfo findAssetBundle = GetAssetBundleInfo(assetBundleName, assetBundleVariant);

            if (findAssetBundle != null)
            {
                return(findAssetBundle == selfAssetBundle);
            }

            foreach (AssetBundleInfo assetBundle in m_AssetBundles.Values)
            {
                if (selfAssetBundle != null && assetBundle == selfAssetBundle)  //排除自身,因为自身的名称肯定等于自身的
                {
                    continue;
                }

                if (assetBundle.Name == assetBundleName)    //Bundle名一致
                {
                    if (assetBundle.Variant == null && assetBundleVariant != null)
                    {
                        return(false);
                    }

                    if (assetBundle.Variant != null && assetBundleVariant == null)
                    {
                        return(false);
                    }
                }

                if (assetBundle.Name.Length > assetBundleName.Length &&
                    assetBundle.Name.IndexOf(assetBundleName, StringComparison.CurrentCultureIgnoreCase) == 0 &&
                    assetBundle.Name[assetBundleName.Length] == '/')
                {
                    return(false);
                }

                if (assetBundleName.Length > assetBundle.Name.Length &&
                    assetBundleName.IndexOf(assetBundle.Name, StringComparison.CurrentCultureIgnoreCase) == 0 &&
                    assetBundleName[assetBundle.Name.Length] == '/')
                {
                    return(false);
                }
            }

            return(true);
        }
 public static AssetInfo Create(string guid, AssetBundleInfo assetBundleInfo)
 {
     return(new AssetInfo(guid, assetBundleInfo));
 }
 public void SetAssetBundle(AssetBundleInfo assetBundleInfo)
 {
     AssetBundleInfo = assetBundleInfo;
 }
 private AssetInfo(string guid, AssetBundleInfo assetBundleInfo)
 {
     Guid            = guid;
     AssetBundleInfo = assetBundleInfo;
 }