Exemplo n.º 1
0
        /// <summary>
        /// 根据AB名称获取该模块下的所有的AssetBundle构建对象
        /// </summary>
        /// <returns></returns>
        public static List <AssetBundleBuild> GetBuildMapByAssetBundleNames(List <string> _assetBunleNames)
        {
            List <AssetBundleBuild> result = new List <AssetBundleBuild>();

            foreach (var v in _assetBunleNames)
            {
                var allPath = AssetDatabase.GetAssetPathsFromAssetBundle(v);
                if (allPath.Length == 0)
                {
                    continue;
                }
                AssetBundleBuild map = new AssetBundleBuild();
                string[]         nameAndExtension = v.Split('.');
                map.assetBundleName    = nameAndExtension[0];
                map.assetBundleVariant = nameAndExtension[1];
                map.assetNames         = allPath;
                result.Add(map);
            }
            return(result);
        }
Exemplo n.º 2
0
        //アセットバンドルリストを取得
        AssetBundleBuild[] ToAssetBundleBuilds(List <MainAssetInfo> assets)
        {
            List <AssetBundleBuild> list = new List <AssetBundleBuild>();

            foreach (MainAssetInfo asset in assets)
            {
                AssetImporter importer = asset.AssetImporter;
                if (importer == null)
                {
                    Debug.LogError("Not Find Importer");
                    continue;
                }
                AssetBundleBuild build = new AssetBundleBuild();
                build.assetBundleName    = importer.assetBundleName;
                build.assetBundleVariant = importer.assetBundleVariant;
                build.assetNames         = AssetDatabase.GetAssetPathsFromAssetBundle(importer.assetBundleName);
                list.Add(build);
            }
            return(list.ToArray());
        }
Exemplo n.º 3
0
    static void export()
    {
        AssetBundleInfo abi = new AssetBundleInfo();
        var             abs = AssetDatabase.GetAllAssetBundleNames();

        for (int i = 0; i < abs.Length; i++)
        {
            var files = AssetDatabase.GetAssetPathsFromAssetBundle(abs[i]);
            abi.AssetBundles[abs[i]] = files;
            foreach (var f in files)
            {
                Debug.Log(abs[i] + ":" + f);
            }
        }
        var    writer = new YamlDotNet.Serialization.Serializer();
        string str    = writer.Serialize(abi);

        Debug.Log(str);
        File.WriteAllText(getconfpath(), str);
    }
Exemplo n.º 4
0
    public static void BuildAssetBundle()
    {
        #region   生成配置表
        string[] allBundles = AssetDatabase.GetAllAssetBundleNames();   //直接得到不带后缀的包名
        //key为全路径,value为bundlename
        Dictionary <string, string> tempDic = new Dictionary <string, string>();
        for (int i = 0; i < allBundles.Length; i++)
        {
            //Debug.Log(allBundles[i] + "    ----");
            string[] bundlePathArray = AssetDatabase.GetAssetPathsFromAssetBundle(allBundles[i]);
            for (int j = 0; j < bundlePathArray.Length; j++)
            {
                //Debug.Log(allBundles[i] + "_______" + bundlePathArray[j]);
                tempDic.Add(bundlePathArray[j], allBundles[i]);
            }
        }

        //这里还有一个步骤,就是如果之前资源的一些属性改变了(比如名字),那么如果之前已经打包过了,如果重新打包时,
        //不将这些属性改变了的资源的ab包删除掉,就会产生冗余,所以打包之前先判断
        //判断的逻辑是:已经设置的ab包名 跟 已经打包好的ab包 进行比较,如果设置的ab包名中不包含当前存在的ab包名,则删除
        DeleteNotExistABName();

        //生成配置表
        CreateConfigTable(tempDic);
        #endregion

        //执行打包
        AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(PathConfig.Instance.GetABTargetPath(),
                                                                       BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget);

        if (manifest == null)
        {
            Debug.LogError("AssetBundle 打包失败");
        }
        else
        {
            Debug.Log("AssetBundle 打包完成");
        }
        AppBuildEditor.CopyABToStreamAssetsPath();
        AssetDatabase.Refresh();
    }
