最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Unity_Addressable_Synchronous Workflow(同步工作流程)

2023-04-11 15:56 作者:unity_某某師_高錦錦  | 我要投稿

Synchronous Addressables APIs help to more closely mirror Unity asset loading workflows.?AsyncOperationHandles?now have a method called?WaitForCompletion()?that force the async operation to complete and return the?Result?of the operation.

譯:

API

Result

The result of?WaitForCompletion?is the?Result?of the async operation it is called on. If the operation fails, this returns?default(TObject).

譯:

It is possible to get a?default(TObject)?for a result when the operation doesn't fail. Async operations that auto release their?AsyncOperationHandles?on completion are such cases.?Addressables.InitializeAsync()?and any API with a?autoReleaseHandle?parameter set to true will return?default(TObject)?even though the operations themselves succeeded.

譯:

Performance

It is worth noting that calling?WaitForCompletion?may have performance implications on your runtime when compared to?Resources.Load?or?Instantiate?calls directly. If your?AssetBundle?is local or has been previously downloaded and cached, these performance hits are likely to be negligible. However, this may not be the case for your individual project setup.

譯:

All currently active Asset Load operations are completed when?WaitForCompletion?is called on any Asset Load operation, due to how Async operations are handled in the Engine. To avoid unexpected stalls, use?WaitForCompletion?when the current operation count is known, and the intention is for all active operations to complete synchronously.

譯:

When using?WaitForCompletion, there are performance implications. When using 2021.2.0 or newer, these are minimal. Using an older version can result in delays that scale with the number of Engine Asset load calls that are loading when?WaitForCompletion?is called.

譯:

It is not recommended that you call?WaitForCompletion?on an operation that is going to fetch and download a remote?AssetBundle. Though, it is possible if that fits your specific situation.

譯:

Code Sample

Scenes

Due to engine limitations scenes cannot be completed synchronously. Calling WaitForCompletion on an operation returned from?Addressables.LoadSceneAsync?will not completely load the scene, even if activateOnLoad is set to true. It will wait for dependencies and assets to complete but the scene activation must be done asynchronously. This can be done using the sceneHandle, or by the?AsyncOperation?from ActivateAsync on the SceneInstance as shown below.

譯:由于引擎限制,場景無法同步完成。即使activateOnLoad設(shè)置為true,調(diào)用Addressables.LoadSceneAsync返回的操作上的WaitForCompletion也無法完全加載場景,它只會等待依賴和資產(chǎn)完成,但場景激活必須異步完成??梢允褂胹ceneHandle或以下示例中SceneInstance上的ActivateAsync的AsyncOperation來完成此操作。

NOTE

Unloading a scene cannot be completed synchronously. Calling WaitForCompleted on a scene unload will not unload the scene or any assets, and a warning will be logged to the console.

譯:卸載場景無法同步完成。在場景卸載上調(diào)用WaitForCompletion將不會卸載場景或任何資產(chǎn),并在控制臺記錄警告。

NOTE

Due to limitations with Scene integration on the main thread through the?SceneManager?API, it is possible to lock the Editor or Player when calling?WaitForCompletion?in association with scene loading. The issue primarily surfaces when loading two scenes in succession, with the second scene load request having?WaitForCompletion?called from its?AsyncOperationHandle.

譯:

Since scene loading takes extra frames to fully integrate on the main thread, and?WaitForCompletion?locks the main thread, you could hit a situation where Addressables has been informed by the?SceneManager?that the first scene is fully loaded, even though it hasn't completed finished all the required operations. At this point, the scene is fully loaded, but the?SceneManager?attempts to call?UnloadUnusedAssets, on the main thread, if the scene was loaded in?Single?mode. Then, the second scene load request locks the main thread with?WaitForCompletion, but cannot begin loading because?SceneManager?requires the?UnloadUnusedAssets?to complete before the next scene can begin loading. In order to avoid this deadlock, it is advised that you either load successive scenes asynchronously, or ensure a sufficient delay is added between scene load requests.

譯:

