Ejemplo n.º 1
0
        /// <summary>
        /// 添加MainManifest对象.
        /// </summary>
        public void AddMainManifestAssetsTarget()
        {
            string manifestBundleId = AssetBundleDirNameOfNormal;

            if (string.IsNullOrEmpty(manifestBundleId) == true)
            {
                return;
            }

            string path = GetLocalBundleFilePath(
                manifestBundleId, TUploadFileType.MainManifest, false);

            if (File.Exists(path) == false)
            {
                return;
            }

            BundleMap bm = new BundleMap();

            bm.ID   = manifestBundleId;
            bm.Type = TBundleType.Normal;
            int index = path.IndexOf(manifestBundleId);

            bm.Path = path.Substring(0, index);

            // 添加对象
            this.AddTarget(bm, TUploadFileType.MainManifest);
        }
Ejemplo n.º 2
0
            protected string[][] Parse(AbstractTexture texture)
            {
                TextAsset targetFile = Resources.Load <TextAsset>("assetBundleInfo");

                BundleMap map = JsonUtility.FromJson <BundleMap>(targetFile.text);

                string[][] textures = null;
                foreach (var raceInfo in map.races)
                {
                    if (raceInfo.race.Equals(texture.CharacterRace))
                    {
                        foreach (var textureInfo in raceInfo.textures)
                        {
                            if (textureInfo.type.Equals(texture.Type))
                            {
                                textures = new string[textureInfo.texturePaths.Count][];
                                int i = 0;
                                foreach (var textureColors in textureInfo.texturePaths)
                                {
                                    textures[i] = new string[textureColors.colors.Count];
                                    int j = 0;
                                    foreach (var texturePath in textureColors.colors)
                                    {
                                        textures[i][j] = texturePath.path;
                                        j++;
                                    }
                                    i++;
                                }
                            }
                        }
                    }
                }
                return(textures);
            }
Ejemplo n.º 3
0
            /*
             * Parse Fx meshes from AssetBundle
             */
            private IEnumerator ParseFx(AbstractFXMesh mesh, Action <GameObject[]> callback)
            {
                TextAsset targetFile = Resources.Load <TextAsset>("assetBundleInfo");

                GameObject[] meshObjects = null;

                BundleMap map = JsonUtility.FromJson <BundleMap>(targetFile.text);

                foreach (var raceInfo in map.races)
                {
                    if (raceInfo.race.Equals(mesh.CharacterRace))
                    {
                        foreach (var meshInfo in raceInfo.fxs)
                        {
                            if (meshInfo.type.Equals(mesh.FxType))
                            {
                                meshObjects = new GameObject[meshInfo.meshPaths.Count];

                                int i = 0;
                                foreach (var meshPathInfo in meshInfo.meshPaths)
                                {
                                    yield return(LoadMeshCoroutine(meshPathInfo.path, (GameObject meshGameObject) =>
                                    {
                                        meshObjects[i] = meshGameObject;
                                    }));

                                    i++;
                                }
                            }
                        }
                    }
                }
                callback.Invoke(meshObjects);
            }
		private bool UpdateHtmlFile(ref string html, string bundleType, BundleMap map, IEnumerable<Match> matches)
		{
			var result = true;
			var builder = new StringBuilder();
			var start = 0;
			foreach (var match in matches)
			{
				var key = match.Groups["key"].Value;
				if (!map.ContainsKey(key))
				{
					Log.LogError("{0} bundle '{1}' not found.", CultureInfo.InvariantCulture.TextInfo.ToTitleCase(bundleType), match.Groups["key"].Value);
					result = false;
					continue;
				}

				builder.Append(html.Substring(start, match.Index - start));
				builder.AppendFormat(BeginBundleMarker, bundleType, key);
				builder.AppendLine();
				builder.Append(map[key].Html);
				builder.AppendFormat(EndBundleMarker, bundleType, key);

				start = match.Index + match.Length;
			}
			if (start < html.Length)
			{
				builder.Append(html.Substring(start));
			}

			html = builder.ToString();
			return result;
		}