Exemplo n.º 5
0
    void onOpenMap(DataRow data)
    {
        string targetPath = "scene/" + data["mapResId"].ToString();

        string[] assets2 = AssetDatabase.GetAssetPathsFromAssetBundle(targetPath);
        //string[]  assets2 = new string[1];
        //assets2[0] = "E:/xlj-res/main/main/Assets/ART/Scenescene/"+ data["mapResId"].ToString() ;
        if (assets2.Length == 0)
        {
            Debug.LogError("地图资源不存在:" + data["mapResId"].ToString());
            showError("地图资源设置不正确:" + data["mapResId"].ToString() + ",请联系前端处理");
        }
        // else
        {
            if (assets2.Length > 1)
            {
                Debug.LogWarning("有重复的地图资源:" + data["mapResId"].ToString());
            }
            string[] demos = AssetDatabase.FindAssets(data["mapResId"].ToString() + "_demo t:Scene");
            if (demos.Length == 0)
            {
                showError("地图demo资源不存在:" + data["mapResId"].ToString());
                return;
            }
            Debug.Log("begin to open scene:" + AssetDatabase.GUIDToAssetPath(demos[0]));
            bool ret = EditorApplication.OpenScene(AssetDatabase.GUIDToAssetPath(demos[0]));
            curMapData           = data;
            EditorData.mapId     = curMapData["mapid"].ToString();
            EditorData.mapResId  = curMapData["mapResId"].ToString();
            EditorData.mapTileId = curMapData["mapTileId"].ToString();
            LoadTile(EditorData.mapTileId);
            Debug.Log("set map tile id:" + EditorData.mapTileId);
            safeConfig();
            curTool = 0;
            EditorData.start_edit_tile = false;
            showMesh  = false;
            npcLoaded = false;
            npcHelper = new NpcEditHelper();
            Repaint();
        }
    }
Exemplo n.º 6
0
    static void BunildAssetBundle()
    {
        string[] allBundles = AssetDatabase.GetAllAssetBundleNames();
        //key为全路径,value为包名
        Dictionary <string, string> resPathDic = new Dictionary <string, string>();

        for (int i = 0; i < allBundles.Length; i++)
        {
            string[] allBundlePath = AssetDatabase.GetAssetPathsFromAssetBundle(allBundles[i]);
            for (int j = 0; j < allBundlePath.Length; j++)
            {
                if (allBundlePath[j].EndsWith(".cs"))
                {
                    continue;
                }

                Debug.Log("此AB包:" + allBundles[i] + "下面包含的资源文件路径:" + allBundlePath[j]);
                resPathDic.Add(allBundlePath[j], allBundles[i]);
            }
        }

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

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

        AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(m_BunleTargetPath, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget);

        if (manifest == null)
        {
            Debug.LogError("AssetBundle 打包失败!");
        }
        else
        {
            Debug.Log("AssetBundle 打包完毕");
        }
    }
Exemplo n.º 7
0
        public static GameObject GetPrefab(string moduleName)
        {
            // Check in Resources
            var resourceResults = Resources.LoadAll(moduleName + "Prefab");

            if (resourceResults?.Count() != 0)
            {
                return(resourceResults.SingleOrDefault() as GameObject);
            }

            // check inside asset bundles available to the editor
            var prefabName = moduleName + "Prefab.prefab";

#if UNITY_EDITOR
            foreach (var assetPath in AssetDatabase.GetAssetPathsFromAssetBundle(moduleName.ToLower() + "assets"))
            {
                var fileName = Path.GetFileName(assetPath);
                if (fileName == prefabName)
                {
                    return(AssetDatabase.LoadAssetAtPath <GameObject>(assetPath));
                }
            }
#endif
            // check inside asset bundles available to the runtime
            if (!Application.ModuleAssetBundles.ContainsKey(moduleName))
            {
                return(null);
            }

            var assetBundle = Application.ModuleAssetBundles[moduleName];
            foreach (var assetName in assetBundle.GetAllAssetNames())
            {
                if (assetName.Contains(prefabName.ToLower()))
                {
                    var modulePrefab = assetBundle.LoadAsset <GameObject>(assetName);
                    return(modulePrefab);
                }
            }

            return(null);
        }
    public void Report()
    {
        try
        {
            int           idx = 0;
            StringBuilder sb  = new StringBuilder();

            string[] abnames = AssetDatabase.GetAllAssetBundleNames();
            bool     isFirst = true;
            AssetsReporterUtils.AddCurrenTimeVar(sb);
            AssetsReporterUtils.AddPlatformVar(sb, "");

            var dependsAssetBundle = new HashSet <string>();
            sb.Append("g_ab_report=[");
            foreach (var abname in abnames)
            {
                string[] paths = AssetDatabase.GetAssetPathsFromAssetBundle(abname);
                if (paths == null || paths.Length == 0)
                {
                    continue;
                }
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    sb.Append(",");
                }
                CreateAssetData(sb, abname, paths);
                ++idx;
                EditorUtility.DisplayProgressBar("AssetBundleReport", abname, idx / (float)abnames.Length);
            }
            sb.Append("];");
            File.WriteAllText("AssetsReporter/result/report_ab.js", sb.ToString());
        }
        finally
        {
            EditorUtility.ClearProgressBar();
        }
    }
