Exemplo n.º 1
0
    public void ValidateAssetBundleList_WithVariants_ContainsCorrectList()
    {
        // Account for existing bundles
        int numBundles = AssetDatabase.GetAllAssetBundleNames().Length;

        List <string> listOfPrefabs = new List <string>();

        string bundleName = "bundletest";

        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundleName, "v1"));
        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundleName, "v2"));

        TestUtil.ExecuteCodeAndCleanupAssets(() =>
        {
            //Act: Operates on the list of asset bundle names found in the AssetDatabase
            string[] list = Model.ValidateBundleList();

            //Assert
            Assert.AreEqual(numBundles + 2, list.Length);
            Assert.IsTrue(list.Contains(bundleName + ".v1"));
            Assert.IsTrue(list.Contains(bundleName + ".v2"));
        }, listOfPrefabs);
    }
        public static void Build(AssetBundleConfig abConfig)
        {
            if (!Directory.Exists(abConfig.outputPath))
            {
                Directory.CreateDirectory(abConfig.outputPath);
            }

//            CheckAndClearOldRepeatAssets();
            ClearUselessAssetBundleFiles(abConfig.outputPath);

            var assets = new List <string>();

            foreach (var abName in AssetDatabase.GetAllAssetBundleNames())
            {
                foreach (var assetPath in AssetDatabase.GetAssetPathsFromAssetBundle(abName))
                {
                    assets.Add(assetPath);
                }
            }

            AddAssetBundleNameForRepeatDependencies(assets);
            InternalBuildAssetBundle(abConfig, null);
        }
Exemplo n.º 3
0
    public static void SetAssetBundlesName()
    {
        //nameDict.Clear();
        pathDict.Clear();

        int length = AssetDatabase.GetAllAssetBundleNames().Length;

        Debug.Log("生成前 bundle数目 " + length);

        //构造相对路径使用
        resourcePath = Application.dataPath + c_ResourceParentPath;

        direIndex  = resourcePath.LastIndexOf(c_ResourceParentPath);
        direIndex += c_ResourceParentPath.Length;

        assetsIndex = resourcePath.LastIndexOf(c_AssetsParentPath);
        EditorUtility.DisplayProgressBar("生成Bundle名字", "进度", 0);
        RecursionDirectory(Application.dataPath + "/Resources/");

        length = AssetDatabase.GetAllAssetBundleNames().Length;
        Debug.Log("生成后 bundle数目 " + length);
        EditorUtility.ClearProgressBar();
    }
Exemplo n.º 4
0
    static void RemoveUnusedBundles(BundleInfoAsset rsd)
    {
        string[] bs = AssetDatabase.GetAllAssetBundleNames();
        int      i  = 0;

        foreach (var name in bs)
        {
            i++;
            if (null == rsd.BundleInfos.Find((info) =>
            {
                return(info.name == name);
            }))
            {
                if (EditorUtility.DisplayCancelableProgressBar(string.Format("remove unused {0}", name), name, 1))
                {
                    EditorUtility.ClearProgressBar();
                    return;
                }
                AssetDatabase.RemoveAssetBundleName(name, true);
            }
        }
        EditorUtility.ClearProgressBar();
    }