Ejemplo n.º 5
0
    protected static void UpdateBundles(Config[] configs)
    {
        var bundleMap = new BundleMap();

        for (int i = 0; i < configs.Length; i++)
        {
            var raceName = configs[i].folderName;

            var raceMap = new RaceMap();
            raceMap.race       = raceName;
            raceMap.configPath = ParseConfigPath(configs[i]);
            raceMap.prefabPath = ParsePrefabPath(configs[i]);
            raceMap.textures   = ParseBundleTextures(raceName);
            raceMap.meshes     = ParseBundleMeshes(raceName);
            raceMap.fxs        = ParseBundleFXMeshes(raceName);

            bundleMap.races.Add(raceMap);
        }

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

        using (FileStream fs = new FileStream("Assets/Resources/assetBundleInfo.json", FileMode.Create))
        {
            using (StreamWriter writer = new StreamWriter(fs))
            {
                writer.Write(JsonUtility.ToJson(bundleMap));
            }
        }
        AssetDatabase.Refresh();
    }
Ejemplo n.º 6
0
            /*
             * Parse Armor and weapon meshes from AssetBundle
             */
            private IEnumerator Parse(AbstractMesh mesh, Action <GameObject[], AbstractTexture[]> callback)
            {
                TextAsset targetFile = Resources.Load <TextAsset>("assetBundleInfo");

                GameObject[]      meshObjects = null;
                AbstractTexture[] textures    = null;

                var textureLoader = new TextureLoader();

                BundleMap map = JsonUtility.FromJson <BundleMap>(targetFile.text);

                foreach (var raceInfo in map.races)
                {
                    if (raceInfo.race.Equals(mesh.CharacterRace))
                    {
                        foreach (var meshInfo in raceInfo.meshes)
                        {
                            if (meshInfo.type.Equals(mesh.MeshType))
                            {
                                meshObjects = new GameObject[meshInfo.meshPaths.Count];
                                textures    = new AbstractTexture[meshInfo.meshPaths.Count];

                                int i = 0;
                                foreach (var meshPathInfo in meshInfo.meshPaths)
                                {
                                    yield return(LoadMeshCoroutine(meshPathInfo.modelPath,
                                                                   (GameObject meshGameObject) =>
                                    {
                                        meshObjects[i] = meshGameObject;
                                    }));

                                    var texturePaths = new string[meshPathInfo.textures.Count][];
                                    int j            = 0;
                                    foreach (var texture in meshPathInfo.textures)
                                    {
                                        texturePaths[j] = new string[texture.colors.Count];
                                        int k = 0;
                                        foreach (var color in texture.colors)
                                        {
                                            texturePaths[j][k] = color.path;
                                            k++;
                                        }
                                        j++;
                                    }

                                    textures[i] = new MeshTexture(textureLoader, mesh.CharacterRace, texturePaths);
                                    i++;
                                }
                            }
                        }
                    }
                }
                callback.Invoke(meshObjects, textures);
            }
Ejemplo n.º 7
0
        /// <summary>
        /// 添加对象.
        /// </summary>
        /// <param name="iTarget">对象.</param>
        /// <param name="iFileType">上传文件类型.</param>
        /// <param name="iHashCode">HashCode(Unity3d打包生成).</param>
        public void AddTarget(
            BundleMap iTarget, TUploadFileType iFileType, string iHashCode = null)
        {
            if (iTarget == null)
            {
                return;
            }
            UploadItem _item    = null;
            string     filePath = GetLocalBundleFilePath(
                iTarget.ID, iFileType, (TBundleType.Scene == iTarget.Type));
            string checkCode = null;

            string dataSize = null;

            if ((false == string.IsNullOrEmpty(filePath)) &&
                (true == File.Exists(filePath)))
            {
                if (TCheckMode.Unity3d_Hash128 == this.CheckMode)
                {
                    checkCode = iHashCode;
                }
                else
                {
                    checkCode = GetFileMD5(filePath);
                }
                FileInfo fileInfo = new FileInfo(filePath);
                dataSize = fileInfo.Length.ToString();
            }
            else
            {
                this.Warning("AddTarget()::Target File is not exist!!!(target:{0})", filePath);
            }

            bool _exist = this.isTargetExist(iTarget.ID, iFileType, out _item);

            if (false == _exist)
            {
                _item           = this.CreateUploadItem(iTarget.ID, iTarget.Type, iFileType);
                _item.CheckCode = checkCode;
                _item.DataSize  = dataSize;
            }
            else
            {
                if ((false == string.IsNullOrEmpty(checkCode)) &&
                    (false == checkCode.Equals(_item.CheckCode)))
                {
                    _item.CheckCode = checkCode;
                    _item.DataSize  = dataSize;
                    _item.Uploaded  = false;
                }
            }
            UtilsAsset.SetAssetDirty(this);
        }