Exemplo n.º 9
0
        /// <summary>
        /// 打包
        /// </summary>
        static void BuidAssetBundle()
        {
            string[] allBundles = AssetDatabase.GetAllAssetBundleNames();
            //key 全路径 value 包名
            Dictionary <string, string> resPathDic = new Dictionary <string, string>();

            for (int i = 0; i < allBundles.Length; i++)
            {
                string[] allBundlePath = AssetDatabase.GetAssetPathsFromAssetBundle(allBundles[i]);
                for (int j = 0; j < allBundlePath.Length; j++)
                {
                    if (allBundlePath[j].EndsWith(".cs"))
                    {
                        continue;
                    }

                    Debug.Log("此aB包:" + allBundles[i] + "下面包含资源文件路径:" + allBundlePath[j]);
                    if (ValidPaht(allBundlePath[j]))
                    {
                        resPathDic.Add(allBundlePath[j], allBundles[i]);
                    }
                }
            }

            DeletAB();
            //生成自己的AB包配置表
            WriteData(resPathDic);

            AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(BundleTargetPath,
                                                                           BuildAssetBundleOptions.ChunkBasedCompression,
                                                                           EditorUserBuildSettings.activeBuildTarget);

            if (manifest == null)
            {
                Debug.LogError("AssetBundle打包失败");
            }
            else
            {
                Debug.Log("AssetBundle 打包完毕");
            }
        }
Exemplo n.º 10
0
        static void BunildAssetBundle(AF_ABConfig abConfig)
        {
            string[] allBundles = AssetDatabase.GetAllAssetBundleNames();
            //key : 为全路径 value :为名字
            Dictionary <string, string> resPathDic = new Dictionary <string, string>();

            for (int i = 0; i < allBundles.Length; i++)
            {
                string[] allBundlePath = AssetDatabase.GetAssetPathsFromAssetBundle(allBundles[i]);
                for (int j = 0; j < allBundlePath.Length; j++)
                {
                    //判断有没有包含脚本文件
                    if (allBundlePath[j].EndsWith(".cs"))
                    {
                        continue;
                    }

                    //Debug.Log("此AB包:" + allBundles[i] + "下面包含的资源文件路径:" + allBundlePath[j]);
                    if (ValidPath(allBundlePath[j]))
                    {
                        resPathDic.Add(allBundlePath[j], allBundles[i]);
                    }
                }
            }

            //现在已经设置好了在这一次要打包的AB包,因此要清除无用的AB包,比如之前存在的AB包
            DeleteAB();
            //生成自己的配置表
            WriteData(resPathDic, abConfig.configWritingMode, abConfig.packageABType);

            AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(m_BundleTargetPath, BuildAssetBundleOptions.ChunkBasedCompression, buildTarget);

            if (manifest == null)
            {
                AFLogger.EditorErrorLog("AssetBundle" + buildTarget.ToString() + "打包失败,请检查设置!");
            }
            else
            {
                AFLogger.d("AssetBundle" + buildTarget.ToString() + "打包完毕");
            }
        }