Exemplo n.º 5
0
        public void CollectData()
        {
            List <string> assetPaths = new List <string>();

            foreach (string abName in AssetDatabase.GetAllAssetBundleNames())
            {
                assetPaths.AddRange(AssetDatabase.GetAssetPathsFromAssetBundle(abName));
            }
            assets = new List <Object>();
            string filter = "Assets/" + folder + (folder == "" ? "" : "/");

            foreach (string path in AssetDatabase.GetAllAssetPaths().Except(AssetDatabase.GetDependencies(assetPaths.ToArray())).OrderBy(x => x))
            {
                if (path.StartsWith(filter))
                {
                    Object obj = AssetDatabase.LoadMainAssetAtPath(path);
                    if (!(obj is DefaultAsset || obj is MonoScript))
                    {
                        assets.Add(obj);
                    }
                }
            }
        }
        public static string AssetPathToAssetbundleName(string assetPath)
        {
            string[] allNames = AssetDatabase.GetAllAssetBundleNames();
            foreach (string name in allNames)
            {
                string[] allPath = AssetDatabase.GetAssetPathsFromAssetBundle(name);
                if (allPath == null)
                {
                    continue;
                }

                int idx = System.Array.IndexOf(allPath, assetPath);
                if (idx == -1)
                {
                    //not found
                    continue;
                }

                return(name);
            }

            return(null);
        }
        public static AssetBundleBuildInput GenerateAssetBundleBuildInput(AssetBundleBuildSettings settings)
        {
            var input = new AssetBundleBuildInput();

            input.settings = settings;
            var bundleNames = AssetDatabase.GetAllAssetBundleNames();

            input.bundles = new AssetBundleBuildInput.Definition[bundleNames.Length];
            for (int i = 0; i < bundleNames.Length; i++)
            {
                int dot = bundleNames[i].LastIndexOf('.');
                input.bundles[i].name    = dot < 0 ? bundleNames[i] : bundleNames[i].Substring(0, dot);
                input.bundles[i].variant = dot < 0 ? string.Empty : bundleNames[i].Substring(dot + 1);
                var assets = AssetDatabase.GetAssetPathsFromAssetBundle(bundleNames[i]);
                input.bundles[i].assets = new GUID[assets.Length];
                for (int a = 0; a < assets.Length; a++)
                {
                    input.bundles[i].assets[a] = new GUID(AssetDatabase.AssetPathToGUID(assets[a]));
                }
            }

            return(input);
        }
Exemplo n.º 8
0
        public static void ClearAssetBundleName()
        {
            if (EditorUtility.DisplayDialog("警告", "即将清除所有资源包标签,操作不可逆,是否继续?", "必须的", "我再想想"))
            {
                // UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.TopLevel);
                string[] names  = AssetDatabase.GetAllAssetBundleNames();
                int      length = names.Length;
                string[] oldAssetBundleNames = new string[length];
                for (int i = 0; i < length; i++)
                {
                    oldAssetBundleNames[i] = names[i];
                }

                for (int j = 0; j < oldAssetBundleNames.Length; j++)
                {
                    Debug.Log("Asset bundle name " + oldAssetBundleNames[j] + " has remove.");
                    AssetDatabase.RemoveAssetBundleName(oldAssetBundleNames[j], true);
                }
            }
            else
            {
            }
        }
Exemplo n.º 9
0
            public static void BuildBundles()
            {
                string[] paths = Directory.GetDirectories(Path.Combine(Application.dataPath, String.Join(Path.DirectorySeparatorChar.ToString(), new string[] { "Player", "Bundles" })));

                foreach (string path in paths)
                {
                    BuildBundle(path);
                }

                string[] names = AssetDatabase.GetAllAssetBundleNames();

                if (0 < names.Count())
                {
                    if (!Directory.Exists(DIR_OUT))
                    {
                        Directory.CreateDirectory(DIR_OUT);
                    }

                    BuildPipeline.BuildAssetBundles(DIR_OUT,
                                                    BuildAssetBundleOptions.None,
                                                    BuildTarget.StandaloneWindows);
                }
            }
Exemplo n.º 10
0
        public static IEnumerable <SerializedProperty> WalkAssetBundles()
        {
            var seen  = new HashSet <UnityEngine.Object>();
            var queue = new Queue <UnityEngine.Object>();
            var names = AssetDatabase.GetAllAssetBundleNames();

            foreach (string name in names)
            {
                foreach (var path in AssetDatabase.GetAssetPathsFromAssetBundle(name))
                {
                    var obj = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(path);
                    queue.Enqueue(obj);
                }
            }
            while (queue.Count > 0)
            {
                var obj = queue.Dequeue();
                if (seen.Contains(obj))
                {
                    continue;
                }
                seen.Add(obj);
                var serializedObject = new SerializedObject(obj);
                var prop             = serializedObject.GetIterator();
                prop.Next(true);
                while (prop.NextVisible(true))
                {
                    if (prop.propertyType == SerializedPropertyType.ObjectReference &&
                        prop.objectReferenceValue != null &&
                        !seen.Contains(prop.objectReferenceValue))
                    {
                        queue.Enqueue(prop.objectReferenceValue);
                    }
                    yield return(prop);
                }
            }
        }
