public async void Setup(SyncObject obj) { // TODO: dynamic model change handling if (!obj.HasField("model") || !(obj.GetField("model") is BlobHandle)) { // TODO: obj.WriteErrorLog("Model", $"This object has no model field or not a blob handle. Ignoring."); return; } BlobHandle handle = (BlobHandle)obj.GetField("model"); Blob blob = await obj.Node.ReadBlob(handle); obj.WriteDebugLog("Model", $"Blob {handle} loaded"); // Because UniGLTF.ImporterContext is the parent class of VRMImporterContext, // ( https://github.com/vrm-c/UniVRM/blob/3b68eb7f99bfe78ea9c83ea75511282ef1782f1a/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs#L11 ) // loading procedure is probably almost same (See PlyayerAvatar.cs for VRM loading). // https://github.com/vrm-c/UniVRM/blob/3b68eb7f99bfe78ea9c83ea75511282ef1782f1a/Assets/VRM/UniGLTF/Editor/Tests/UniGLTFTests.cs#L46 ctx = new UniGLTF.ImporterContext(); // ParseGlb parses GLB file. // https://github.com/vrm-c/UniVRM/blob/3b68eb7f99bfe78ea9c83ea75511282ef1782f1a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs#L239 // Currently, only GLB (glTF binary format) is supported because it is self-contained ctx.ParseGlb(blob.Data); ctx.Root = gameObject; await ctx.LoadAsyncTask(); // UniGLTF also has ShowMeshes https://github.com/ousttrue/UniGLTF/wiki/Rutime-API#import ctx.ShowMeshes(); obj.WriteDebugLog("Model", "Model load completed"); LoadComplete?.Invoke(this); }
/// <summary> /// 异步获取/加载资源 /// </summary> /// <param name="name">资源完整路径名</param> /// <param name="onComplete">资源加载完毕时触发委托</param> /// <returns>资源异步加载请求</returns> public AssetAsync GetAssetAsync(string name, LoadComplete onComplete) { CheckInitAsync(); var info = AssetBundleManager.Instance.GetAssetInfo(name); var asset = GetAssetFromCacheAndLoadQueue(info); if (asset != null) { if (asset.IsDone) //资源已加载完毕,直接执行委托并返回请求 { onComplete(asset); AddAssetToDict(info, asset); return(asset); } } else //缓存、正在加载列表都没有请求时新建一个 { asset = new AssetAsync(info); _waitingQueue.Enqueue(asset); _asyncInquiryDict.Add(info, asset); } asset.callbacks += onComplete; //资源未加载完毕,添加委托 if (_loadCoroutine == null) { _loadCoroutine = _mono.StartCoroutine(LoadAssetAsync()); } return(asset); }
/// <summary> /// This method converts a message string into a message class. /// </summary> /// <param name="message">Message string.</param> /// <returns>Message class.</returns> public static Message GetMessage(string message) { MessageType messageType = MessageUtils.GetMessageType(message); switch (messageType) { case MessageType.Current: case MessageType.CurrentAggregation: Current current = new Current(); current.Unpack(message); return(current); case MessageType.Trade: Trade trade = new Trade(); trade.Unpack(message); return(trade); case MessageType.LoadComplete: LoadComplete loadComplete = new LoadComplete(); loadComplete.Unpack(message); return(loadComplete); } MessageBag messageBag = new MessageBag(); messageBag.Unpack(message); return(messageBag); }
private LoadComplete _loadAllComplete; // AssetBundle加载全部完成的委托 /// <summary> /// 构造函数 /// </summary> /// <param name="sceneName">场景名称</param> /// <param name="abName">AssetBundle名称</param> /// <param name="loadAllComplete">加载完成所有AssetBundle的委托</param> public MultiAssetBundleManager(string sceneName, string abName, LoadComplete loadAllComplete) { _currSceneName = sceneName; _currAssetBundleName = abName; _loaderCacheDict = new Dictionary<string, SingleAssetBundleLoader>(); _relationDict = new Dictionary<string, AssetBundleRelation>(); _loadAllComplete = loadAllComplete; }
//销毁 public void destroy() { _bDestroy = true; if (_removeComplete != null) { _removeComplete(this); } _removeComplete = null; _loadComplete = null; if (_effectGameObj != null) { Object.DestroyObject(_effectGameObj); } _effectGameObj = null; if (onEffectDestroy != null) { onEffectDestroy(this); onEffectDestroy = null; } OnEffectEvent = null; onEffectDestroy = null; //EffectManager.getInstance().removeFromList(this); //Resources.UnloadUnusedAssets(); //AssetManager.getInstance().UnloadUnusedResourcesAssets(); }
private IEnumerator LoadAsync(string sceneName) { ResourceLoader.LoadScene(sceneName); AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName); operation.allowSceneActivation = false; int toPercent = 0; int curPercent = 0; while (operation.progress < 0.9f) { toPercent = (int)operation.progress * 100 - curPercent; yield return(IncreaseInstruction(curPercent, toPercent)); } toPercent = 100; yield return(IncreaseInstruction(curPercent, toPercent)); operation.allowSceneActivation = true; yield return(operation); if (null != SwtichingScene) { SwtichingScene.Invoke(); } if (null != LoadComplete) { LoadComplete.Invoke(); } }
public MutilABMgr(string abName, LoadComplete loadCompleteHandle) { m_currentABName = abName; m_ABCompleteHandle = loadCompleteHandle; m_singleABDict = new Dictionary <string, SingleABLoader>(); m_relationDict = new Dictionary <string, ABRelation>(); }
private void StartLoad() { _filmRepository.SetConnection(_connectionString); var films = GetFilms(); var viewFilms = FilmsToViewModel(films); _filmBindingList = new BindingList <FilmViewModel>(viewFilms); LoadComplete?.Invoke(this, EventArgs.Empty); }
public async Task LoadLibraryAsync(string fileName, bool precache = false) { try { LoadProgress?.Invoke(this, new TransitionLibraryProgressEventArgs(0, 1, "loading transitions settings")); var transitions = await ConfigParser.ParseAsync(fileName); foreach (var transition in transitions) { TransitionData?transitionData = null; switch (transition[0]) { case "SoundAndGif": float.TryParse(transition[3], out var duration); transitionData = new SoundAndGifTransitionData(transition[1], transition[2], duration); break; } if (transitionData != null) { if (TransitionCache.ContainsKey(transitionData.Hash)) { TransitionCache[transitionData.Hash].Count++; } else { TransitionCache.Add(transitionData.Hash, transitionData); } } } ListReady?.Invoke(this, null); if (precache) { int current = 0; int total = TransitionCache.Count(); while (current < TransitionCache.Count()) { var toCache = TransitionCache.Skip(current).Take(2).ToList(); Task[] tasks = toCache.Select(tc => tc.Value.PreloadAsync()).ToArray(); await Task.WhenAll(tasks); current += toCache.Count(); LoadProgress?.Invoke(this, new TransitionLibraryProgressEventArgs(current, total, "Preloading")); } } } catch (Exception ex) { CustomMainForm.Log($"{ex.StackTrace}"); CustomMainForm.Log($"{ex.Message}"); } finally { LoadComplete?.Invoke(this, null); } }
public AssetBundleLoader(LoadComplete loadComplete, LoadProgress loadProgress, string bundleName) { mLoadComplete = loadComplete; mLoadProgress = loadProgress; mBundleName = bundleName; mProgress = 0f; mBundlePath = PathUtil.GetWWWPath() + "/" + bundleName; mWWW = null; mAssetLoader = null; }
public SingleABLoader(string abName, LoadComplete loadComplete) { m_assetLoader = null; m_abName = abName; m_loadCompleteHandle = loadComplete; m_abDownLoadPath = PathTools.GetWWWPath() + "/" + m_abName; }
private void CallBack(Scene id, LoadSceneMode lod) { LoadComplete lc = new LoadComplete(); lc.cmd = (int)U3DSENGTOJSMSG.SCENELOADED; JsonData jd = JsonMapper.ToJson(lc); Debug.Log("场景加载成功" + jd.ToString()); ReadJavaInterface.Hello(jd.ToString()); }
public void ReleaseFun(string url, LoadComplete funOnLoadComplete) { AssetInfo assetInfo; if (assertDict.TryGetValue(url, out assetInfo)) { assetInfo.OnLoadComplete -= funOnLoadComplete; } }
/// <summary> /// 构造函数 /// </summary> /// <param name="lc"></param> /// <param name="lp"></param> /// <param name="bundleName"></param> public AssetBundleLoader(LoadComplete lc, LoadProgress lp, string bundleName) { this.lc = lc; this.lp = lp; this.bundleName = bundleName; this.progress = 0; this.bundlePath = PathUtil.GetWWWPath() + "/" + bundleName; this.www = null; this.assetLoader = null; }
/// <summary> /// ロード /// </summary> public void LoadAsset <TObject>(string key, string path, LoadComplete <TObject> loadEndEvent) { if (_LoadHandleList == null) { return; } // if ( !_LoadHandleList.ContainsKey(key) ) ロード済みの場合でも呼ぶ { StartCoroutine(LoadAssetAsync <TObject>(key, path, loadEndEvent)); } }
private void InitialSyncCompleted(MessageBase msg) { lock (readyLock) { _asyncReady = true; _logger.LogDebug("initial sync complete"); if (Ready) { LoadComplete?.Invoke(this, new EventArgs()); } } }
public SingleABLoader(string abName, LoadComplete loadComplete) { m_asetLoader = null; m_abName = abName; m_loadCompleteHandle = loadComplete; m_abDownLoadPath = PathTools.GetWWWPath() + "/" + m_abName; LogHelperLSK.Log("下载路径是: " + m_abDownLoadPath); }
IEnumerator LoadAssets(string strName, LoadComplete callBack, bool isScene) { WWW www = WWW.LoadFromCacheOrDownload(VersionManager.GetResPath("AssetBundle"), 0); yield return(www); List <AssetBundle> assetBundleList = new List <AssetBundle>(); AssetBundle assetBundle = www.assetBundle; assetBundleList.Add(assetBundle); AssetBundleManifest abManifest = assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); foreach (var dependAsset in abManifest.GetAllDependencies(strName.ToLower())) { WWW dependWWW = WWW.LoadFromCacheOrDownload(VersionManager.GetResPath(dependAsset), 0); yield return(dependWWW); assetBundleList.Add(dependWWW.assetBundle); } WWW asset = WWW.LoadFromCacheOrDownload(VersionManager.GetResPath(strName.ToLower()), 0); yield return(asset); AssetBundle assetAB = asset.assetBundle; assetBundleList.Add(assetAB); if (isScene) { SceneManager.LoadScene(strName); if (callBack != null) { callBack(null); } } else { GameObject go = assetAB.LoadAsset <GameObject>(strName); if (callBack != null) { callBack(GameObject.Instantiate(go)); } } foreach (var ab in assetBundleList) { if (ab != null) { ab.Unload(false); } } }
public AssetInfo Load( string url, LoadComplete funOnLoadComplete, AssetType type ) { return(Load( url, funOnLoadComplete, type, false, AssetLoaderLevel.IMMEDIATELY )); }
/// <summary> /// ロード /// </summary> private IEnumerator LoadAssetAsync <TObject>(string key, string path, LoadComplete <TObject> loadEndEvent) { var handle = Addressables.LoadAssetAsync <TObject>(path); yield return(handle); bool isSucceeded = handle.Status == AsyncOperationStatus.Succeeded; if (isSucceeded) { _LoadHandleList.Add(key, new AddressableInfo(path, handle)); } loadEndEvent?.Invoke(isSucceeded, handle.Result); }
public AssetInfo Load( string url, LoadComplete funOnLoadComplete, AssetType type, bool useCache, int nLoadLevel ) { AssetInfo assetInfo; if (assertDict.TryGetValue(url, out assetInfo)) { if (type != AssetType.ONLY_DOWNLOAD) { assetInfo.type = type; } if (assetInfo.load_type == AssetInfo.LOAD_TYPE.LOADED) { if (null != funOnLoadComplete) { assetInfo.OnLoadComplete += funOnLoadComplete; } assetInfo.RaiseLoadComplete(); assetInfo.ClearEvent(); } else { if (null != funOnLoadComplete) { assetInfo.OnLoadComplete += funOnLoadComplete; } UpdateAssetInfoInWaitList(assetInfo, nLoadLevel); } } else { assetInfo = new AssetInfo(url, useCache); assetInfo.type = type; assetInfo.nLoadLevel = nLoadLevel; if (null != funOnLoadComplete) { assetInfo.OnLoadComplete += funOnLoadComplete; } AddAssetInfoToWaitList(assetInfo, nLoadLevel); assertDict.Add(assetInfo.url, assetInfo); } return(assetInfo); }
/// <summary> /// Se ejecuta al cargar el mapa /// </summary> public void OnLoadComplete(string load) { if (!string.IsNullOrEmpty(load)) { IsLoad = load == "bingmapv8_loadcomplete"; if (IsLoad) { LoadComplete?.Invoke(this, EventArgs.Empty); System.Diagnostics.Debug.WriteLine("Se ha cargado el mapa", "BingMapV8"); } } else { } }
/// <summary> /// 加载指定场景中的ab包 /// </summary> /// <param name="sceneName">场景名</param> /// <param name="abName">ab包名</param> /// <param name="loadComplete">加载完成回调</param> /// <returns></returns> public IEnumerator LoadAssetBundle(string sceneName, string abName, LoadComplete loadComplete) { while (!ABManifestLoader.Instance.IsLoadFnish) { yield return(null); } // m_mainfest = ABManifestLoader.Instance.GetAssetBundleManifest(); if (!m_allScenes.ContainsKey(sceneName)) { MutilABMgr temp = new MutilABMgr(abName, loadComplete); m_allScenes.Add(sceneName, temp); } MutilABMgr mutilABMgr = m_allScenes[sceneName]; yield return(mutilABMgr.LoadAssetBundle(abName)); }
void LoadAssets(string path, LoadComplete cb, object obj = null) { if (mAssetsABDic.ContainsKey(path)) { AssetsBundleData abd = mAssetsABDic[path]; abd.depIndex += 1; UnityEngine.Object o = GetObj(abd.ab, path); if (cb != null) { cb.Invoke(o, obj); } } else { SynLoadAssets(path, false, obj, cb); } }
/// <summary> /// 释放所有资源,场景切换时进行调用 /// </summary> public void DisposeAllAssets() { try { foreach (SingleAssetBundleLoader loader in _loaderCacheDict.Values) { // 逐一释放所有加载过的AssetBundle loader.DisposeAll(); } } finally { _loaderCacheDict.Clear(); // 释放加载集合缓存 _loaderCacheDict = null; _relationDict.Clear(); // 释放其他资源 _relationDict = null; _currSceneName = null; _currAssetBundleName = null; _loadAllComplete = null; Resources.UnloadUnusedAssets(); // 卸载无用资源 System.GC.Collect(); // 垃圾收集 } }
/// <summary> /// 下载AssetBundle指定的包 /// </summary> /// <param name="sceneName">场景名称</param> /// <param name="abName">AssetBundle名称</param> /// <param name="loadAllCompleteHandle">加载完成的委托</param> /// <returns></returns> public IEnumerator LoadAssetBundlePack(string sceneName, string abName, LoadComplete loadAllCompleteHandle) { // 参数检查 if (string.IsNullOrEmpty(sceneName) || string.IsNullOrEmpty(abName)) { Debug.LogError($"{GetType()}/LoadAssetBundlePack()方法传入的场景名称和包名称参数为空,无法加载"); yield break; } // 等待Manifest加载完毕 while (!AssetBundleManifestLoader.GetInstance().IsLoadFinish) { yield return(null); } // ab包中的所有依赖项 _manifest = AssetBundleManifestLoader.GetInstance().GetAsstBundleManifest(); if (_manifest == null) { Debug.LogError($"{GetType()}/LoadAssetBundlePack()方法_manifest为空,清单文件出现问题无法加载依赖项"); yield break; } // 场景的包管理类加入到集合中 if (!_sencesDict.ContainsKey(sceneName)) { MultiAssetBundleManager multiMannger = new MultiAssetBundleManager(sceneName, abName, loadAllCompleteHandle); _sencesDict.Add(sceneName, multiMannger); } // 获取多包管理类 MultiAssetBundleManager multiManngerInDict = _sencesDict[sceneName]; if (multiManngerInDict == null) { Debug.LogError($"{GetType()}/LoadAssetBundlePack()中multiManngerInDict为空,场景的多包管理类创建失败"); yield break; } // 加载指定Ab包 yield return(multiManngerInDict?.LoadAssetBundle(abName)); }
static void Load(SaveFile saveFile) { Migrations.Migrate(saveFile); PreLoad?.Invoke(); GameTime.save = saveFile.gameTime; CurrencySystem.instance.save = saveFile.currency; ConveyorSystem.instance.save = saveFile.conveyor; MachineSystem.instance.save = saveFile.machine; TileSelectionManager.instance.save = saveFile.tileSelection; OverviewCameraController.instance.save = saveFile.overviewCameraController; Analytics.instance.save = saveFile.analytics; BackgroundMusic.instance.SetSave(in saveFile.backgroundMusic); InterfaceSelectionManager.instance.SetSave(in saveFile.interfaceSelection); MachineGroupAchievements.instance.SetSave(in saveFile.machineGroupAchievements); MachineUnlockSystem.instance.SetSave(in saveFile.machineUnlocks); ProgressionStore.instance.SetSave(in saveFile.progressionSystem); SpacePlatform.SetSave(in saveFile.spacePlatforms); PostLoad?.Invoke(); LoadComplete?.Invoke(); }
public void Load( string url, LoadComplete funOnLoadComplete, AssetType type ) { AssetInfo infor = AssetLoader.GetInstance().Load(url, type); if (infor.isDone()) { funOnLoadComplete(infor); return; } LoadStruct ls = new LoadStruct(); ls.infor = infor; ls.funOnLoadComplete = funOnLoadComplete; loadingAsset.Insert(0, ls); Count = loadingAsset.Count; }
/// <summary> /// 释放本场景中的所有资源 /// </summary> public void DisposeAllAsset() { List <string> keys = new List <string>(); keys.AddRange(m_singleABDict.Keys); try { for (int i = 0; i < keys.Count; i++) { m_singleABDict[keys[i]].DisposeAll(); } } catch (Exception ex) { Debug.LogError(ex); } finally { m_singleABDict.Clear(); m_singleABDict = null; //释放其他的 m_relationDict.Clear(); m_relationDict = null; m_currentSingleABLoader = null; m_currentScenesName = null; m_currentABName = null; m_ABCompleteHandle = null; //卸载没有使用到的资源 Resources.UnloadUnusedAssets(); //强制GC GC.Collect(); } }
public void LoadAsset(string strName, LoadComplete callBack) { StartCoroutine(LoadAssets(strName, callBack, false)); }