private (LayoutInfo, AssetsInfo) Create(XdArtboard xdArtboard, XdAssetHolder assetHolder, string name, Dictionary <string, string> userData) { var renderer = new XdRenderer(xdArtboard, assetHolder, _objectParsers, _groupParsers, _triggers); var layoutInfoForCalcHash = new LayoutInfo( name, 0, renderer.Meta, new Dictionary <string, string>(), renderer.Root, renderer.Elements.ToArray() ); var hash = FastHash.CalculateHash(JsonConvert.SerializeObject(AkyuiCompressor.ToSerializable(layoutInfoForCalcHash))); var layoutInfo = new LayoutInfo( name, hash, renderer.Meta, userData, renderer.Root, renderer.Elements.ToArray() ); var assetsInfo = new AssetsInfo( renderer.Assets.ToArray() ); return(layoutInfo, assetsInfo); }
public async ValueTask <bool> DownloadIndexJsonAsync(AssetsInfo info) { _logService.Info(nameof(AssetService), $"Fetching download list for version \"{info.ID}\""); try { byte[] json = await _client.GetByteArrayAsync(info.IndexUrl); string indexDir = $"{_gamePathService.AssetsDir}/indexes"; //Make sure directory exists Directory.CreateDirectory(indexDir); File.WriteAllBytes($"{indexDir}/{info.ID}.json", json); return(true); } catch (HttpRequestException ex) { _logService.Error(nameof(AssetService), $"Failed to fetch download list: HTTP error\n{ex.Message}"); return(false); } catch (OperationCanceledException) { // Timeout _logService.Error(nameof(AssetService), $"Failed to fetch download list: Timeout"); return(false); } }
public BaseData(int type, string name, string talk, AssetsInfo assets) { this.type = type; this.name = name; this.talk = talk; this.assets = assets; }
public IEnumerator LoadAssetAsync <T>(string assetBundleName, string assetName, Action <T> callback) where T : UnityEngine.Object { string assetPath = null; Debug.Log(assetBundleName); AssetsInfo assetsInfo = GameUtility.assetsInfo; if (assetsInfo.assetList != null && assetsInfo.assetList.Count > 0) { for (int i = 0; i < assetsInfo.assetList.Count; i++) { if (assetsInfo.assetList[i].bundleName == assetBundleName) { if (assetsInfo.assetList[i].name == assetName) { assetPath = assetsInfo.assetList [i].path; break; } } } } ResourceRequest request = Resources.LoadAsync(assetPath, typeof(T)); yield return(request); if (request.isDone) { if (request.asset == null) { Debug.LogError("request.asset is Null : " + assetPath); } callback(request.asset as T); } }
//点击 Bundle命名 相关操作 static public void NameBundleClick() { if (DevelopUtility.bundleSetting.pathList.Count > 0) { if (assetsInfo == null) { assetsInfo = new AssetsInfo(); } else { assetsInfo.assetList.Clear(); } //对所有文件命名 for (int i = 0; i < DevelopUtility.bundleSetting.pathList.Count; i++) { if (DevelopUtility.bundleSetting.pathSelectList [i]) { assetsInfo.assetList = NameBundleStart(DevelopUtility.bundleSetting.pathList [i], DevelopUtility.clientConfig.assetBundleVariant); } } //创建新的加载策略文件 CreatePolicys(DevelopUtility.bundleSetting.pathList[0]); CheckAssetsInfo(); CreateAssetsInfo(Application.streamingAssetsPath + "/" + GameUtility.GetPlatformName() + "/" + DevelopUtility.clientConfig.hotfixFile); } else { Debug.LogError("没有选择任何可执行路径。"); } }
public void AddContent() { switch (dropdown.value) { case 0: return; case 1: name = UtilMethods.GetUIOb(CreateBg, "name").GetComponentInChildren <InputField>(); img = UtilMethods.GetUIOb(CreateBg, "img").GetComponentInChildren <InputField>(); effectVoice = UtilMethods.GetUIOb(CreateBg, "effectVoice").GetComponentInChildren <InputField>(); bgm = UtilMethods.GetUIOb(CreateBg, "bgm").GetComponentInChildren <InputField>(); BaseData sc_data = new SceneInfo(); sc_data.type = dropdown.value; sc_data.name = name.text; sc_data.pos = -1; assets = new AssetsInfo(img.text, bgm.text, "", effectVoice.text, ""); sc_data.assets = assets; CreateManager.Instance.dataList.Add(sc_data); break; case 2: name = UtilMethods.GetUIOb(CreateCharacter, "name").GetComponentInChildren <InputField>(); Dropdown pos = UtilMethods.GetUIOb(CreateCharacter, "pos").GetComponentInChildren <Dropdown>(); InputField content = UtilMethods.GetUIOb(CreateCharacter, "content").GetComponentInChildren <InputField>(); img = UtilMethods.GetUIOb(CreateCharacter, "img").GetComponentInChildren <InputField>(); effectVoice = UtilMethods.GetUIOb(CreateCharacter, "effectVoice").GetComponentInChildren <InputField>(); bgm = UtilMethods.GetUIOb(CreateCharacter, "bgm").GetComponentInChildren <InputField>(); BaseData ch_data = new CharacterItem(); ch_data.type = dropdown.value; ch_data.name = name.text; ch_data.pos = pos.value >= 4 ? -1 : pos.value; ch_data.talk = content.text; assets = new AssetsInfo(img.text, bgm.text, "", effectVoice.text, ""); ch_data.assets = assets; CreateManager.Instance.dataList.Add(ch_data); break; case 3: InputField senario = UtilMethods.GetUIOb(CreateScenario, "senario").GetComponentInChildren <InputField>(); BaseData se_data = new SceneInfo(); se_data.type = dropdown.value; assets = new AssetsInfo(); assets.scenario = senario.text; se_data.assets = assets; CreateManager.Instance.dataList.Add(se_data); break; default: break; } }
static public IEnumerator LoadAssetsInfo(Action <AssetsInfo> callback = null) { if (assetsInfo == null) { yield return(LoadFromJson <AssetsInfo> (GameUtility.StreamingHotfixPathFull, "AssetsInfo", (config) => { assetsInfo = config; if (callback != null) { callback(assetsInfo); } })); } }
public Task <ImmutableArray <AssetObject> > CheckIntegrityAsync(AssetsInfo info) { var query = info.Objects? .AsParallel() .Select(pair => pair.Value) .Where(obj => { string objPath = $"{_gamePathService.AssetsDir}/objects/{obj.Path}"; return(!(File.Exists(objPath) && CryptoUtil.ValidateFileSHA1(objPath, obj.Hash))); }); return(Task.FromResult(query?.ToImmutableArray() ?? ImmutableArray <AssetObject> .Empty)); }
void OnAssetsLoadingComplete(AssetBundle a_assetsbundle, AssetsInfo a_assetsInfo) { TotalAssets++; GameObject loadedObject; loadedObject = Instantiate(a_assetsbundle.LoadAsset(a_assetsInfo.AssetName, typeof(GameObject))) as GameObject; loadedObject.SetActive(false); m_assetsGameObjlst.Add(loadedObject.GetComponent<AssetsData>()); if (TotalAssets == GameManager.Instance.AllAssetsInfoList.Count) { GameState l_gameState = FiniteStateMachine.Instance.GetCurrentState<GameState>(); l_gameState.MakeActiveArCameraAndImageTarget(m_assetsGameObjlst); } }
private void AssetsInfo(object sender, EventArgs e) { Property property = (Property)dataGridView1.CurrentRow.DataBoundItem; if (property == null) { return; } AssetsInfo form = new AssetsInfo(); form.setInfo(property); form.Show(); }
public Task <AssetObject[]> CheckIntegrityAsync(AssetsInfo info) { var query = info.Objects? .Select(pair => pair.Value) .AsParallel() .Where(obj => { string path = $"{_gamePathService.AssetsDir}/objects/{obj.Path}"; return(!File.Exists(path) || obj.Hash != Utils.CryptUtil.GetFileSHA1(path)); }); return(Task.FromResult(query?.ToArray())); }
IEnumerator DeleteFile() { while (ExcessAssets.Count > 0) { AssetsInfo info = ExcessAssets.Dequeue(); string fileNamePath = Path.Combine(PersistentABPath, info.AssetName); if (File.Exists(fileNamePath)) { File.Delete(fileNamePath); } VersionHelper.RemoveAssetsInfo(info); yield return(null); } VersionHelper.RecodeAssetList(PersistentAssetsListPath); }
//検索対象を抽出 void CollectTartgetAssets() { TargetAssets.Clear(); string[] targetGuids = AssetDatabase.FindAssets("t:scene t:prefab t:material"); foreach (var targetGuid in targetGuids) { //guidから参照しているアセットを取り出す var targetPath = AssetDatabase.GUIDToAssetPath(targetGuid); var assetsPathes = AssetDatabase.GetDependencies(targetPath); var asset = new AssetsInfo(); asset.guid = targetGuid; asset.path = targetPath; asset.assetsPathes = assetsPathes; TargetAssets.Add(targetGuid, asset); } needCollection = false; }
IEnumerator Unzip() { while (!DownloadFinished || FileBuffs.Count > 0) { if (FileBuffs.Count > 0) { AssetsInfo assetsInfo = FileBuffs.Dequeue(); if (assetsInfo != null && assetsInfo.Datas != null) { string filePath = Path.Combine(PersistentABPath, assetsInfo.AssetName); filePath = filePath.Replace('\\', '/'); string dirPath = Path.GetDirectoryName(filePath); Debug.LogFormat("保存资源资源{0}到{1}", assetsInfo.AssetName, filePath); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } using (FileStream fileStream = File.Create(filePath)) { yield return(fileStream.BeginWrite(assetsInfo.Datas, 0, assetsInfo.Datas.Length, null, null)); } VersionHelper.UpdateAssetsInfo(assetsInfo); VersionHelper.RecodeAssetList(PersistentAssetsListPath); ++HotFixSystem.I.DownloadIndex; } } yield return(null); } if (DownloadFail) { NextHotFixPipeline = EHotFixPipeline.Fail; } else { NextHotFixPipeline = EHotFixPipeline.CheckAssetsList; } }
IEnumerator DownLoadZip() { DownloadFail = false; DownloadFinished = false; HotFixSystem.I.DownloadIndex = 0; yield return(DeleteFile()); while (NewAssets.Count > 0) { AssetsInfo assetsInfo = NewAssets.Dequeue(); string url = Path.Combine(DownloadABUrl, assetsInfo.AssetName); url = url.Replace("\\", "/"); Debug.LogFormat("尝试下载资源{0}", url); HttpReq = UnityWebRequest.Get(url); HttpReq.SetRequestHeader("Cache-Control", "max-age=0, no-cache, no-store"); HttpReq.SetRequestHeader("Pragma", "no-cache"); yield return(HttpReq.Send()); if (!HttpReq.isNetworkError && HttpReq.responseCode == 200) { assetsInfo.Datas = HttpReq.downloadHandler.data; FileBuffs.Enqueue(assetsInfo); HttpReq = null; HotFixSystem.I.HotFixFullSize += assetsInfo.Size; } else { Debug.LogErrorFormat("下载资源{0}失败 {1} responseCode == {2}", HttpReq.url, HttpReq.error, HttpReq.responseCode); DownloadFail = true; } yield return(null); } DownloadFinished = true; }
AssetsInfo AddAssets(bool isAsset) { if (isAssets) { GUILayout.BeginVertical("Box"); img = EditorGUILayout.ObjectField("图片", img, typeof(Texture2D), true) as Texture2D; bgm = EditorGUILayout.ObjectField("背景音乐", bgm, typeof(AudioClip), true) as AudioClip; voice = EditorGUILayout.ObjectField("人物配音", voice, typeof(AudioClip), true) as AudioClip; effectAudio = EditorGUILayout.ObjectField("效果音", effectAudio, typeof(AudioClip), true) as AudioClip; GUILayout.EndVertical(); } AssetsInfo assetsInfo = new AssetsInfo(); assetsInfo.img = AssetDatabase.GetAssetPath(img) ?? ""; assetsInfo.bgm = GetPathString(bgm); assetsInfo.voice = GetPathString(voice); assetsInfo.effectVoice = GetPathString(effectAudio); assetsInfo.scenario = ""; return(assetsInfo); }
public Task CopyToVirtualAsync(AssetsInfo info) { return(Task.Run(() => info.Objects? .AsParallel() .ForAll(pair => { string objectPath = $"{_gamePathService.AssetsDir}/objects/{pair.Value.Path}"; string virtualPath = $"{_gamePathService.AssetsDir}/virtual/legacy/{pair.Key}"; string virtualDir = Path.GetDirectoryName(virtualPath); if (!File.Exists(objectPath) || File.Exists(virtualPath)) { return; } // Make sure directory exists Directory.CreateDirectory(virtualDir); File.Copy(objectPath, virtualPath); }) )); }
public bool LoadAllObjects(AssetsInfo info) { string jsonPath = $"{_gamePathService.AssetsDir}/indexes/{info.ID}.json"; if (!File.Exists(jsonPath)) { return(false); } if (info.Objects != null) { return(true); } using var reader = new StreamReader(jsonPath, Encoding.UTF8); var opetions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var jasset = JsonSerializer.Deserialize <JAsset>(reader.ReadToEnd(), opetions); info.Objects = jasset.objects; return(true); }
AssetsInfo AddAssets(bool isAsset, bool isCharacter = false) { AssetsInfo assetsInfo = new AssetsInfo(); if (isCharacter) { assetsInfo.img = SetPath("character/", img); } else { assetsInfo.img = SetPath("sprites/", img); } assetsInfo.bgm = SetPath("audios/bgm/", bgm); assetsInfo.voice = SetPath("audios/voice/", voice); assetsInfo.effectVoice = SetPath("audios/effectVoice/", effectAudio); //if (type == 2) //{ // assetsInfo.scenario.name = scenario.name; //} return(assetsInfo); }
public async ValueTask <bool> DownloadIndexJsonAsync(AssetsInfo info) { try { var json = await _client.GetByteArrayAsync(info.IndexUrl); string indexDir = $"{_gamePathService.AssetsDir}/indexes"; //Make sure directory exists Directory.CreateDirectory(indexDir); File.WriteAllBytes($"{indexDir}/{info.ID}.json", json); return(true); } catch (HttpRequestException ex) { Debug.WriteLine(ex.ToString()); return(false); } catch (OperationCanceledException) { Debug.WriteLine("[ERROR] Index json download time out"); return(false); } }
private void OnResponseGetAssetsInfo(ISFSObject a_infoData) { //assetsinfo if(a_infoData.GetBool(Keys.SUCCESS)) { ISFSArray l_tempSfsArray = a_infoData.GetSFSArray(Keys.ASSETS_INFO); List<AssetsInfo> l_allCurrentInfoList = new List<AssetsInfo>(); for (int indexAssetInfo = 0; indexAssetInfo < l_tempSfsArray.Count; indexAssetInfo++) { AssetsInfo l_temp = new AssetsInfo(); l_temp.AssetID = (int)(l_tempSfsArray.GetSFSObject(indexAssetInfo)).GetLong("assetsid"); l_temp.ImageTargetID = (l_tempSfsArray.GetSFSObject(indexAssetInfo)).GetUtfString("imagetargetid"); l_temp.URL = (l_tempSfsArray.GetSFSObject(indexAssetInfo)).GetUtfString("assetsurl"); l_temp.AssetName = (l_tempSfsArray.GetSFSObject(indexAssetInfo)).GetUtfString("assetname"); l_allCurrentInfoList.Add(l_temp); } GameBaseEvent l_assetsInfoEvent = new GameBaseEvent(eGameEvents.getAssetsInfo.ToString()); GameEventArgs l_eventArg = new GameEventArgs(); l_eventArg.EventData = (object)l_allCurrentInfoList; l_assetsInfoEvent.Args = l_eventArg; dispatchEvent(this, l_assetsInfoEvent); } else { Debug.Log(a_infoData.GetUtfString(Keys.ERROR)); } }
IEnumerator CheckAssetsListCoroutine() { ++AssetsCheckCount; HotFixSystem.I.CheckVersionProgress = 0f; #region 尝试加载Remote资源列表============== Debug.LogFormat("尝试下载Remote资源列表 {0}", RemoteAssetsListUrl); using (UnityWebRequest req = UnityWebRequest.Get(RemoteAssetsListUrl)) { req.SetRequestHeader("Cache-Control", "max-age=0, no-cache, no-store"); req.SetRequestHeader("Pragma", "no-cache"); req.timeout = 5; yield return(req.Send()); if (!req.isNetworkError && req.responseCode == 200) { MemoryStream ms = new MemoryStream(req.downloadHandler.data); VersionHelper.SetRemoteAssetsList(ms); } else { Debug.LogWarningFormat("下载Remote资源列表失败 {0} responseCode == {1}", req.error, req.responseCode); NextHotFixPipeline = EHotFixPipeline.FailRemote; yield break; } } HotFixSystem.I.CheckVersionProgress = 0.1f; yield return(null); #endregion #region 尝试加载本地资源列表============== Debug.LogFormat("尝试加载Persistent资源列表 {0}", PersistentAssetsListPath); WWW www = new WWW(PersistentPrefix + PersistentAssetsListPath); yield return(www); if (string.IsNullOrEmpty(www.error)) { MemoryStream ms = new MemoryStream(www.bytes); VersionHelper.SetPersistentAssetsList(ms); www.Dispose(); www = null; } else { Debug.LogWarningFormat("加载本地资源列表失败 {0}", www.error); if (InitCount < 1) { NextHotFixPipeline = EHotFixPipeline.InitAssets; } else { NextHotFixPipeline = EHotFixPipeline.Fail; } yield break; } HotFixSystem.I.CheckVersionProgress = 0.3f; yield return(null); #endregion Debug.Log("计算需要更新的资源"); HotFixSystem.I.HotFixSize = 0L; HotFixSystem.I.HotFixTotalSize = 0L; HotFixSystem.I.HotFixFileCount = 0; FileBuffs.Clear(); NewAssets.Clear(); ExcessAssets.Clear(); //需要下载的内容 int index = 0; int count = VersionHelper.RemoteAssetsList.Count; foreach (AssetsInfo info in VersionHelper.RemoteAssetsList.Values) { AssetsInfo localInfo = null; if (!VersionHelper.PersistentAssetsList.TryGetValue(info.AssetName, out localInfo) || !info.AssetMD5.Equals(localInfo.AssetMD5)) { NewAssets.Enqueue(info); HotFixSystem.I.HotFixTotalSize += info.Size; ++HotFixSystem.I.HotFixFileCount; } ++index; if (index % 80 == 0 || index == count) { HotFixSystem.I.CheckVersionProgress = 0.3f + 0.3f * (float)index / (float)count; yield return(null); } } Debug.LogFormat("需要更新的资源 {0}", HotFixSystem.I.HotFixFileCount); Debug.Log("计算需要删除的资源"); //需要删除的内容 index = 0; count = VersionHelper.PersistentAssetsList.Count; foreach (AssetsInfo info in VersionHelper.PersistentAssetsList.Values) { if (!VersionHelper.RemoteAssetsList.ContainsKey(info.AssetName)) { ExcessAssets.Enqueue(info); } ++index; if (index % 80 == 0 || index == count) { HotFixSystem.I.CheckVersionProgress = 0.6f + 0.3f * (float)index / (float)count; yield return(null); } } Debug.LogFormat("需要删除的资源 {0}", ExcessAssets.Count); HotFixSystem.I.CheckVersionProgress = 1f; if (HotFixSystem.I.HotFixFileCount > 0) { NextHotFixPipeline = EHotFixPipeline.WaitUserConfirm; } else if (ExcessAssets.Count > 0) { NextHotFixPipeline = EHotFixPipeline.FixAssets; } else { NextHotFixPipeline = EHotFixPipeline.Success; } if (NextHotFixPipeline != EHotFixPipeline.Success && AssetsCheckCount > 1) { NextHotFixPipeline = EHotFixPipeline.Fail; } }