Exemplo n.º 11
0
        static void BuildAssetBundle()
        {
            if (!Directory.Exists("Assets/AssetBundles"))
            {
                Directory.CreateDirectory("Assets/AssetBundles");
            }

            // Make sure all assets in level editor bundles are marked with pb_MetaData
            foreach (string bundle_name in AssetDatabase.GetAllAssetBundleNames())
            {
                if (pb_Config.AssetBundle_Names.Any(x => x.IndexOf(bundle_name, StringComparison.OrdinalIgnoreCase) >= 0))
                {
                    foreach (string asset_path in AssetDatabase.GetAssetPathsFromAssetBundle(bundle_name))
                    {
                        SetMetadata(asset_path, bundle_name);
                    }
                }
            }

            BuildPipeline.BuildAssetBundles("Assets/AssetBundles", BuildAssetBundleOptions.UncompressedAssetBundle | BuildAssetBundleOptions.ForceRebuildAssetBundle);
        }
Exemplo n.º 12
0
    static public void BuildNeedAssetBundle()
    {
        string bundleName = "pplbundle222";

        if (!Directory.Exists(Application.dataPath + "/AssetBundles"))
        {
            Directory.CreateDirectory(Application.dataPath + "/AssetBundles");
        }

        AssetBundleBuild[] buildBundles = new AssetBundleBuild[1];

        buildBundles[0].assetBundleName = bundleName;
        buildBundles[0].assetNames      = AssetDatabase.GetAssetPathsFromAssetBundle(bundleName);

        BuildPipeline.BuildAssetBundles(
            Application.dataPath + "/AssetBundles", // 빌드된 에셋 번들이 생성될 경로
            buildBundles,                           // 빌드할 에셋 번들들의 정보
            BuildAssetBundleOptions.None,           // 에셋 번들 빌드 옵션
            BuildTarget.StandaloneWindows           // 에셋 번들의 타겟 플랫폼
            );
    }
Exemplo n.º 13
0
        private static Object LoadEditorAsset(string assetBundleName, string assetName)
        {
#if UNITY_EDITOR
            var paths = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);

            if (paths != null)
            {
                foreach (string s in paths)
                {
                    var currentAssetName = Path.GetFileNameWithoutExtension(s);
                    var currentAsset     = AssetDatabase.LoadAssetAtPath <Object>(s);

                    if (currentAssetName == assetName)
                    {
                        return(currentAsset);
                    }
                }
            }
#endif
            return(null);
        }
Exemplo n.º 14
0
        static void BuildSomeAssetBundles()
        {
            List <AssetBundleBuild> list = new List <AssetBundleBuild>();

            //需要build 什么就写在这
            string[] bundleNames = new string[] { };
            for (int i = 0; i < bundleNames.Length; i++)
            {
                AssetBundleBuild build = new AssetBundleBuild();
                build.assetBundleName = bundleNames[i];
                build.assetNames      = AssetDatabase.GetAssetPathsFromAssetBundle(build.assetBundleName);
                list.Add(build);
            }

            BuildSomeAssetBundles(Application.dataPath + "/StreamingAssets/SimpleAssetBundles", list.ToArray());

            File.Delete(Application.dataPath + "/StreamingAssets/AssetBundlesMiniGame/" + "AssetBundlesMiniGame");
            File.Delete(Application.dataPath + "/StreamingAssets/AssetBundlesMiniGame/" + "AssetBundlesMiniGame.manifest");

            AssetDatabase.Refresh();
        }
Exemplo n.º 15
0
    //在打包之前建立资源路径和AB名字的关系
    public static void SetBuildAbDicInfo()
    {
        string[] allBundleName = AssetDatabase.GetAllAssetBundleNames();
        for (int i = 0; i < allBundleName.Length; i++)
        {
            string[] allAssetPath = AssetDatabase.GetAssetPathsFromAssetBundle(allBundleName[i]);
            for (int j = 0; j < allAssetPath.Length; j++)
            {
                if (allAssetPath[j].EndsWith(".cs"))
                {
                    continue;
                }

                //是否是有效路径判断
                if (IsEffectivePath(allAssetPath[j]))
                {
                    m_AllAssetBundleDic.Add(allAssetPath[j], allBundleName[i]);
                }
            }
        }
    }