Exemplo n.º 11
0
        public void AddressableAssetUtility_ConvertAssetBundlesToAddressables_CanConvertBundles(int numBundles)
        {
            // Setup
            var prevGroupCount = Settings.groups.Count;
            var testAssetGUIDs = new List <string>();

            for (int i = 0; i < numBundles; i++)
            {
                var testObject = new GameObject("TestObjectForBundles" + i);
#if UNITY_2018_3_OR_NEWER
                PrefabUtility.SaveAsPrefabAsset(testObject, ConfigFolder + "/testasset" + i + ".prefab");
#else
                PrefabUtility.CreatePrefab(k_TestConfigFolder + "/testasset" + i + ".prefab", testObject);
#endif
                testAssetGUIDs.Add(AssetDatabase.AssetPathToGUID(ConfigFolder + "/testasset" + i + ".prefab"));
                var importer = AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(testAssetGUIDs[i]));
                importer.assetBundleName = "testAssetBundleName" + i;
                AssetDatabase.SaveAssets();
            }
            AddressableAssetSettingsDefaultObject.Settings = Settings;

            // Test
            AddressableAssetUtility.ConvertAssetBundlesToAddressables();
            Assert.AreEqual(prevGroupCount + numBundles, Settings.groups.Count);
            Assert.AreEqual(0, AssetDatabase.GetAllAssetBundleNames().Length);
            for (int i = 0; i < numBundles; i++)
            {
                Assert.NotNull(Settings.FindAssetEntry(testAssetGUIDs[i]));
            }

            // Cleanup
            for (int i = 0; i < numBundles; i++)
            {
                var lastGroupIndex = AddressableAssetSettingsDefaultObject.Settings.groups.Count - 1;
                AddressableAssetSettingsDefaultObject.Settings.RemoveGroup(AddressableAssetSettingsDefaultObject.Settings.groups[lastGroupIndex]);
            }
        }
Exemplo n.º 12
0
        public bool BuildAssetBundles(ABBuildInfo info)
        {
            if (info == null)
            {
                Debug.Log("Error in build");
                return(false);
            }

            //Debug.Log("suffix: " + info.suffix);
            //设置所有Assetbundle的尾缀
            foreach (var assetBundleName in AssetDatabase.GetAllAssetBundleNames())
            {
                foreach (var item in AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName))
                {
                    AssetImporter asset = AssetImporter.GetAtPath(item);
                    asset.assetBundleVariant = "ab";
                    //Debug.Log(asset.assetBundleVariant);
                }
            }

            var buildManifest = BuildPipeline.BuildAssetBundles(info.outputDirectory, info.options, info.buildTarget);

            if (buildManifest == null)
            {
                Debug.Log("Error in build");
                return(false);
            }

            foreach (var assetBundleName in buildManifest.GetAllAssetBundles())
            {
                if (info.onBuild != null)
                {
                    info.onBuild(assetBundleName);
                }
            }
            return(true);
        }
Exemplo n.º 13
0
    public void HandleBundleMerge_Merges_BundlesCorrectly()
    {
        // Account for existing bundles
        int numBundles = AssetDatabase.GetAllAssetBundleNames().Length;

        string bundle1Name = "bundle1";
        string bundle2Name = "bundle2";

        BundleDataInfo bundle1DataInfo = Model.CreateEmptyBundle() as BundleDataInfo;

        Model.HandleBundleRename(new BundleTreeItem(bundle1DataInfo, 0, ABModelUtil.FakeTexture2D), bundle1Name);

        BundleDataInfo bundle2DataInfo = Model.CreateEmptyBundle() as BundleDataInfo;

        Model.HandleBundleRename(new BundleTreeItem(bundle2DataInfo, 0, ABModelUtil.FakeTexture2D), bundle2Name);

        List <string> listOfPrefabs = new List <string>();

        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle1Name, String.Empty));
        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle2Name, String.Empty));
        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle2Name, String.Empty));

        TestUtil.ExecuteCodeAndCleanupAssets(() =>
        {
            Model.HandleBundleMerge(new BundleInfo[] { bundle2DataInfo }, bundle1DataInfo);

            string[] bundleNames = AssetDatabase.GetAllAssetBundleNames();
            Assert.AreEqual(numBundles + 1, bundleNames.Length);
            Assert.IsTrue(bundleNames.Contains(bundle1Name));

            //Make sure every asset now has bundle1 as the bundle name
            foreach (string prefab in listOfPrefabs)
            {
                Assert.AreEqual(bundle1Name, AssetImporter.GetAtPath(prefab).assetBundleName);
            }
        }, listOfPrefabs);
    }