Ejemplo n.º 8
0
            private IEnumerator LoadConfigsCoroutine(Action <Config[]> callback)
            {
                TextAsset targetFile = Resources.Load <TextAsset>("assetBundleInfo");

                var       configs = new List <Config>();
                BundleMap map     = JsonUtility.FromJson <BundleMap>(targetFile.text);

                foreach (var raceInfo in map.races)
                {
                    yield return(LoadConfigCoroutine(raceInfo.configPath, raceInfo.prefabPath, (Config config) =>
                    {
                        configs.Add(config);
                    }));
                }
                callback.Invoke(configs.ToArray());
            }
		private BundleMap LoadBundles(Context context, string type, string template)
		{
			var bundleFiles = context.Bundles
				.Where(b => b.EndsWith("." + type + ".bundle", StringComparison.OrdinalIgnoreCase))
				.ToList();

			var map = new BundleMap(bundleFiles.Count);
			foreach (var bundleFile in bundleFiles)
			{
				try
				{
					var bundle = new Bundle(context, bundleFile);
					Log.LogMessage("Bundle: " + bundleFile);
					Log.LogMessage("\tType: " + type);
					Log.LogMessage("\tKey: " + bundle.Key);
					Log.LogMessage("\tMinify: " + bundle.Minify);
					Log.LogMessage("\tOutputDirectory: " + bundle.OutputDirectory);

					if (context.DebugBuild)
					{
						var html = new StringBuilder();
						foreach (var file in bundle.Files)
						{
							html.AppendFormat(template, file.Url);
							Log.LogMessage("\tFile: " + file.Path);
							Log.LogMessage("\t\tUrl: " + file.Url);
						}
						bundle.Html = html.ToString();
					}
					else
					{
						bundle.Html = String.Format(template, bundle.BundleFile.Url);
						Log.LogMessage("\tUrl: " + bundle.BundleFile.Url);
					}

					map.Add(bundle.Key, bundle);
					Log.LogMessage("Found bundle '{0}':\r\n{1}", bundle.Key, bundle.Html);
				}
				catch (Exception ex)
				{
					Log.LogError("Failed to load or parse bundle file '{0}'\r\n{1}", bundleFile, ex);
				}
			}

			return map;
		}
Ejemplo n.º 10
0
    public static T LoadResource <T>(string a_path, AssetType a_type) where T : UnityEngine.Object
    {
#if DEBUG
        if (resourceMap == null)
        {
            DebugInstantiateManager();
        }
#endif


        int    bundleNameEndIndex = a_path.IndexOf("/", 0, StringComparison.Ordinal);
        string bundleName         = a_path.Substring(0, bundleNameEndIndex);
        // Try to map to bundle

        BundleMap bundleMap = null;
        string    finalPath;
        PathMap   pathMap = null;

        bool found = false;
        if (resourceMap.bundles.TryGetBundleMap(bundleName, out bundleMap)) // Bundle Found
        {
            if (bundleMap.TryGetValue(a_type, out pathMap))
            {
                found = pathMap.TryGetValue(a_path.GetHashCode(), out finalPath);
            }
        }

        if (!found) // Search Global Asset Map
        {
            pathMap = resourceMap.types[(int)a_type];
            int pathHash = a_path.GetHashCode();
            found = pathMap.TryGetValue(pathHash, out finalPath);
        }

        if (!found)
        {
            Debug.LogError("ResourceManager was unable to find an Asset with path " + a_path + " of type " + a_type);
            return(null);
        }

        return(Resources.Load <T>(a_path));
    }
