Exemplo n.º 1
0
        public static void Build()
        {
            mAssetFilters.Clear();
            mABPathFilters.Clear();
            mAllFolderABDic.Clear();
            mAllSingleAssetABDic.Clear();
            mAllFileABNameDic.Clear();
            abNameConfig = AssetDatabase.LoadAssetAtPath <ABNameConfig>(mABNameConfigPath);
            //------文件夹ab字典添加
            foreach (var folderAB in abNameConfig.AllFolderAB)
            {
                if (mAllFolderABDic.ContainsKey(folderAB.ABName))
                {
                    Debug.LogError("AB包配置名字重复,请检查!");
                }
                else
                {
                    mAllFolderABDic.Add(folderAB.ABName, folderAB.Path);
                    mABPathFilters.Add(folderAB.Path);
                    mAssetFilters.Add(folderAB.Path);
                }
            }
            //------单prefab ab字典添加
            //在配置文件夹下搜索所有prefab
            _FindSingleAsset(SingleAssetType.Prefab);
            //------scene ab字典添加
            //在配置文件夹下搜索所有场景
            _FindSingleAsset(SingleAssetType.Scene);
            foreach (string name in mAllFolderABDic.Keys)
            {
                setABName(name, mAllFolderABDic[name]);
            }

            foreach (string name in mAllSingleAssetABDic.Keys)
            {
                setABName(name, mAllSingleAssetABDic[name]);
            }

            BunildAssetBundle();
            //清除包名标记
            string[] abNames = AssetDatabase.GetAllAssetBundleNames();
            for (int i = 0; i < abNames.Length; i++)
            {
                AssetDatabase.RemoveAssetBundleName(abNames[i], true);
                EditorUtility.DisplayProgressBar("清除AB包名", "名字:" + abNames[i], i * 1.0f / abNames.Length);
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            EditorUtility.ClearProgressBar();
        }
Exemplo n.º 2
0
        public static void Build()
        {
            mAssetLst.Clear();
            mABPathFilter.Clear();
            mAllFolderABDic.Clear();
            mAllPrefabABDic.Clear();
            ABNameConfig abNameConfig = AssetDatabase.LoadAssetAtPath <ABNameConfig>(mABNameConfigPath);

            //------文件夹ab字典添加
            foreach (var folderAB in abNameConfig.AllFolderAB)
            {
                if (mAllFolderABDic.ContainsKey(folderAB.ABName))
                {
                    Debug.LogError("AB包配置名字重复,请检查!");
                }
                else
                {
                    mAllFolderABDic.Add(folderAB.ABName, folderAB.Path);
                    mABPathFilter.Add(folderAB.Path);
                    mAssetLst.Add(folderAB.Path);
                }
            }
            //------单prefab ab字典添加

            //在配置文件夹下搜索所有prefab
            string[] prfGuids = AssetDatabase.FindAssets("t:Prefab", abNameConfig.AllPrefabAB.ToArray());
            for (int i = 0; i < prfGuids.Length; i++)
            {
                string prfPath = AssetDatabase.GUIDToAssetPath(prfGuids[i]);
                EditorUtility.DisplayProgressBar("查找Prefab", "Prefab:" + prfPath, i * 1.0f / prfGuids.Length);
                mAssetLst.Add(prfPath);
                if (!containPathFilter(prfPath))
                {
                    string        prfName        = prfPath.Remove(0, prfPath.LastIndexOf("/") + 1);
                    GameObject    obj            = AssetDatabase.LoadAssetAtPath <GameObject>(prfPath);
                    string[]      allDependences = AssetDatabase.GetDependencies(prfPath);
                    List <string> allDependPath  = new List <string>();
                    for (int j = 0; j < allDependences.Length; j++)
                    {
                        if (!containPathFilter(allDependences[j]) && !allDependences[j].EndsWith(".cs"))
                        {
                            mABPathFilter.Add(allDependences[j]);
                            allDependPath.Add(allDependences[j]);
                        }
                    }
                    if (mAllPrefabABDic.ContainsKey(obj.name))
                    {
                        Debug.LogError("存在相同名字的Prefab!名字:" + obj.name);
                    }
                    else
                    {
                        mAllPrefabABDic.Add(obj.name, allDependPath);
                    }
                }
            }

            foreach (string name in mAllFolderABDic.Keys)
            {
                setABName(name, mAllFolderABDic[name]);
            }

            foreach (string name in mAllPrefabABDic.Keys)
            {
                setABName(name, mAllPrefabABDic[name]);
            }

            BunildAssetBundle();
            //清除包名标记
            string[] abNames = AssetDatabase.GetAllAssetBundleNames();
            for (int i = 0; i < abNames.Length; i++)
            {
                AssetDatabase.RemoveAssetBundleName(abNames[i], true);
                EditorUtility.DisplayProgressBar("清除AB包名", "名字:" + abNames[i], i * 1.0f / abNames.Length);
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            EditorUtility.ClearProgressBar();
        }