Exemplo n.º 14
0
    /// <summary>
    /// 打包过程
    /// </summary>
    static void BuildAssetBundle()
    {
        string[] allBundleNames = AssetDatabase.GetAllAssetBundleNames();    //获取所有包名
        //key为全路径,Value为包名  这个字典是所有打包的全路径和包名,用于设置自己的配置表
        Dictionary <string, string> resultPathDic = new Dictionary <string, string>();

        for (int i = 0; i < allBundleNames.Length; i++)
        {
            string[] allBundlePaths = AssetDatabase.GetAssetPathsFromAssetBundle(allBundleNames[i]); //获取该包名下的所有路径
            for (int j = 0; j < allBundlePaths.Length; j++)
            {
                if (allBundlePaths[j].EndsWith(".cs"))
                {
                    continue;
                }

                Debug.Log("AB包:" + allBundleNames[i] + " 包含资源路径:" + allBundlePaths[j]);

                resultPathDic.Add(allBundlePaths[j], allBundleNames[i]);
            }
        }

        if (!Directory.Exists(BUNDLETARGERPATH))
        {
            Directory.CreateDirectory(BUNDLETARGERPATH);
        }

        //删除不存在或者已经改名的AB包
        DeleteAB();

        //自己的配置表生成
        CreateConfigTable(resultPathDic);

        //打包
        BuildPipeline.BuildAssetBundles(BUNDLETARGERPATH, BuildAssetBundleOptions.ChunkBasedCompression,
                                        EditorUserBuildSettings.activeBuildTarget);
    }
Exemplo n.º 15
0
    public static void Gen()
    {
        string[]      allbundles = AssetDatabase.GetAllAssetBundleNames();
        List <string> lines      = new List <string>();

        foreach (var bundleName in allbundles)
        {
            string[] assetPaths =
                AssetDatabase.GetAssetPathsFromAssetBundle(bundleName);

            foreach (var astPath in assetPaths)
            {
                string        assetName   = Path.GetFileNameWithoutExtension(astPath);
                StringBuilder lineBuilder = new StringBuilder();
                lineBuilder.Append($"{astPath},{bundleName},{assetName},{Path.GetExtension(astPath)}");
                lines.Add(lineBuilder.ToString());
            }
        }

        string fileName = Path.Combine(System.Environment.CurrentDirectory, "csv", "asset", "asset.csv");

        using (var stream = File.OpenWrite(fileName))
        {
            StreamWriter sw = new StreamWriter(stream, Encoding.GetEncoding(936));
            stream.Seek(0, SeekOrigin.Begin);
            stream.SetLength(0);
            sw.WriteLine("##assetPath,bundleName,assetName,type");
            foreach (var line in lines)
            {
                sw.WriteLine(line);
            }

            sw.Close();
        }

        Debug.Log($"Generate Assets.csv successfully at path {fileName}");
    }
Exemplo n.º 16
0
    static void BuildAssetBundle()  //打AB包
    {
        //生成AB包配置表

        string[] allBundles = AssetDatabase.GetAllAssetBundleNames();

        //Key为全路径   Value为包名
        Dictionary <string, string> resPathDic = new Dictionary <string, string>();

        for (int i = 0; i < allBundles.Length; i++)
        {
            string[] abPaths = AssetDatabase.GetAssetPathsFromAssetBundle(allBundles[i]);

            for (int j = 0; j < abPaths.Length; j++)
            {
                resPathDic.Add(abPaths[j], allBundles[i]);
            }
        }

        DeleteUnusedAB();
        WriteData(resPathDic);

        BuildPipeline.BuildAssetBundles(m_BundleTargetPath, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget);
    }
Exemplo n.º 17
0
    /// <summary>
    /// 删除多余的AB包
    /// </summary>
    private static void DeleteAB()
    {
        //获取所有AB包的名字
        string[]      allBundlesName = AssetDatabase.GetAllAssetBundleNames();
        DirectoryInfo direction      = new DirectoryInfo(_bundleTargetPath);

        FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
        for (int i = 0; i < files.Length; i++)
        {
            //判断是否已经存在AB包中
            if (ContainABName(files[i].Name, allBundlesName) || files[i].Name.EndsWith(".meta"))
            {
                continue;
            }
            else
            {
                Debug.Log("此AB包已经被删或者改名了:" + files[i].Name);
                if (File.Exists(files[i].FullName))
                {
                    File.Delete(files[i].FullName);
                }
            }
        }
    }