Ejemplo n.º 11
0
    private static void MapResBundleFolder(string a_bundleName, string a_bundlePath)
    {
        string dirName = a_bundleName;

        BundleMap  bundleMap  = null;
        BundleName bundleName = new BundleName(dirName);

        if (currentBundleMap.TryGetValue(bundleName, out bundleMap) == false) // No Path Map Exists
        {
            bundleMap = new BundleMap();
        }

        DirectoryInfo bundleDir = new DirectoryInfo(a_bundlePath);

        for (int i = 0; i < (int)bundleMap.Count; ++i)
        {
            AssetType type      = (AssetType)i;
            string    extension = AssetTypeExtensionLookup[type];
            RecursivelyMapBundleDir(bundleDir, bundleMap[type], currentTypeMaps[i], extension);
        }

        Debug.Log("Map Directory Complete!");
    }
Ejemplo n.º 12
0
    private static void MapResBundleFolder(DirectoryInfo a_bundleDir)
    {
        string dirName = a_bundleDir.Name;

        BundleMap  bundleMap  = null;
        BundleName bundleName = new BundleName(dirName);

        if (currentBundleMap.TryGetValue(bundleName, out bundleMap) == false) // No Path Map Exists
        {
            bundleMap = new BundleMap();
            currentBundleMap.Add(bundleName, bundleMap);
        }

        for (int i = 0; i < (int)AssetType.COUNT; ++i)
        {
            AssetType type = (AssetType)i;
            string    extension;

            if (AssetTypeExtensionLookup.TryGetValue(type, out extension) == false)
            {
                continue;
            }

            PathMap pathMap;
            if (bundleMap.TryGetValue(type, out pathMap) == false)
            {
                Debug.LogError("Failed to get path map of type " + type + " from bundlemap!");
                continue;
            }

            PathMap globalPathMap = currentTypeMaps[i];

            RecursivelyMapBundleDir(a_bundleDir, pathMap, globalPathMap, extension);
        }

        Debug.Log("Map Directory Complete!");
    }