由于在主線程上通過SceneManager API進(jìn)行場景集成的限制,當(dāng)調(diào)用與場景加載相關(guān)的WaitForCompletion時,可能會鎖定編輯器或播放器。這個問題主要在連續(xù)加載兩個場景時出現(xiàn),第二個場景加載請求從其AsyncOperationHandle調(diào)用WaitForCompletion。由于場景加載需要額外的幀才能在主線程上完全集成,而WaitForCompletion會鎖定主線程,因此您可能會遇到這樣一種情況:Addressables已被SceneManager告知第一個場景已完全加載,即使它尚未完成所有所需的操作。此時,場景已完全加載,但是SceneManager嘗試在主線程上調(diào)用UnloadUnusedAssets,如果場景是在Single模式下加載的,則第二個場景加載請求會使用WaitForCompletion鎖定主線程,但無法開始加載,因為SceneManager需要在下一個場景開始加載之前完成UnloadUnusedAssets。為了避免這種死鎖情況,建議您要么異步加載連續(xù)的場景,要么在場景加載請求之間添加足夠的延遲。

Synchronous Addressables with Custom Operations

Addressables supports custom?AsyncOperations?which support unique implementations of?InvokeWaitForCompletion. This method can be overridden to implement custom synchronous operations.

譯:Addressables支持定制的AsyncOperations,支持InvokeWaitForCompletion的獨特實現(xiàn)??梢灾貙懘朔椒▉韺崿F(xiàn)自定義同步操作。

Custom operations work with?ChainOperations?and?GroupsOperations. If you require chained operations to be completed synchronously, ensure that your custom operations implement?InvokeWaitForCompletion?and create a?ChainOperation?using your custom operations. Similarly,?GroupOperations?are well suited to ensure a collection of?AsyncOperations, including custom operations, complete together.

譯:自定義操作與ChainOperations和GroupsOperations一起使用。如果您需要按順序完成鏈接操作,請確保您的自定義操作實現(xiàn)InvokeWaitForCompletion并使用自定義操作創(chuàng)建ChainOperation。

Both?ChainOperation?and?GroupOperation?have their own implementations of?InvokeWaitForCompletion?that relies on the?InvokeWaitForCompletion?implementations of the operations they depend on.

譯:同樣,GroupOperations非常適合確保包括自定義操作在內(nèi)的一組AsyncOperations一起完成。ChainOperation和GroupOperation都有自己的InvokeWaitForCompletion實現(xiàn),它們依賴于它們所依賴的操作的InvokeWaitForCompletion實現(xiàn)。

WebGL

WebGL does not support?WaitForCompletion. On WebGL, all files are loaded using a web request. On other platforms, a web request gets started on a background thread and the main thread spins in a tight loop while waiting for the web request to finish. This is how Addressables does it for?WaitForCompletion?when a web request is used.

譯:WebGL不支持WaitForCompletion。在WebGL上,所有文件都使用Web請求加載。在其他平臺上,Web請求在后臺線程中啟動,而主線程在等待Web請求完成時會旋轉(zhuǎn)一個緊密的循環(huán)。當(dāng)使用Web請求時,Addressables如何處理WaitForCompletion。

Since WebGL is single-threaded, the tight loop blocks the web request and the operation is never allowed to finish. If a web request finishes the same frame it was created, then?WaitForCompletion?wouldn't have any issue. However, we cannot guarantee this to be the case, and likely it isn't the case for most instances.

譯:由于WebGL是單線程的,緊密的循環(huán)會阻塞Web請求,并且操作永遠(yuǎn)不允許完成。如果Web請求在創(chuàng)建的同一幀中完成,則WaitForCompletion將沒有任何問題。但是,我們無法保證這是通常情況,因此這種情況可能不會發(fā)生

Unity_Addressable_Synchronous Workflow(同步工作流程)的評論 (共 條)

分享到微博請遵守國家法律
晋城| 自治县| 兴宁市| 南和县| 囊谦县| 大冶市| 新干县| 阿尔山市| 兴安盟| 兴仁县| 三门县| 惠水县| 金门县| 铁岭县| 新安县| 烟台市| 宁化县| 盈江县| 新营市| 白沙| 普定县| 武邑县| 建水县| 淮南市| 宿迁市| 永年县| 蓬溪县| 米易县| 那坡县| 恩施市| 红河县| 枞阳县| 石首市| 观塘区| 彭山县| 宁安市| 康保县| 昭通市| 双峰县| 梁平县| 嘉祥县|