Exemplo n.º 18
0
    public void Reload()
    {
        buildTarget = EditorUserBuildSettings.activeBuildTarget;
        assetBundles.Clear();

        var versions = GetVersionJson();

        foreach (var(bundleName, assetPath) in AssetDatabase.GetAllAssetBundleNames()
                 .Zip(AssetDatabase.GetAllAssetPaths()))
        {
            var children = AssetDatabase.GetAssetPathsFromAssetBundle(bundleName);
            Assert.AreEqual(children.Length, 1);
            var row = new Row
            {
                Name    = bundleName,
                Path    = children[0],
                Version = versions[bundleName]?.Value <int>() ?? 1
            };
            versions[bundleName] = row.Version;
            assetBundles.Add(row);
        }

        SaveVersionJson();
    }
Exemplo n.º 19
0
        public static void ClearAnalysisAssetBundleNames()
        {
            var abNames = AssetDatabase.GetAllAssetBundleNames();

            foreach (var abName in abNames)
            {
                if (string.IsNullOrWhiteSpace(abName))
                {
                    continue;
                }

                if (abName.StartsWith(dependentABPrefix))
                {
                    var abAssetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(abName);

                    foreach (var assetPath in abAssetPaths)
                    {
                        if (IsCSharp(assetPath))
                        {
                            continue;
                        }

                        var go = AssetDatabase.LoadAssetAtPath <Object>(assetPath);

                        if (go)
                        {
                            AssetImporter assetImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(go.GetInstanceID()));

                            assetImporter.assetBundleName = string.Empty;
                        }
                    }
                }
            }

            RemoveUnusedAssetBundleNames();
        }
Exemplo n.º 20
0
        // 删除无用AB包
        static void DeleteUnusedAB()
        {
            // 获取所有AB名
            string[] allABName = AssetDatabase.GetAllAssetBundleNames();

            DirectoryInfo directory = new DirectoryInfo(m_BundleTargetPath);

            FileInfo[] files = directory.GetFiles("*", SearchOption.AllDirectories);
            for (int i = 0; i < files.Length; i++)
            {
                if (ContainedABName(files[i].Name, allABName) || files[i].Name.EndsWith(".meta"))
                {
                    continue;
                }
                else
                {
                    Debug.Log("此AB包已经被删除或者改名了: " + files[i].Name);
                    if (File.Exists(files[i].FullName))
                    {
                        File.Delete(files[i].FullName);
                    }
                }
            }
        }
Exemplo n.º 21
0
        static void BuildAssetBundle()
        {
            // 获取所有AB名
            string[] allABName = AssetDatabase.GetAllAssetBundleNames();

            // key 为全路径, value为ab名
            Dictionary <string, string> resPathDic = new Dictionary <string, string>();


            for (int i = 0; i < allABName.Length; i++)
            {
                // 获取所有相同ab名的资源的路径
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(allABName[i]);

                for (int j = 0; j < assetPaths.Length; j++)
                {
                    if (assetPaths[j].EndsWith(".cs"))
                    {
                        continue;
                    }

                    Debug.Log("此AB包: " + allABName[i] + "下面包含的资源文件路径: " + assetPaths[j]);

                    if (ValidPath(assetPaths[j]))
                    {
                        resPathDic.Add(assetPaths[j], allABName[i]);
                    }
                }
            }

            DeleteUnusedAB();
            // 生成自己的配置表
            WriteData(resPathDic);

            BuildPipeline.BuildAssetBundles(m_BundleTargetPath, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget);
        }
Exemplo n.º 22
0
    /// <summary>
    /// 删除此次打包不需要的AB包,打AB包为增量打包,保留此次打包中仍需要打包的ab包文件可以提高打包速度
    /// </summary>
    static void DeletAB()
    {
        string[] allbundlesName = AssetDatabase.GetAllAssetBundleNames();

        DirectoryInfo directory = new DirectoryInfo(m_BundleTargetPath);

        FileInfo[] files = directory.GetFiles("*", SearchOption.AllDirectories);

        for (int i = 0; i < files.Length; i++)
        {
            if (ContainABName(files[i].Name, allbundlesName) || files[i].Name.EndsWith(".meta"))//删除.meta对应自以后,unity会自动清理.meta文件
            {
                continue;
            }
            else
            {
                Debug.Log("此AB包已被删除或改名:" + files[i].Name);
                if (File.Exists(files[i].FullName))
                {
                    File.Delete(files[i].FullName);
                }
            }
        }
    }
