public void OnPreprocessBuild(BuildTarget target, string path)
        {
            BuildABScript.CopyAssetBundlesTo(Path.Combine(Application.streamingAssetsPath, LWUtility.AssetBundles));
            var platformName = BuildABScript.GetPlatformName();
            var searchPath   = Path.Combine(Path.Combine(Application.streamingAssetsPath, LWUtility.AssetBundles),
                                            platformName);

            if (!Directory.Exists(searchPath))
            {
                return;
            }
            var files = Directory.GetFiles(searchPath, "*.manifest", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var info = new FileInfo(file);
                if (info.Exists)
                {
                    info.Delete();
                }
            }

            files = Directory.GetFiles(searchPath, "*.meta", SearchOption.AllDirectories);
            foreach (var item in files)
            {
                var info = new FileInfo(item);
                info.Delete();
            }
        }
        private void ResetManifest()
        {
            var manifest = BuildABScript.GetManifest();

            manifest.assets  = new AssetRef[0];
            manifest.dirs    = new string[0];
            manifest.bundles = new string[0];
            EditorUtility.SetDirty(manifest);
            AssetDatabase.SaveAssets();
            BuildCahe();
        }
        private void BuildCahe()
        {
            _lastModify = File.GetLastWriteTime(LWUtility.AssetsManifestAsset);
            var manifest = BuildABScript.GetManifest();
            var sb       = new StringBuilder(512);

            for (var i = 0; i < manifest.bundles.Length; i++)
            {
                sb.AppendLine(string.Format("bundle[{0}]={1}", i, manifest.bundles[i]));
            }

            sb.AppendLine();
            for (var i = 0; i < manifest.dirs.Length; i++)
            {
                sb.AppendLine(string.Format("dir[{0}]={1}", i, manifest.dirs[i]));
            }
            sb.AppendLine();

            for (int i = 0; i < manifest.assets.Length; i++)
            {
                var assetData = manifest.assets[i];
                var desc      = string.Format("asset[{0}] = bundle:{1}, dir:{2}, name:{3}", i, assetData.bundle, assetData.dir, assetData.name);
                sb.AppendLine(desc);
            }


            _manifestStr = sb.ToString();
            _lineIndex.Clear();
            _lineIndex.Add(-1);
            for (var i = 0; i < _manifestStr.Length; i++)
            {
                if (_manifestStr[i] == '\n')
                {
                    _lineIndex.Add(i);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// 对指定的文件夹进行标记
        /// </summary>
        /// <param name="ResPath">文件夹路径</param>
        /// <param name="isClear">是否为清空标记</param>
        public static void MarkAssets(string ResPath, bool isClear = false)
        {
            var assetsManifest = BuildABScript.GetManifest();
            //1.环境准备
            string rootPath = Path.Combine(Application.dataPath, ResPath.Substring(7)); //去掉ResPath的Assets
                                                                                        //扫描所有文件
            var allFiles = Directory.GetFiles(rootPath, "*.*", SearchOption.AllDirectories);
            var fileList = new List <string>(allFiles);

            //剔除不打包的部分
            for (int i = fileList.Count - 1; i >= 0; i--)
            {
                var fi        = allFiles[i];
                var extension = Path.GetExtension(fi.ToLower());
                //
                if (extension.ToLower() == ".meta" || extension.ToLower() == ".cs" || extension.ToLower() == ".js")
                {
                    fileList.RemoveAt(i);
                }
            }
            for (int i = 0; i < fileList.Count; i++)
            {
                //替换路径中的反斜杠为正斜杠       
                string strTempPath = fileList[i].Replace(@"\", "/");
                //截取我们需要的路径
                string path = strTempPath.Substring(strTempPath.IndexOf("Assets"));
                //根据路径加载资源
                if (Directory.Exists(path) || path.EndsWith(".cs", System.StringComparison.CurrentCulture))
                {
                    continue;
                }
                if (EditorUtility.DisplayCancelableProgressBar("标记资源", path, i * 1f / fileList.Count))
                {
                    break;
                }
                var dir  = Path.GetDirectoryName(path);
                var name = Path.GetFileNameWithoutExtension(path);
                if (dir == null)
                {
                    continue;
                }
                dir = dir.Replace("\\", "/") + "/";
                if (name == null)
                {
                    continue;
                }

                var assetBundleName = dir + name;//TrimedAssetBundleName(Path.Combine(dir, name),ResPath);
                if (!isClear)
                {
                    SetAssetBundleNameAndVariant(path, assetBundleName.ToLower(), null);
                }
                else
                {
                    SetAssetBundleNameAndVariant(path, null, null);
                }
            }
            EditorUtility.SetDirty(assetsManifest);
            AssetDatabase.SaveAssets();
            EditorUtility.ClearProgressBar();
        }