Exemplo n.º 16
0
        /// <summary>
        /// Create BundleInfo
        /// </summary>
        /// <param name="rootFolder">The AssetBundle directory.</param>
        /// <param name="filename">The filename</param>
        /// <param name="manifest"></param>
        /// <returns></returns>
        protected virtual BundleInfo CreateBundleInfo(string rootFolder, string filename, AssetBundleManifest manifest)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return(null);
            }

            string   path       = rootFolder + "/" + filename;
            FileInfo file       = new FileInfo(path);
            string   bundleName = this.RemoveExtensionAndHash(filename);
            long     size       = file.Length;
            uint     crc        = 0;

            BuildPipeline.GetCRCForAssetBundle(file.FullName, out crc);
            Hash128 hash    = manifest.GetAssetBundleHash(filename);
            string  variant = file.Extension.Replace(".", "");

            string[] dependencies = manifest.GetDirectDependencies(filename);
            string[] assets       = AssetDatabase.GetAssetPathsFromAssetBundle(string.IsNullOrEmpty(variant) ? bundleName : string.Format("{0}.{1}", bundleName, variant));
            return(new BundleInfo(bundleName, variant, hash, crc, size, filename, true, assets, dependencies));
        }
Exemplo n.º 17
0
        public static void RemoveBundle(this SerializedProperty bundles, int index)
        {
            if (index < 0 || index >= bundles.arraySize)
            {
                return;
            }

            var    bundle = bundles.GetArrayElementAtIndex(index);
            string name   = bundle.FindPropertyRelative(Bundle.nameOfName).stringValue;

            string[] paths = AssetDatabase.GetAssetPathsFromAssetBundle(name);
            foreach (string path in paths)
            {
                AssetImporter.GetAtPath(path).assetBundleName = string.Empty;
            }
            AssetDatabase.RemoveAssetBundleName(name, true);

            bundles.MoveArrayElement(index, bundles.arraySize - 1);
            --bundles.arraySize;
            bundles.serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 18
0
        public void Rename(string newName)
        {
            if (displayName == newName)
            {
                return;
            }

            string[] paths = AssetDatabase.GetAssetPathsFromAssetBundle(displayName);
            foreach (string path in paths)
            {
                var importer = AssetImporter.GetAtPath(path);
                importer.assetBundleName = newName;
            }

            AssetDatabase.RemoveAssetBundleName(displayName, false);

            var nameSp = model.FindPropertyRelative(Bundle.nameOfName);

            nameSp.stringValue = newName;
            _bundlesSp.serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 19
0
    //private readonly string[] mIpAdressTypeName = new string[]{"自定义", "内网测试", "外网测试", "安卓正式", "AppStore", "周望远", "杨泽浪"};

    //private readonly string[] mIpAdressTypeName = new string[] { "自定义", "内网测试", "外网测试", "安卓正式", "AppStore", "周望远", "杨泽浪" };

    void OnEnable()
    {
        mTarget = target as DynamicPrefable;

        if (!string.IsNullOrEmpty(mTarget.assetBundlePath))
        {
            var mainPath = AssetDatabase.GetAssetPathsFromAssetBundle(mTarget.assetBundlePath)[0];
            var go       = AssetDatabase.LoadMainAssetAtPath(mainPath) as GameObject;
            tmpGameObject = go;
            AssetImporter assetImporter = AssetImporter.GetAtPath(mainPath);

            mTarget.assetBundlePath = assetImporter.assetBundleName;
            mTarget.prefableName    = go.name;
        }

        // while(mTarget.transform.childCount >0){
        //  GameObject.DestroyImmediate (mTarget.transform.GetChild (0).gameObject);
        // }

        // mTarget.Prview();
    }
    private void UpdateAssetSizeRecursive()
    {
        foreach (var asset in m_assets)
        {
            asset.Value.m_totalBytesWithDeps = -1;
        }

        foreach (var bundleName in AssetDatabase.GetAllAssetBundleNames())
        {
            Bundle bundle;
            if (!m_bundles.TryGetValue(bundleName, out bundle))
            {
                continue;
            }

            HashSet <string> bundleAssets = null;
            foreach (var assetPath in AssetDatabase.GetAssetPathsFromAssetBundle(bundleName))
            {
                Asset asset;
                if (!m_assets.TryGetValue(assetPath, out asset))
                {
                    continue;
                }

                var visited = new HashSet <string>();
                RecurseAssetSize(asset, asset.m_directBundle, visited);

                if (bundleAssets != null)
                {
                    bundleAssets.UnionWith(visited);
                }
                else
                {
                    bundleAssets = visited;
                }
            }

            bundle.m_totalBytes = bundleAssets != null?bundleAssets.Sum(a_b => m_assets[a_b].m_bytes) : 0;
        }
    }
Exemplo n.º 21
0
    private static void BunildAssetBundle(string fileName = null)
    {
        string[] allBundles = AssetDatabase.GetAllAssetBundleNames();
        //key为全路径,value为包名
        Dictionary <string, string> resPathDic = new Dictionary <string, string>();

        for (int i = 0; i < allBundles.Length; i++)
        {
            string[] allBundlePath = AssetDatabase.GetAssetPathsFromAssetBundle(allBundles[i]);
            for (int j = 0; j < allBundlePath.Length; j++)
            {
                if (allBundlePath[j].EndsWith(".cs"))
                {
                    continue;
                }

                resPathDic.Add(allBundlePath[j], allBundles[i]);
            }
        }

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

        DeleteAB();
        //BuildPipeline.SetAssetBundleEncryptKey("0123456789abcdef");//加密ab包
        AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(m_BuildTarget, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);

        //AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(m_BunleTargetPath, BuildAssetBundleOptions.ChunkBasedCompression |BuildAssetBundleOptions.EnableProtection, EditorUserBuildSettings.activeBuildTarget);//加密ab包需要的打包方式
        if (manifest == null)
        {
            Debug.LogError("AssetBundle 打包失败!");
        }
        else
        {
            Debug.Log("AssetBundle 打包完毕");
        }
        DeleteMainfest();
    }
Exemplo n.º 22
0
        /// <summary>
        /// 获得目录下可以打包的AssetBundleBuild
        /// </summary>
        /// <param name="assetPaths"></param>
        /// <returns></returns>
        public static List <AssetBundleBuild> GetAssetBundleBuilds(string[] assetPaths)
        {
            List <AssetBundleBuild> assetBundleBuilds = new List <AssetBundleBuild>();
            HashSet <string>        processedBundles  = new HashSet <string>();

            // Get asset bundle names from selection
            foreach (var assetPath in assetPaths)
            {
                var importer = AssetImporter.GetAtPath(assetPath);

                if (importer == null)
                {
                    continue;
                }

                // Get asset bundle name & variant
                var assetBundleName     = importer.assetBundleName;
                var assetBundleVariant  = importer.assetBundleVariant;
                var assetBundleFullName = string.IsNullOrEmpty(assetBundleVariant)
                    ? assetBundleName
                    : assetBundleName + "." + assetBundleVariant;

                // Only process assetBundleFullName once. No need to add it again.
                if (processedBundles.Contains(assetBundleFullName))
                {
                    continue;
                }

                processedBundles.Add(assetBundleFullName);

                AssetBundleBuild build = new AssetBundleBuild();

                build.assetBundleName    = assetBundleName;
                build.assetBundleVariant = assetBundleVariant;
                build.assetNames         = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleFullName);

                assetBundleBuilds.Add(build);
            }
            return(assetBundleBuilds);
        }
Exemplo n.º 23
0
    //[MenuItem("Tools/Generate AB Relation")]
    public static void GenerateRelation()
    {
        DicABRelation.Clear();
        var abNames = AssetDatabase.GetAllAssetBundleNames();

        foreach (var abname in abNames)
        {
            //Live2d资源不要放到判定文件中
            if (abname.Contains("reslive2d"))
            {
                continue;
            }
            var paths = AssetDatabase.GetAssetPathsFromAssetBundle(abname);
            foreach (var eachPath in paths)
            {
                string assetName = Path.GetFileNameWithoutExtension(eachPath);
                var    TypeAsset = AssetDatabase.GetMainAssetTypeAtPath(eachPath);
                Generate(abname, assetName, TypeAsset);
                //Debug.LogError($"eachPath:{eachPath} TypeAsset:{TypeAsset}");
                string ext = Path.GetExtension(eachPath);
                if (ext.Contains("jpg") || ext.Contains("png") || ext.Contains("tga"))
                {
                    Generate(abname, assetName, typeof(UnityEngine.Sprite));
                }
            }
        }
        #region print info
        foreach (var item in DicABRelation)
        {
            foreach (var abAndType in item.Value)
            {
                Debug.Log($"assetName:{item.Key} TypeAsset:{abAndType.Key} abName:{abAndType.Value}");
            }
        }
        #endregion
        //生成配置文件
        GenerateABConfigeFile(Path.Combine(Application.dataPath, "Bundles/ABConfig"));
        //不能热更代码Mapping没有意义
        //UpdateABMappingCode();
    }
Exemplo n.º 24
0
    static public void BuildAssetBundleForLua()
    {
        //复制到LuaBundle目录下,准备打Bundle
        if (Directory.Exists(luaBundlePath))
        {
            FileUtil.DeleteFileOrDirectory(luaBundlePath);
        }
        FileUtil.CopyFileOrDirectory(LuaManager.LuaPath, luaBundlePath);
        string[] filePaths = Directory.GetFiles(luaBundlePath, "*", SearchOption.AllDirectories);
        foreach (var filePath in filePaths)
        {
            if (filePath.IndexOf(".meta") == -1)
            {
                File.Move(filePath, filePath + ".bytes");
            }
        }
        AssetDatabase.Refresh();
        //设置bundle名
        var importer = AssetImporter.GetAtPath(luaBundlePath);

        importer.assetBundleName = "lua";
        AssetBundleBuild build = new AssetBundleBuild();

        build.assetBundleName = importer.assetBundleName;
        build.assetNames      = AssetDatabase.GetAssetPathsFromAssetBundle(importer.assetBundleName);
        //Build AssetBundle
        if (Directory.Exists(assetBundlePath))
        {
            FileUtil.DeleteFileOrDirectory(assetBundlePath);
        }
        Directory.CreateDirectory(assetBundlePath);
        BuildPipeline.BuildAssetBundles(
            assetBundlePath,
            new AssetBundleBuild[] { build },
            BuildAssetBundleOptions.None,
            EditorUserBuildSettings.activeBuildTarget
            );
        AssetDatabase.Refresh();
    }
Exemplo n.º 25
0
        public void MarkAllAndSave(string saveTo)
        {
            AssetDatabase.RemoveUnusedAssetBundleNames();
            notInterestedOldAssets.Clear();
            allMarks.Clear();

            foreach (var bundle in AssetDatabase.GetAllAssetBundleNames())
            {
                foreach (var assetpath in AssetDatabase.GetAssetPathsFromAssetBundle(bundle))
                {
                    var asset = assetpath.Replace("\\", "/");
                    if (notInterestedOldAssets.ContainsKey(asset))
                    {
                        EditorLogger.Log("duplicate {0}", asset);
                    }
                    else
                    {
                        //EditorLogger.Log("old asset = {0}, bundle = {1}", asset, bundle);
                        notInterestedOldAssets.Add(asset, bundle);
                    }
                }
            }

            DoMark();

            foreach (var old in notInterestedOldAssets)
            {
                var importer = AssetImporter.GetAtPath(old.Key);
                importer.assetBundleName = null;
                EditorLogger.Log("unmark asset = {0}, bundle = {1}", old.Key, old.Value);
            }
            using (var sw = new StreamWriter(saveTo, false)) //no bom
            {
                foreach (var kv in allMarks)
                {
                    sw.WriteLine(kv.Key + "," + kv.Value);
                }
            }
        }
Exemplo n.º 26
0
        public static void CheckDuplicate()
        {
            asset2bundle = new Dictionary <string, string>();
            foreach (var bundle in AssetDatabase.GetAllAssetBundleNames())
            {
                foreach (var asset in AssetDatabase.GetAssetPathsFromAssetBundle(bundle))
                {
                    asset2bundle.Add(asset, bundle);
                }
            }

            Debug.Log("asset count=" + asset2bundle.Count);
            depasset2bundles = new Dictionary <string, DepInfo>();
            foreach (var kv in asset2bundle)
            {
                collectDep(kv.Key, kv.Value, 0);
            }

            int canSaveMemSize = 0;

            foreach (var kv in depasset2bundles)
            {
                var depinfo = kv.Value;
                if (depinfo.containingABs.Count > 1)
                {
                    depinfo.memsize = calcSize(kv.Key);

                    Debug.Log(kv.Key + " count=" + depinfo.containingABs.Count + ", memsize=" +
                              depinfo.memsize);
                    foreach (var containingAB in depinfo.containingABs)
                    {
                        Debug.Log("    " + containingAB);
                    }
                    canSaveMemSize += depinfo.memsize * (depinfo.containingABs.Count - 1);
                }
            }

            Debug.Log("can save mem size=" + canSaveMemSize);
        }
Exemplo n.º 27
0
        /// <summary>
        /// name のアセットとサブアセットをアセットバンドルから読み込みます。
        /// </summary>
        /// <param name="name">アセット名</param>
        /// <returns>該当するアセット</returns>
        public override UnityEngine.Object[] LoadAssetWithSubAssets(string name)
        {
            if (!m_IsDone)
            {
                throw new System.NullReferenceException();
            }

            Object[] result     = null;
            var      assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(nameWithVariant);

            if ((assetPaths != null) && (0 < assetPaths.Length))
            {
                result = assetPaths.Where(x => !x.EndsWith(".unity"))
                         .SelectMany(x => AssetDatabase.LoadAllAssetRepresentationsAtPath(x))
                         .ToArray();
            }
            if (result == null)
            {
                result = new Object[0];
            }
            return(result);
        }
Exemplo n.º 28
0
        /// <summary>
        /// アセットバンドルにあるすべてのシーンアセットのパス( *.unity アセットへのパス)を返します。
        /// </summary>
        /// <returns>すべてのシーンアセットのパス</returns>
        public override string[] GetAllScenePaths()
        {
            if (!m_IsDone)
            {
                throw new System.NullReferenceException();
            }

            string[] result     = null;
            var      assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(nameWithVariant);

            if ((assetPaths != null) && (0 < assetPaths.Length))
            {
                result = assetPaths.Where(x => x.EndsWith(".unity"))
                         .Select(x => x.ToLower())
                         .ToArray();
            }
            if (result == null)
            {
                result = new string[0];
            }
            return(result);
        }
Exemplo n.º 29
0
        public static void Build(AssetBundleManifest manifest)
        {
            List <string> contentList = new List <string>();

            string[] allAssetBundleNames = manifest.GetAllAssetBundles();
            foreach (var assetBundleName in allAssetBundleNames)
            {
                //寻找项目中assetBundle_name为assetBundle_name的asset的路径,以Asset/开头
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                foreach (string assetPath in assetPaths)
                {
                    string content = string.Format("{0}{1}{2}", assetBundleName, StringConst.String_Comma, assetPath);
                    contentList.Add(content);
                }
            }

            contentList.Sort();

            string fileOutputPath = BuildConst.AssetPathMap_File_Name.WithRootPath(BuildConst.Output_Path);

            StdioUtil.WriteTextFile(new FileInfo(fileOutputPath), contentList, false);
        }
Exemplo n.º 30
0
        public static bool ClearAllDepABName(bool refreshAndSaveAssets)
        {
            var needRefresh = false;

            foreach (var abName in AssetDatabase.GetAllAssetBundleNames())
            {
                if (ABConfig.IsDepABName(abName))
                {
                    foreach (var path in AssetDatabase.GetAssetPathsFromAssetBundle(abName))
                    {
                        needRefresh |= ClearAB(path);
                    }
                    AssetDatabase.RemoveAssetBundleName(abName, true);
                }
            }
            if (needRefresh && refreshAndSaveAssets)
            {
                AssetDatabase.Refresh();
                AssetDatabase.SaveAssets();
            }
            return(true);
        }