Exemplo n.º 23
0
    private static void Reset()
    {
        if (BuildSettings.clearAssetBundle)
        {
            // 清除现有ab目录
            IGG.FileUtil.ClearDirectory(BuildSettings.assetBundleOutputPath);
        }
        else
        {
            IGG.FileUtil.CreateDirectory(BuildSettings.assetBundleOutputPath);
        }

        if (BuildSettings.resetAssetBundleName)
        {
            // 清除所有assetbundle名
            var assetBundleNames = AssetDatabase.GetAllAssetBundleNames();
            foreach (string name in assetBundleNames)
            {
                AssetDatabase.RemoveAssetBundleName(name, true);
            }
        }

        AssetDatabase.Refresh();
    }
Exemplo n.º 24
0
        protected virtual void DrawBuilderInfo(IProjectBuilder builder)
        {
            if (builder.BuildApplication)
            {
                string productName     = builder.ProductName;
                string version         = builder.Version;
                string fullVersionCode = BuildPathUtils.GetVersionCodeLong(builder);

                string titleText = string.Format("{0} ver.{1} ({2})", productName, version, fullVersionCode);

                GUILayout.Label(
                    new GUIContent(titleText, GetBuildTargetIcon(builder)), EditorStyles.largeLabel);
            }
            else if (builder.BuildAssetBundle)
            {
                var assetBundles      = AssetDatabase.GetAllAssetBundleNames();
                int assetBundlesCount = assetBundles.Length;

                string titleText = string.Format("{0} AssetBundles", assetBundlesCount);

                GUILayout.Label(
                    new GUIContent(titleText, GetBuildTargetIcon(builder)), EditorStyles.largeLabel);
            }
        }
Exemplo n.º 25
0
    //打包
    static void BiuldAssetBundle()
    {
        string[] ab_names = AssetDatabase.GetAllAssetBundleNames();
        //key:path value:ABname
        Dictionary <string, string> ab_path_dic = new Dictionary <string, string>();

        for (int i = 0; i < ab_names.Length; i++)
        {
            string[] ab_path = AssetDatabase.GetAssetPathsFromAssetBundle(ab_names[i]);
            for (int j = 0; j < ab_path.Length; j++)
            {
                if (ab_path[j].EndsWith(".cs"))
                {
                    continue;
                }
                //所有依赖都需要存入字典
                ab_path_dic.Add(ab_path[j], ab_names[i]);
            }
        }
        DeleteAB();
        //生成配置
        //这个path是依赖的 Asset/.../xx.mp3 相对路径
        WriteData(ab_path_dic);
        AssetDatabase.Refresh();
        SetABName("assetbundleconfig", BINARY_PATH);
        AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(BundleTargetPath, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget);

        if (manifest == null)
        {
            Debug.LogError("打包失败");
        }
        else
        {
            Debug.Log("打包成功");
        }
    }
Exemplo n.º 26
0
    // スクリプト作成
    public static void CreateScript()
    {
        var builder = new StringBuilder();

        builder.AppendFormat("public static class {0}", FILENAME_WITHOUT_EXTENSION).AppendLine();
        builder.AppendLine("{");

        foreach (var name in AssetDatabase.GetAllAssetBundleNames())
        {
            LoadAssetBundle(name, builder);
        }

        builder.AppendLine("}");

        var directoryName = Path.GetDirectoryName(PATH);

        if (!Directory.Exists(directoryName))
        {
            Directory.CreateDirectory(directoryName);
        }

        File.WriteAllText(PATH, builder.ToString(), Encoding.UTF8);
        AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
    }
 private void RedundanciesAB(object context)
 {
     try
     {
         EditorUtility.DisplayProgressBar("RedundanciesAB", "GetAllAssetBundleNames", 0.1f);
         var tempABs = AssetDatabase.GetAllAssetBundleNames();
         EditorUtility.DisplayProgressBar("RedundanciesAB", "Optimize", 0.25f);
         RedundanciesOp.Optimize(ref tempABs);
         EditorUtility.DisplayProgressBar("RedundanciesAB", "RemoveUnusedAssetBundleNames", 0.7f);
         AssetDatabase.RemoveUnusedAssetBundleNames();
         EditorUtility.DisplayProgressBar("RedundanciesAB", "RemoveUnusedAssetBundleNames", 0.75f);
         AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate);
         EditorUtility.DisplayProgressBar("RedundanciesAB", "RemoveUnusedAssetBundleNames", 0.9f);
         AssetBundleModel.Model.ForceReloadData(this);
     }
     catch (Exception e)
     {
         throw e;
     }
     finally
     {
         EditorUtility.ClearProgressBar();
     }
 }
