private void RemoveButton(ProviderModel providerData) { GUI.enabled = true; var btn = GUILayout.Button(new GUIContent { text = "Remove", }, buttonWidth, buttonHeight); if (btn && !isProcessing) { GUI.enabled = true; try { ZLog.Warning(">>>>>>>>> Remove Click! <<<<<<<<<<"); if (EditorUtility.DisplayDialog("Remove Package", "Are you sure you want to remove this package?", "Remove", "Cancle")) { ZBaseEditorCoroutines.StartEditorCoroutine(RemovePackage(providerData.providerName, (result) => { if (result.Status == StatusCode.Success) { ZLog.Info(string.Format("***Remove Success {0} {1}***", providerData.providerName, providerData.latestUnityVersion)); canRefresh = true; } })); } } catch (System.Exception e) { ZLog.Error("Error " + e.Message); } } }
/// <summary> /// 读取操作记录 /// </summary> /// <returns></returns> public List <string> ReadActionsCache() { try { string[] files = ReadFiles(actionsDirectory); if (files == null) { return(null); } List <string> data = new List <string>(files.Length); for (int i = 0; i < files.Length; i++) { string tmp = ReadText(files[i]); if (!string.IsNullOrEmpty(tmp)) { data.Add(tmp); } } return(data); } catch (Exception e) { ZLog.Error("read action cache flie error : " + e.Message); return(null); } }
private IEnumerator RemovePackage(string PackageName, System.Action <RemoveRequest> callback) { var result = Client.Remove(PackageName); while (!result.IsCompleted) { isProcessing = true; yield return(new WaitForSeconds(0.1f)); } if (result.Error != null) { ZLog.Error("[Error] Add Fail: " + result.Error.message); if (callback != null) { callback(null); } } else { if (callback != null) { callback(result); } } }
void PackageInstallProgress() { if (remRequest.IsCompleted) { switch (remRequest.Status) { case StatusCode.Failure: ZLog.Error("Couldn't install package '" + remRequest.Result.displayName + "': " + remRequest.Error.message); break; case StatusCode.InProgress: break; case StatusCode.Success: ZLog.Info("Installed package: " + remRequest.Result.displayName); break; } if (urlQueue.Count > 0) { remRequest = Client.Add(urlQueue.Dequeue()); } else { // no more packages to remove EditorApplication.update -= PackageInstallProgress; isAddMultiPkg = false; } } }
public List <string> ReadAll(string path) { try { if (Directory.Exists(path) == false) { return(null); } string[] directories = Directory.GetDirectories(path); string[] files = Directory.GetFiles(path); List <string> all = new List <string>(); if (directories != null && directories.Length > 0) { all.AddRange(directories); } if (files != null && files.Length > 0) { all.AddRange(files); } return(all); } catch (Exception e) { ZLog.Error("read flies error : " + e.Message); return(null); } }
public void PlaySound(string path, GameObject target, AudioType format = AudioType.OGGVORBIS) { if (string.IsNullOrEmpty(path) || target.activeInHierarchy == false) { return; } string uid = AlgorithmUtil.ToMD5(path); AudioClip clip = GetClip(uid); if (clip == null) { if (File.Exists(path)) { if (CallbackController.Instance == null) { ZLog.Error("must attach the script of CallbackController"); return; } if (loadCoroutine != null) { CallbackController.Instance.StopCoroutine(loadCoroutine); } loadCoroutine = CallbackController.Instance.StartCoroutine(LoadAndPlayDelay(uid, path, target, false, true, format)); } else { ZLog.Error("the file not existed"); } } PlaySound(clip, target); }
/// <summary> /// 如果正在显示,不做处理 /// 如果在hide ,显示出来 /// 其他情况就创建一个新的 /// </summary> /// <param name="type"></param> /// <returns></returns> public async Task <UI> CreateAsync(string type) { UI ui = Get(type); if (ui != null && ui.UiComponent.InShow) { return(ui); } //打开遮罩,阻挡点击事件,只有一个控件,很快的 UI uiEventMask = await CreateUIEventMask(); await semaphoreSlim.WaitAsync(); bool isRelease = false; //信号量释放后要重新刷新堵塞前的状态 ui = Get(type); if (ui != null && ui.UiComponent.InShow) { ReleaseRelated(uiEventMask, ref isRelease); return(ui); } try { if (ui == null) { //ui = UiTypes[type].Create(this.GetParent<Scene>(), type, Root); ui = await uiFactory.CreateAsync(type); uis.Add(type, ui); } if (ui.GameObject == null) { ZLog.Error(type + "CreateAsync ui.GameObject==null"); //return null; } else { SetViewParent(ui, ui.GameObject.GetComponent <CanvasConfig>()?.CanvasName); ui.ShowUI(); AddCanvas(ui.GameObject); } //热更层不会走finally,所有这里直接释放掉 ReleaseRelated(uiEventMask, ref isRelease); return(ui); } catch (Exception e) { throw new Exception($"{type} UI 错误: {e}"); } finally { ReleaseRelated(uiEventMask, ref isRelease); } }
private IEnumerator AddPackage(ProviderModel providerInfo, System.Action <AddRequest> callback) { float percentProgress = 0; AddRequest result = null; string urlDownload = ""; ProviderModel providerSever = providersSet[providerInfo.providerName]; if (providerSever.source == ZBaseEnum.Source.git) { urlDownload = providerInfo.downloadURL + string.Format(SuffixesVersionGitURL, providerInfo.latestUnityVersion); } else if (providerSever.source == ZBaseEnum.Source.embedded) { urlDownload = string.Format(InstallURL, ZBasePackageIdConfig.Repo, providerInfo.providerName); } else if (providerSever.source == ZBaseEnum.Source.registry) { urlDownload = providerInfo.providerName; } result = Client.Add(urlDownload); while (!result.IsCompleted) { isProcessing = true; EditorUtility.DisplayCancelableProgressBar(providerInfo.displayProviderName + " Downloading...", "", percentProgress); percentProgress += 0.002f; if (percentProgress >= 1) { percentProgress = 0; } yield return(new WaitForSeconds(0.1f)); } EditorUtility.ClearProgressBar(); if (result.Error != null) { ZLog.Error("[Error] Add Fail: " + result.Error.message); if (callback != null) { callback(null); } } else { if (callback != null) { callback(result); } } }
private void InstallButton(ProviderModel providerData) { bool btn = GUILayout.Button(new GUIContent { text = "Install", }, buttonWidth, buttonHeight); if (btn && !isProcessing) { GUI.enabled = true; try { ZLog.Warning(">>>>>>>>> Install Click! <<<<<<<<<<"); if (providersSet[providerData.providerName].dependencies.Count == 0) { ZBaseEditorCoroutines.StartEditorCoroutine(AddPackage(providerData, (result) => { if (result.Status == StatusCode.Success) { ZLog.Info(string.Format("***Install Success {0} {1}***", providerData.providerName, providerData.latestUnityVersion)); canRefresh = true; if (!providerData.providerName.StartsWith("com")) { EditorPrefs.SetString("key_package_import", providerData.providerName); } } })); } else { ZBaseEditorCoroutines.StartEditorCoroutine(AddPackageWithDependencie(providerData, (result) => { if (result.Status == StatusCode.Success) { ZLog.Info(string.Format("***Install Success {0} {1}***", providerData.providerName, providerData.latestUnityVersion)); EditorApplication.UnlockReloadAssemblies(); canRefresh = true; if (!providerData.providerName.StartsWith("com")) { EditorPrefs.SetString("key_package_import", providerData.providerName); } } })); } } catch (System.Exception e) { ZLog.Error("Error " + e.Message); } } }
public void CheckForErrors(TokenNode rootToken, List <ParsingError> errors) { if (errors.Count > 0) { foreach (ParsingError error in errors) { ZLog.Error($"Error parsing root script node - {rootToken.ToString_Internal(false)}, error: {error.Exception.Message}"); } ZLog.Error($"{rootToken}"); throw new AggregateException($"Error parsing root script node - {rootToken.ToString_Internal(false)}", errors.Select((error => error.Exception))); } }
private IEnumerator DownloadFile(string downloadFileUrl, string downloadFileName, System.Action callback) { string fileDownloading = ""; Dictionary <string, string> listRequest = new Dictionary <string, string>(); listRequest.Add(downloadFileName, downloadFileUrl); listRequest.Add(downloadFileName + ".meta", downloadFileUrl + ".meta"); foreach (var item in listRequest) { string path = string.Format(PackManagerDownloadDir, ZBasePackageIdConfig.NamePackageManager, providersLocal[ZBasePackageIdConfig.NamePackageManager].hash, item.Key); fileDownloading = string.Format("Downloading {0}", item.Key); UnityWebRequest downloadWebClient = new UnityWebRequest(item.Value); downloadWebClient.downloadHandler = new DownloadHandlerFile(path); downloadWebClient.SendWebRequest(); if (!downloadWebClient.isHttpError && !downloadWebClient.isNetworkError) { while (!downloadWebClient.isDone) { isProcessing = true; yield return(new WaitForSeconds(0.1f)); if (EditorUtility.DisplayCancelableProgressBar("Download Manager", fileDownloading, downloadWebClient.downloadProgress)) { ZLog.Error(downloadWebClient.error); CancelDownload(); downloadWebClient.Dispose(); } } } else { ZLog.Error("Error Downloading " + downloadFileName + " : " + downloadWebClient.error); CancelDownload(); downloadWebClient.Dispose(); } } EditorUtility.ClearProgressBar(); yield return(new WaitForSeconds(0.1f)); if (callback != null) { callback.Invoke(); } }
private void ImportPackage(ProviderModel providerModel) { string urlPackageImport = string.Format(InstallPackLocalDir, providerModel.providerName, providersLocal[providerModel.providerName].hash, providerModel.displayProviderName); if (CheckFileExist(urlPackageImport)) { AssetDatabase.ImportPackage(urlPackageImport, true); } else { ZLog.Error("File import not found!"); } }
/// <summary> /// 读取证书 /// </summary> /// <returns></returns> public string ReadCertificate() { try { if (File.Exists(certificatePath) == false) { return(""); } return(File.ReadAllText(certificatePath)); } catch (Exception e) { ZLog.Error("read flie error : " + e.Message); return(""); } }
public string[] ReadFiles(string path) { try { if (Directory.Exists(path) == false) { return(null); } return(Directory.GetFiles(path)); } catch (Exception e) { ZLog.Error("read flies error : " + e.Message); return(null); } }
public long GetFileSize(string path) { try { if (!File.Exists(path)) { return(0); } FileInfo info = new FileInfo(path); return(info.Length); } catch (Exception e) { ZLog.Error("get file size Error : " + e.Message); return(0); } }
public string ReadTasks() { try { string path = Path.Combine(rootDirectory, "tasks.json"); if (File.Exists(path) == false) { return(""); } return(File.ReadAllText(path)); } catch (Exception e) { ZLog.Error("read flie error : " + e.Message); return(""); } }
public void ClearFile(string path) { if (string.IsNullOrEmpty(path)) { return; } try { if (File.Exists(path) == false) { return; } File.Delete(path); }catch (Exception e) { ZLog.Error("delete flie Error : " + e.Message); } }
private IEnumerator GetRequest(string url, System.Action <Dictionary <string, object> > callback) { UnityWebRequest unityWebRequest = UnityWebRequest.Get(url); var webRequest = unityWebRequest.SendWebRequest(); if (!unityWebRequest.isHttpError && !unityWebRequest.isNetworkError) { ZLog.Info("[Get] URL: " + url); while (!webRequest.isDone) { yield return(new WaitForSeconds(0.1f)); if (EditorUtility.DisplayCancelableProgressBar("Downloading...", "", webRequest.progress)) { ZLog.Error(string.Format("[Get] URL: {0}\n{1}", url, unityWebRequest.error)); CancelDownload(); } } EditorUtility.ClearProgressBar(); string json = unityWebRequest.downloadHandler.text; ZLog.Info("Data: " + json); Dictionary <string, object> dic = new Dictionary <string, object>(); // try { dic = Json.Deserialize(json) as Dictionary <string, object>; if (callback != null) { callback(dic); } } catch (Exception e) { ZLog.Error("[Get] URL: " + url + "\n" + "[Parse Data] Error: " + e.ToString()); } } else { ZLog.Error("[Error] Load Fail: " + unityWebRequest.error); } }
public string SaveScreenshot(string appid, int screenid, string url, byte[] pngData) { try { if (Directory.Exists(screenDirectory) == false) { Directory.CreateDirectory(screenDirectory); } string path = Path.Combine(screenDirectory, appid + "-" + screenid.ToString()); File.WriteAllBytes(path, pngData); return(path); } catch (Exception e) { ZLog.Error("save flie error : " + e.Message); return(""); } }
public void ClearDirectory(string path) { if (string.IsNullOrEmpty(path)) { return; } try { if (Directory.Exists(path) == false) { return; } Directory.Delete(path, true); } catch (Exception e) { ZLog.Error("delete flie Error : " + e.Message); } }
public string SaveLogo(string appid, string url, byte[] pngData) { try { if (Directory.Exists(logoDirectory) == false) { Directory.CreateDirectory(logoDirectory); } string path = Path.Combine(logoDirectory, appid); File.WriteAllBytes(path, pngData); return(path); } catch (Exception e) { ZLog.Error("save flie error : " + e.Message); return(""); } }
public void GetVersionInfoFromLocal(Dictionary <string, object> data) { foreach (var item in data) { try { if (item.Key.ToLower().Equals("version")) { this.currentUnityVersion = item.Value as string; } } catch (Exception e) { ZLog.Error("Error parse tool version info " + e.ToString()); } } ZLog.Info(string.Format("***Pack {0} on local, version {1}***", this.displayProviderName, this.currentUnityVersion)); }
private void ImportButton(ProviderModel providerData) { bool btn = GUILayout.Button(new GUIContent { text = "Import", }, buttonWidth, buttonHeight); if (btn && !isProcessing) { GUI.enabled = true; try { ZLog.Warning(">>>>>>>>> Import Click! <<<<<<<<<<"); ImportPackage(providerData); } catch (Exception e) { ZLog.Error("Error " + e.Message); } } }
private void GetDataFromPackageLockServer(Dictionary <string, object> data) { providersSet.Clear(); try { object dependencies; if (data.TryGetValue("dependencies", out dependencies)) { if (dependencies != null) { foreach (var item in dependencies as Dictionary <string, object> ) { ProviderModel info = new ProviderModel(); if (ZBasePackageIdConfig.ListPackages.ContainsKey(item.Key)) { if (info.GetFromJson(item.Key, item.Value as Dictionary <string, object>)) { providersSet.Add(info.providerName, info); if (info.currentUnityVersion != "none") { ZLog.Info(string.Format("***Package {0} on server, version {1}***", info.displayProviderName, info.latestUnityVersion)); } } } } } } progressLoadData++; ZBaseEditorCoroutines.StartEditorCoroutine(GetVersionForEmbeddedPack()); } catch (Exception e) { ZLog.Error("Error Get Version From Package Lock Server: " + e.Message); } }
// server private void GetDataFromPackageConfig(Dictionary <string, object> data) { ZBasePackageIdConfig.ListPackages.Clear(); try { if (data.Count > 0) { foreach (var item in data) { ZBasePackageIdConfig.ListPackages.Add(item.Key, item.Value.ToString()); } } progressLoadData++; GetPackageLockServer(); } catch (Exception e) { ZLog.Error("Error Get Version From Package Lock Server: " + e.Message); } }
private void LoadPackageFromLocal(string namePackage, System.Action <Dictionary <string, object> > callback) { try { Dictionary <string, object> dic = new Dictionary <string, object>(); string path = string.Format(PackVersionLocalDir, namePackage); string fileContent = File.ReadAllText(path); dic = Json.Deserialize(fileContent) as Dictionary <string, object>; if (dic.Count > 0) { if (callback != null) { callback(dic); } } } catch (Exception e) { ZLog.Error("Error Load Package From Local: " + e.Message); } }
private void UnloadOneBundle(string assetBundleName) { assetBundleName = assetBundleName.ToLower(); ABInfo abInfo; if (!this.bundles.TryGetValue(assetBundleName, out abInfo)) { ZLog.Error("==========所有 bundles=========="); //return; foreach (var item in bundles) { ZLog.Error(item.Key); } throw new Exception($"not found assetBundle: {assetBundleName}"); } //Log.Debug($"---------- unload one bundle {assetBundleName} refcount: {abInfo.RefCount}"); --abInfo.RefCount; if (abInfo.RefCount > 0) { return; } ZLog.Error($"移除assetBundleName??{assetBundleName}"); this.bundles.Remove(assetBundleName); // 缓存10个包 this.cacheDictionary.Enqueue(assetBundleName, abInfo); if (this.cacheDictionary.Count > 10) { abInfo = this.cacheDictionary[this.cacheDictionary.FirstKey]; this.cacheDictionary.Dequeue(); abInfo.Dispose(); } //Log.Debug($"cache count: {this.cacheDictionary.Count}"); }
public void PlayMusic(string path, GameObject target, bool loop, AudioType format = AudioType.OGGVORBIS) { if (string.IsNullOrEmpty(path) || target.activeInHierarchy == false || isLoading) { return; } ZLog.Log("audio manager play one......path = " + path); string uid = AlgorithmUtil.ToMD5(path); AudioClip clip = GetClip(uid); if (clip == null) { if (File.Exists(path)) { //Debug.LogError("time read file start:" + Time.realtimeSinceStartup); //new Thread(() => ReadFile(uid, path, target, loop)).Start(); if (CallbackController.Instance == null) { ZLog.Error("must attach the script of CallbackController"); return; } if (loadCoroutine != null) { CallbackController.Instance.StopCoroutine(loadCoroutine); } loadCoroutine = CallbackController.Instance.StartCoroutine(LoadAndPlayDelay(uid, path, target, loop, false, format)); } else { ZLog.Error("the file not existed"); } } else { ActiveMusic(clip, target, loop); NotifyManager.SendNotify(NotifyType.OnAudioPlay, path); } }
private bool isNewerVersion(string current, string latest) { bool isNewer = false; try { current = current.Replace("v", ""); latest = latest.Replace("v", ""); int[] currentVersion = Array.ConvertAll(current.Split('.'), int.Parse); int[] remoteVersion = Array.ConvertAll(latest.Split('.'), int.Parse); int remoteBuild = 0; int curBuild = 0; if (currentVersion.Length > 3) { curBuild = currentVersion[3]; } if (remoteVersion.Length > 3) { remoteBuild = remoteVersion[3]; } System.Version cur = new System.Version(currentVersion[0], currentVersion[1], currentVersion[2], curBuild); System.Version remote = new System.Version(remoteVersion[0], remoteVersion[1], remoteVersion[2], remoteBuild); isNewer = cur < remote; } catch (Exception e) { ZLog.Error("Error " + e.Message); } return(isNewer); }
public void WriteActionsCache(string json) { try { DateTime now = DateTime.Now; if (Directory.Exists(actionsDirectory) == false) { Directory.CreateDirectory(actionsDirectory); } string path = Path.Combine(actionsDirectory, now.Year + "-" + now.Month + "-" + now.Day + "_actions.json"); if (File.Exists(path)) { File.Delete(path); } WriteText(path, json); ZLog.Log("WriteActionsCache...."); } catch (Exception e) { ZLog.Error(e.Message); } }