Ejemplo n.º 13
0
        /// <summary>
        /// 打包资源文件
        /// </summary>
        /// <param name="buildTarget">Build target.</param>
        /// <param name="needCompress">If set to <c>true</c> need compress.</param>
        private static void BuildAssetBundle(BuildTarget buildTarget, bool needCompress = false)
        {
            const string funcBlock = "AssetBundlesBuild.BuildAssetBundle()";

            BuildLogger.OpenBlock(funcBlock);

            // 设置上传的打包类型
            UploadList.GetInstance().BuildTarget = buildTarget.ToString();

            BundlesConfig bcConfig = BundlesConfig.GetInstance();

            if ((null == bcConfig) || (0 >= bcConfig.Resources.Count))
            {
                BuildLogger.LogError("BuildAssetBundle::BundlesConfig is invalid!!!");
                return;
            }

            // 清空依赖关系列表
            BundlesMap bundlesMap = BundlesMap.GetInstance();

            if (null == bundlesMap)
            {
                BuildLogger.LogError("BuildAssetBundle::bundlesMap is invalid!!!");
                return;
            }
            bundlesMap.Clear();

            List <BundleResource> allConfig = bcConfig.Resources;

            // make bundle config
            foreach (BundleResource bc in allConfig)
            {
                // filter file
                if (bc.Mode == BundleMode.OneDir)
                {
                    string    bundleId = BundlesMap.GetBundleID(bc.Path);
                    BundleMap bm       = bundlesMap.GetOrCreateBundlesMap(bundleId);

                    bm.ID   = bundleId;
                    bm.Path = bc.Path;

                    // 取得当前目录的文件列表
                    List <string> files = GetAllFiles(bc.Path);

                    // 遍历文件列表
                    foreach (string file in files)
                    {
                        // .DS_Store文件
                        if (file.EndsWith(".DS_Store") == true)
                        {
                            continue;
                        }
                        // *.meta文件
                        if (file.EndsWith(".meta") == true)
                        {
                            continue;
                        }

                        // 若为忽略文件,则跳过
                        if (bcConfig.isIgnoreFile(bc, file) == true)
                        {
                            bm.RemoveIgnorFile(file);
                            continue;
                        }
                        bm.AddFile(file);
                    }

                    bundlesMap.Maps.Add(bm);
                }
                else if (bc.Mode == BundleMode.SceneOneToOne)
                {
                    // 取得当前目录的文件列表
                    List <string> files = GetAllFiles(bc.Path);

                    foreach (string file in files)
                    {
                        // .DS_Store文件
                        if (file.EndsWith(".DS_Store") == true)
                        {
                            continue;
                        }
                        // *.meta文件
                        if (file.EndsWith(".meta") == true)
                        {
                            continue;
                        }
                        // 若非场景文件,则跳过
                        if (file.EndsWith(".unity") == false)
                        {
                            continue;
                        }

                        // 若为忽略文件,则跳过
                        string    bundleId = BundlesMap.GetBundleID(file);
                        BundleMap bm       = bundlesMap.GetOrCreateBundlesMap(bundleId);
                        if (bcConfig.isIgnoreFile(bc, file) == true)
                        {
                            bm.RemoveIgnorFile(file);
                            continue;
                        }

                        bm.ID   = bundleId;
                        bm.Path = bc.Path;
                        bm.Type = TBundleType.Scene;
                        bm.AddFile(file);

                        bundlesMap.Maps.Add(bm);
                    }
                }
                else if (bc.Mode == BundleMode.FileOneToOne)
                {
                    // 取得当前目录的文件列表
                    List <string> files = GetAllFiles(bc.Path);

                    foreach (string file in files)
                    {
                        // .DS_Store文件
                        if (file.EndsWith(".DS_Store") == true)
                        {
                            continue;
                        }
                        // *.meta文件
                        if (file.EndsWith(".meta") == true)
                        {
                            continue;
                        }

                        // 若为忽略文件,则跳过
                        string    bundleId = BundlesMap.GetBundleID(file);
                        BundleMap bm       = bundlesMap.GetOrCreateBundlesMap(bundleId);
                        if (bcConfig.isIgnoreFile(bc, file) == true)
                        {
                            bm.RemoveIgnorFile(file);
                            continue;
                        }

                        bm.ID   = bundleId;
                        bm.Path = bc.Path;
                        bm.AddFile(file);

                        bundlesMap.Maps.Add(bm);
                    }
                }
                else if (bc.Mode == BundleMode.TopDirOneToOne)
                {
                    // 取得目录列表
                    string[] directories = Directory.GetDirectories(bc.Path);
                    if ((directories == null) || (directories.Length <= 0))
                    {
                        BuildLogger.LogWarning("The no subfolder in this path!!!(dir:{0})",
                                               bc.Path);
                        continue;
                    }

                    foreach (string dir in directories)
                    {
                        // 取得当前目录的文件列表
                        List <string> files = GetAllFiles(dir);

                        string bundleId = BundlesMap.GetBundleID(dir);
                        bundleId = BundlesMap.GetBundleID(dir);
                        if (string.IsNullOrEmpty(bundleId) == true)
                        {
                            continue;
                        }
                        BundleMap bm = bundlesMap.GetOrCreateBundlesMap(bundleId);
                        bm.ID   = bundleId;
                        bm.Path = bc.Path;

                        foreach (string file in files)
                        {
                            // .DS_Store文件
                            if (file.EndsWith(".DS_Store") == true)
                            {
                                continue;
                            }
                            // *.meta文件
                            if (file.EndsWith(".meta") == true)
                            {
                                continue;
                            }

                            // 若为忽略文件,则跳过
                            if (bcConfig.isIgnoreFile(bc, file) == true)
                            {
                                bm.RemoveIgnorFile(file);
                                continue;
                            }

                            bm.AddFile(file);
                        }

                        bundlesMap.Maps.Add(bm);
                    }
                }
            }

            // 目录检测
            string checkDir = UploadList.GetInstance().BundlesOutputDir;

            if (Directory.Exists(checkDir) == false)
            {
                Directory.CreateDirectory(checkDir);
            }
            checkDir = UploadList.GetInstance().BundlesOutputDirOfNormal;
            if (Directory.Exists(checkDir) == false)
            {
                Directory.CreateDirectory(checkDir);
            }
            checkDir = UploadList.GetInstance().BundlesOutputDirOfScene;
            if (Directory.Exists(checkDir) == false)
            {
                Directory.CreateDirectory(checkDir);
            }

            bool successed             = false;
            AssetBundleManifest result = null;

            string[]           allAssets = null;
            AssetBundleBuild[] targets   = null;

            // 一般Bundles
            try {
                targets = bundlesMap.GetAllNormalBundleTargets();
                BuildAssetBundleOptions options = BuildAssetBundleOptions.UncompressedAssetBundle;
                result = BuildPipeline.BuildAssetBundles(
                    UploadList.GetInstance().BundlesOutputDirOfNormal,
                    targets,
                    options,
                    buildTarget);
                BuildLogger.LogMessage(" -> BuildPipeline.BuildAssetBundles");
                if (result != null)
                {
                    allAssets = result.GetAllAssetBundles();
                    if ((allAssets != null) && (targets.Length == allAssets.Length))
                    {
                        successed = true;
                    }
                }
            } catch (Exception exp) {
                BuildLogger.LogException("BuildAssetBundles Detail : {0}", exp.Message);
                successed = false;
            }

            // 更新导出标志位
            if (successed == true)
            {
                BuildLogger.LogMessage(" -> BundlesConfig.UpdateBundleStateWhenCompleted");

                Dictionary <string, string> hashCodes = new Dictionary <string, string>();
                foreach (string asset in allAssets)
                {
                    Hash128 hashCode = result.GetAssetBundleHash(asset);
                    if (string.IsNullOrEmpty(hashCode.ToString()) == true)
                    {
                        continue;
                    }
                    string fileSuffix = UploadList.GetInstance().FileSuffix;
                    string key        = asset;
                    if (string.IsNullOrEmpty(fileSuffix) == false)
                    {
                        fileSuffix = fileSuffix.ToLower();
                        fileSuffix = string.Format(".{0}", fileSuffix);
                        key        = key.Replace(fileSuffix, "");
                    }
                    hashCodes[key] = hashCode.ToString();
                }
                // 初始化检测信息(Hash Code)
                bundlesMap.UpdateUploadList(TBundleType.Normal, hashCodes);
                BuildLogger.LogMessage(" -> BundlesMap.UpdateUploadList Normal");
            }

            // Scene Bundles
            List <SceneBundleInfo> targetScenes = bundlesMap.GetAllSceneBundleTargets();

            if ((targetScenes != null) && (targetScenes.Count > 0))
            {
                foreach (SceneBundleInfo scene in targetScenes)
                {
                    if ((scene == null) ||
                        (scene.GetAllTargets() == null) ||
                        (scene.GetAllTargets().Length <= 0))
                    {
                        continue;
                    }
                    try {
                        BuildOptions options = BuildOptions.BuildAdditionalStreamedScenes;
                        if (TBuildMode.Debug == BuildInfo.GetInstance().BuildMode)
                        {
                            options |= BuildOptions.Development;
                        }
                        string sceneState = BuildPipeline.BuildPlayer(
                            scene.GetAllTargets(),
                            UploadList.GetLocalSceneBundleFilePath(scene.BundleId),
                            buildTarget,
                            options);
                        BuildLogger.LogMessage(" -> BuildPipeline.BuildStreamedSceneAssetBundle(State:{0})", sceneState);
                    } catch (Exception exp) {
                        BuildLogger.LogException("BuildStreamedSceneAssetBundle Detail:{0}", exp.Message);
                        successed = false;
                    }
                }
            }

            // 更新导出标志位
            if (successed == true)
            {
                BuildLogger.LogMessage(" -> BundlesConfig.UpdateBundleStateWhenCompleted");

                // 初始化检测信息(Hash Code)
                bundlesMap.UpdateUploadList(TBundleType.Scene);
                BuildLogger.LogMessage(" -> BundlesMap.UpdateUploadList Scene");
            }

            BuildInfo.GetInstance().ExportToJsonFile();
            BuildLogger.LogMessage(" -> BuildInfo.ExportToJsonFile");

            BuildLogger.CloseBlock();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 查询出本地不存在的BundleName列表
        /// </summary>
        /// <param name="queryBundleNameList"></param>
        /// <returns></returns>
        public List <string> QueryLocalNotIncludeBundleList(List <string> queryBundleNameList)
        {
            List <string> localNotIncludeBundleList = BundleMap.GetNotIncludeBundleList(queryBundleNameList);

            return(localNotIncludeBundleList);
        }