/** 获取服务器版本号 */ IEnumerator ReadServerVersionInfo() { int isUpdateTest = PlayerPrefsUtil.GetIntSimple(PlayerPrefsKey.Setting_Update);//测试更新 string centerName = GameConst.CenterName; if (isUpdateTest == 1) { centerName = "Test"; } string url = AssetManagerSetting.GetServerVersionInfoURL(GameConst.WebUrl, centerName); WWW www = new WWW(url); yield return(www); if (!string.IsNullOrEmpty(www.error)) { OnError("获取服务器版本号出错"); Debug.LogErrorFormat("获取服务器版本号出错 url={0}, www.error={1}", url, www.error); www.Dispose(); www = null; yield break; } Debug.Log(www.text); serverVersionInfo = JsonUtility.FromJson <VersionInfo>(www.text); serverVersionInfo.Set(); }
IEnumerator InitAssetList() { string url = AssetManagerSetting.FilesCsvForStreaming; WWW www = new WWW(url); yield return(www); assetList = AssetFileList.Read(AssetManagerSetting.AssetFileListPath); if (string.IsNullOrEmpty(www.error)) { string path, md5; using (StringReader stringReader = new StringReader(www.text)) { while (stringReader.Peek() >= 0) { string line = stringReader.ReadLine(); if (!string.IsNullOrEmpty(line)) { string[] seg = line.Split(';'); path = seg[0]; md5 = seg[1]; assetList.Add(path, md5); AssetManagerSetting.persistentAssetFileList.Remove(AssetManagerSetting.GetPlatformPath(path)); } } } } assetList.Save(AssetManagerSetting.AssetFileListPath); }
public static void GeneratorUpdateList(Version appVer) { string path = AssetManagerSetting.EditorUpdateAssetListPath; Debug.Log(path); PathUtil.CheckPath(path); if (appVer == null) { if (File.Exists(path)) { File.Delete(path); } File.Copy(AssetManagerSetting.EditorFileCsvForStreaming, path); return; } Debug.Log(appVer); AssetFileList app = AssetFileList.Read(AssetManagerSetting.EditorGetVersionFileListPath(appVer.ToString())); AssetFileList curr = AssetFileList.Read(AssetManagerSetting.EditorFileCsvForStreaming); AssetFileList diff = AssetFileList.DiffAssetFileList(app, curr); diff.Save(path); }
public static void CopyStreamFilesCsvToVersion(Version version) { string path = AssetManagerSetting.EditorGetVersionFileListPath(version.ToString()); PathUtil.CheckPath(path); File.Copy(AssetManagerSetting.EditorFileCsvForStreaming, path); }
private void ParseInfo(string p) { AssetLoadType loadType; string path, objType, assetBundleName, assetName, ext; string filename; using (StringReader stringReader = new StringReader(p)) { while (stringReader.Peek() >= 0) { string line = stringReader.ReadLine(); if (!string.IsNullOrEmpty(line)) { string[] seg = line.Split(';'); int length = seg.Length; loadType = (AssetLoadType)Convert.ToInt32(seg[0]); path = seg[1]; objType = length > 2 ? seg[2] : string.Empty; assetBundleName = length > 3 ? seg[3] : string.Empty; assetName = length > 4 ? seg[4] : string.Empty; filename = path.Replace("{0}/", "").ToLower(); #if UNITY_EDITOR ext = length > 5 ? seg[5] : string.Empty; if (AssetManagerSetting.EditorSimulateAssetBundle) { path = string.Format(path, AssetManagerSetting.EditorRootMResources) + ext; } else #endif { path = AssetManagerSetting.GetPlatformPath(path); } AssetInfo assetInfo; if (!assetInfoDict.TryGetValue(filename, out assetInfo)) { assetInfo = new AssetInfo(); assetInfo.name = filename; assetInfoDict.Add(filename, assetInfo); } assetInfo.path = path; assetInfo.loadType = loadType; assetInfo.objType = AssetManagerSetting.GetObjType(objType); assetInfo.assetName = assetName; assetInfo.assetBundleName = assetBundleName; } } } }
public static AssetBundleInfoList GeneratorAssetBundleInfo() { AssetBundleInfoList infoList = new AssetBundleInfoList(); List <string> list = new List <string>(); PathUtil.RecursiveFile(resourceRoot, list, exts); for (int i = 0; i < list.Count; i++) { string path = list[i]; AssetImporter importer = AssetImporter.GetAtPath(path); if (string.IsNullOrEmpty(importer.assetBundleName)) { Debug.LogWarningFormat("MResource资源没有设置AssetBundleName path={0}", path); continue; } AssetBundleInfo item = new AssetBundleInfo(); item.path = path; item.assetBundleName = importer.assetBundleName; item.assetName = PathUtil.ChangeExtension(Path.GetFileName(path), string.Empty); string ext = Path.GetExtension(path).ToLower(); if (ext == ".prefab") { item.objType = AssetManagerSetting.ObjType_GameObject; } else if (path.IndexOf("map/terrain") != -1) { item.objType = AssetManagerSetting.ObjType_Texture; } else if (imageExts.IndexOf(ext) != -1) { TextureImporter textureImporter = TextureImporter.GetAtPath(path) as TextureImporter; if (textureImporter.textureType == TextureImporterType.Sprite) { item.objType = AssetManagerSetting.ObjType_Sprite; } } infoList.Add(item); } EditorUtility.ClearProgressBar(); infoList.Save(AssetManagerSetting.EditorGetAbsoluteStreamPath(AssetManagerSetting.AssetBundleListName)); AssetDatabase.Refresh(); return(infoList); }
public TextAsset LoadConfig(string filename) { #if UNITY_EDITOR if (AssetManagerSetting.EditorSimulateConfig) { return(UnityEditor.AssetDatabase.LoadAssetAtPath <TextAsset>(AssetManagerSetting.EditorGetConfigPath(filename))); } else #endif { return((TextAsset)configAssetBundle.LoadAsset(AssetManagerSetting.GetConfigAssetName(filename))); } }
public static void CopyUpdateAsset(string serverRoot) { PathUtil.CheckPath(serverRoot, false); string updateAssetListPath = null; if (File.Exists(AssetManagerSetting.EditorUpdateAssetListPath)) { updateAssetListPath = AssetManagerSetting.EditorUpdateAssetListPath; } else if (File.Exists(AssetManagerSetting.EditorFileCsvForStreaming)) { updateAssetListPath = AssetManagerSetting.EditorFileCsvForStreaming; } if (!string.IsNullOrEmpty(updateAssetListPath)) { AssetFileList assetFileList = AssetFileList.Read(updateAssetListPath); assetFileList.Add(new AssetFile("{0}/" + AssetManagerSetting.UpdateAssetListName, "")); int count = assetFileList.list.Count; for (int i = 0; i < count; i++) { AssetFile item = assetFileList.list[i]; string path = AssetManagerSetting.GetPlatformPath(item.path); string fromPath = AssetManagerSetting.EditorRootStream + "/" + path; string toPath = serverRoot + "/" + path; PathUtil.CheckPath(toPath); File.Copy(fromPath, toPath, true); if (i % 10 == 0) { UnityEditor.EditorUtility.DisplayProgressBar("拷贝目录", path, 1f * i / count); } } } else { CopyAlleAsset(serverRoot); } UnityEditor.EditorUtility.ClearProgressBar(); }
/** 检测是否已经创建了WWW,没有就创建WWW */ protected bool LoadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest) { // Already loaded. LoadedAssetBundle bundle = null; m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle); if (bundle != null) { bundle.m_ReferencedCount++; return(true); } // string path = AssetManagerSetting.GetAbsoluteAssetBundlePath(assetBundleName); // AssetBundle assetBundle = AssetBundle.LoadFromFile(path); // m_LoadedAssetBundles.Add(assetBundleName, new LoadedAssetBundle(assetBundle) ); // return false; // @TODO: Do we need to consider the referenced count of WWWs? // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync(). // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs. if (m_DownloadingWWWs.ContainsKey(assetBundleName)) { return(true); } WWW download = null; string url = AssetManagerSetting.GetAbsoluteAssetBundleURL(assetBundleName); // For manifest assetbundle, always download it as we don't have hash for it. if (isLoadingAssetBundleManifest) { download = new WWW(url); } else { download = WWW.LoadFromCacheOrDownload(url, assetBundleManifest.GetAssetBundleHash(assetBundleName), 0); } m_DownloadingWWWs.Add(assetBundleName, download); return(false); }
public static void WriteServerURL() { string downloadURL; IPHostEntry host; string localIP = ""; host = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ip in host.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { localIP = ip.ToString(); break; } } downloadURL = "http://" + localIP + ":7888/"; Host = downloadURL; Games.GameConstConfig gameConstConfig = Games.GameConstConfig.Load(); gameConstConfig.WebUrl_Develop = downloadURL; gameConstConfig.Save(); VersionInfo versionInfo = VersionInfo.Load(ServerRootPath + "/" + AssetManagerSetting.VersionInfoName); versionInfo.version = gameConstConfig.Version; if (ServerRootPath == AssetManagerSetting.EditorAssetBundleServerRoot_StreamingAssets) { versionInfo.updateLoadUrl = downloadURL; } else { versionInfo.updateLoadUrl = downloadURL + "StreamingAssets/"; } string versionPath = AssetManagerSetting.GetServerVersionInfoURL(ServerRootPath, gameConstConfig.CenterName); versionInfo.Save(versionPath); }
public static void Config() { string configRoot = AssetManagerSetting.EditorRootConfig; string bytesRoot = AssetManagerSetting.RootConfigBytes; if (!Directory.Exists(configRoot)) { Debug.Log("目录不存在" + configRoot); return; } List <string> configList = new List <string>(); Recursive(configRoot, configList); if (Directory.Exists(bytesRoot)) { PathUtil.DeleteDirectory(bytesRoot); } Directory.CreateDirectory(bytesRoot); for (int i = 0; i < configList.Count; i++) { string sourcePath = configList[i]; string destPath = PathUtil.ChangeExtension(sourcePath.Replace(configRoot, bytesRoot), AssetManagerSetting.BytesExt); PathUtil.CheckPath(destPath, true); File.Copy(sourcePath, destPath, true); } AssetDatabase.Refresh(); List <string> bytesList = new List <string>(); Recursive(bytesRoot, bytesList); string assetBundleName = AssetManagerSetting.ConfigAssetBundleName; AssetBundleBuild[] builds = new AssetBundleBuild[1]; builds[0].assetBundleName = assetBundleName; builds[0].assetNames = bytesList.ToArray(); Debug.Log("bytesList.Count=" + bytesList.Count); string outPath = bytesRoot; PathUtil.CheckPath(outPath, false); BuildPipeline.BuildAssetBundles(outPath, builds, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget); AssetDatabase.Refresh(); string inAssetBundlePath = bytesRoot + "/" + assetBundleName; string outBytesPath = AssetManagerSetting.EditorGetAbsolutePlatformPath(assetBundleName); byte[] bytes = File.ReadAllBytes(inAssetBundlePath); bytes = EncryptBytes(bytes, SKey); PathUtil.CheckPath(outBytesPath, true); File.WriteAllBytes(outBytesPath, bytes); AssetDatabase.Refresh(); if (Directory.Exists(bytesRoot)) { PathUtil.DeleteDirectory(bytesRoot); } AssetDatabase.Refresh(); }
/// <summary> /// 加载 /// </summary> /// <param name="filename">文件名.</param> /// <param name="callback">回调函数(文件名, 资源, 回调参数).</param> /// <param name="arg">回调参数.</param> /// <param name="type">资源类型.</param> public void Load(string filename, Action <string, object, object[]> callback, object[] callbackArgs, Type type) { if (string.IsNullOrEmpty(filename)) { if (callback != null) { callback(filename, null, callbackArgs); } Debug.LogErrorFormat("Load filename=" + filename); return; } if (AssetManagerSetting.IsConfigFile(filename)) { LoadConfig(filename, callback, callbackArgs); return; } string filenameLower = filename.ToLower(); AssetInfo fileInfo; if (!assetInfoDict.TryGetValue(filenameLower, out fileInfo)) { // Debug.LogError("[AssetMananger]资源配置不存在或者加载出错 name="+filenameLower + " assetInfo=" + fileInfo ); if (callback != null && fileInfo == null) { LoadResourceAsync(filename, type, callback, callbackArgs); } return; } AddToModule(fileInfo); if (fileInfo.objType != null && (type == null || type == tmpObjType)) { type = fileInfo.objType; } if (fileInfo.loadType == AssetLoadType.AssetBundle) { #if UNITY_EDITOR if (AssetManagerSetting.EditorSimulateAssetBundle) { try { UnityEngine.Object target = UnityEditor.AssetDatabase.LoadAssetAtPath(fileInfo.path, type); if (callback != null) { callback(filename, target, callbackArgs); } } catch (Exception e) { Debug.LogErrorFormat("fileInfo.path={0} e={1}", fileInfo.path, e); } } else #endif { LoadAssetAsync(filename, fileInfo.assetBundleName, fileInfo.assetName, type, callback, callbackArgs); } } else { LoadResourceAsync(fileInfo.path, type, callback, callbackArgs); } }
IEnumerator UpdateResource(string rootUrl) { // rootUrl = "http://www.ihaiu.com/StreamingAssets/" OnUpdateEnter(); //获取服务器端的file.csv OnState("获取服务器端的file.csv"); string updateAssetListUrl = AssetManagerSetting.GetServerFilesCsvURL(rootUrl); Debug.Log("UpdateAssetList URL: " + updateAssetListUrl); WWW www = new WWW(updateAssetListUrl); yield return(www); if (!string.IsNullOrEmpty(www.error)) { OnError("更新资源读取资源列表失败"); Debug.LogErrorFormat("更新资源读取资源列表失败 updateAssetListUrl={0}, www.error={1}", updateAssetListUrl, www.error); www.Dispose(); www = null; yield break; } AssetFileList updateAssetList = AssetFileList.Deserialize(www.text); www.Dispose(); www = null; //Debug.Log("count: " + files.Length + " text: " + filesText); OnState("读取" + AssetManagerSetting.AssetFileListPath); if (assetList == null) { assetList = AssetFileList.Read(AssetManagerSetting.AssetFileListPath); } List <AssetFile> diffs = AssetFileList.Diff(assetList, updateAssetList); AssetManagerSetting.persistentAssetFileList = AssetFileList.Read(AssetManagerSetting.PersistentAssetFileListPath); string path; //更新 int count = diffs.Count; for (int i = 0; i < count; i++) { AssetFile item = diffs[i]; path = AssetManagerSetting.GetPlatformPath(item.path); OnState("更新" + path); OnUpdateProgress((float)(i + 1) / (float)count); string url = rootUrl + path; www = new WWW(url); yield return(www); if (!string.IsNullOrEmpty(www.error)) { OnUpdateFailed(url); www.Dispose(); www = null; continue; } string localPath = AssetManagerSetting.RootPathPersistent + path; PathUtil.CheckPath(localPath, true); File.WriteAllBytes(localPath, www.bytes); www.Dispose(); www = null; assetList.Add(item); AssetManagerSetting.persistentAssetFileList.Add(path, item.md5); } yield return(new WaitForEndOfFrame()); assetList.Save(AssetManagerSetting.AssetFileListPath); AssetManagerSetting.persistentAssetFileList.Save(AssetManagerSetting.PersistentAssetFileListPath); // 更新完成 OnUpdateEnd(); }
public AssetBundleLoadAssetOperation LoadOperation(string filename, Type type) { AssetBundleLoadAssetOperation operation = null; string filenameLower = filename.ToLower(); if (AssetOperationDict.ContainsKey(filenameLower)) { operation = AssetOperationDict[filenameLower]; operation.referencedCount++; AssetInfo fileInfo; if (assetInfoDict.TryGetValue(filenameLower, out fileInfo)) { AddToModule(fileInfo); } return(operation); } if (AssetManagerSetting.IsConfigFile(filename)) { operation = new AssetBundleLoadAssetOperationSimulation(LoadConfig(filename)); } else { AssetInfo fileInfo; if (!assetInfoDict.TryGetValue(filenameLower, out fileInfo)) { operation = new AssetBundleLoadAssetOperationSimulation(Resources.Load(filename, type)); } else { AddToModule(fileInfo); if (fileInfo.objType != null && (type == null || type == tmpObjType)) { type = fileInfo.objType; } if (fileInfo.loadType == AssetLoadType.AssetBundle) { #if UNITY_EDITOR if (AssetManagerSetting.EditorSimulateAssetBundle) { UnityEngine.Object target = UnityEditor.AssetDatabase.LoadAssetAtPath(fileInfo.path, type); operation = new AssetBundleLoadAssetOperationSimulation(target); } else #endif { operation = manifestAssetBundleManager.LoadAssetAsync(fileInfo.assetBundleName, fileInfo.assetName, type); } } else { operation = new AssetBundleLoadAssetOperationSimulation(Resources.Load(fileInfo.path, type)); } } } operation.referencedCount++; operation.key = filenameLower; AssetOperationDict.Add(filenameLower, operation); AssetOperationList.Add(operation); return(operation); }