Exemplo n.º 28
0
    /// <summary>
    /// 清空AB文件的标记
    /// </summary>
    public static void ClearMarks()
    {
        string[] names = AssetDatabase.GetAllAssetBundleNames();
        if (names.Length < 1)
        {
            return;
        }
        int startIndex = 0;

        for (int i = 0; i < names.Length; i++)
        {
            string name = names[startIndex];
            EditorUtility.DisplayProgressBar("清理标记中", name, (float)(startIndex + 1) / (float)names.Length);
            AssetDatabase.RemoveAssetBundleName(name, true);
            startIndex++;
            if (startIndex >= names.Length)
            {
                EditorUtility.ClearProgressBar();
                EditorApplication.update = null;
                startIndex = 0;
                break;
            }
        }
    }
Exemplo n.º 29
0
    public void HandleBundleMerge_Merges_BundlesWithChildrenCorrectly()
    {
        // Account for existing bundles
        int numBundles = AssetDatabase.GetAllAssetBundleNames().Length;

        string folderName  = "folder";
        string bundle1Name = "bundle1";
        string bundle2Name = folderName + "/bundle2";

        BundleFolderConcreteInfo concrete        = new BundleFolderConcreteInfo(folderName, ABModelUtil.Root);
        BundleDataInfo           bundle1DataInfo = new BundleDataInfo(bundle1Name, ABModelUtil.Root);
        BundleDataInfo           bundle2DataInfo = new BundleDataInfo(bundle2Name, concrete);

        concrete.AddChild(bundle2DataInfo);

        List <string> listOfPrefabs = new List <string>();

        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle1Name, String.Empty));
        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle2Name, String.Empty));
        listOfPrefabs.Add(TestUtil.CreatePrefabWithBundleAndVariantName(bundle2Name, String.Empty));

        TestUtil.ExecuteCodeAndCleanupAssets(() =>
        {
            Model.HandleBundleMerge(new BundleInfo[] { bundle1DataInfo }, bundle2DataInfo);

            string[] bundleNames = AssetDatabase.GetAllAssetBundleNames();
            Assert.AreEqual(numBundles + 1, bundleNames.Length, GetAllElementsAsString(bundleNames));
            Assert.IsTrue(bundleNames.Contains(bundle2Name));

            //Make sure every asset now has bundle1 as the bundle name
            foreach (string prefab in listOfPrefabs)
            {
                Assert.AreEqual(bundle2Name, AssetImporter.GetAtPath(prefab).assetBundleName);
            }
        }, listOfPrefabs);
    }
Exemplo n.º 30
0
    public static void BuidldBundles()
    {
        if (MyEditorTools.IsPlaying())
        {
            return;
        }
        if (!Directory.Exists(resPath))
        {
            Debug.LogError("资源路径不存在:" + resPath);
        }
        if (!Directory.Exists(outPut))
        {
            Directory.CreateDirectory(outPut);
        }
        if (!Directory.Exists(Application.streamingAssetsPath))
        {
            Directory.CreateDirectory(Application.streamingAssetsPath);
        }
        //把热更文件拷贝进来
        //CopyHotFix();

        //清除Ab包资源名
        string[] abNames = AssetDatabase.GetAllAssetBundleNames();
        for (int i = 0; i < abNames.Length; i++)
        {
            AssetDatabase.RemoveAssetBundleName(abNames[i], true);
        }
        Debug.LogError("清除全部资源AssetBundle名称完成!");
        SetAssetsBundleName(resPath);
        Debug.LogError("设置AssetBundle名称完成!");
        EditSpritAtlas.SetUIAtlas();
        BuildPipeline.BuildAssetBundles(outPut, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
        CreateAssetBundleFileInfo();
        AssetDatabase.Refresh();
        Debug.LogError("AssetBundle打包完成!");
    }