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

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

Unity_Addressable_升級到Addressables系統(tǒng)

2023-03-27 11:43 作者:unity_某某師_高錦錦  | 我要投稿

This article covers how to modify your existing project to take advantage of Addressable assets.

譯:本文介紹了如何修改現(xiàn)有項目以使用Addressable?。

Outside of the Addressables system, Unity provides a few "traditional" ways to reference and load assets:

譯:在Addressables系統(tǒng)之外,Unity提供了一些“傳統(tǒng)的”方法來引用和加載資產(chǎn):

  • Scene data: Assets you add directly to a Scene or to a component in a Scene, which the application loads automatically. Unity packages serialized scene data and the assets directly referenced by a scene into a single archive that it includes in your built player application. See?Converting Scenes?and?Using Addressable assets in non-Addressable Scenes.

  • 譯:場景數(shù)據(jù):直接添加到場景或場景中的組件的資產(chǎn),應用程序會自動加載這些資產(chǎn)。Unity將序列化的場景數(shù)據(jù)和直接由場景引用的資產(chǎn)打包到一個單獨的存檔中,包括在你構(gòu)建的播放器應用程序中。參見轉(zhuǎn)換場景和在非可尋址場景中使用可尋址資產(chǎn)。

  • Prefabs: Assets you create using GameObjects and components, and save outside a Scene. See?Converting Prefabs.

  • 譯:預設(shè)物:你使用游戲?qū)ο蠛徒M件創(chuàng)建的資產(chǎn),并保存在場景之外。參見轉(zhuǎn)換預設(shè)物。

  • Resources folders: Assets you place in your project’s Resources folders and load using the Resources API. Unity packages assets in Resources files into a single archive that it includes in your built player application. The Resources archive is separate from the Scene data archive. See?Converting Resources folders.

  • 譯:Resources文件夾:您放置在項目的資源文件夾中的資產(chǎn),并使用資源API加載。Unity將資源文件中的資產(chǎn)打包成一個單一的存檔,它包括在您構(gòu)建的播放器應用程序中。資源歸檔與場景數(shù)據(jù)歸檔是分開的。參見Resources文件夾。

  • AssetBundles: Assets you package in AssetBundles and load with the AssetBundle API. See?Converting AssetBundles.

  • 譯:AssetBundles:你在AssetBundle中打包的資產(chǎn),用AssetBundle API加載。參見AssetBundles

  • StreamingAssets: Files you place in the StreamingAssets folder. Unity includes any files in the StreamingAssets folder in your built player application as is. See?Files in StreamingAssets

  • 譯:StreamingAssets:你放在StreamingAssets文件夾中的文件。Unity包括任何文件在StreamingAssets文件夾在你構(gòu)建的播放器應用程序。參見StreamingAssets中的文件

Converting to Addressables

Content built using Addressables only reference other assets built in that Addressables build. Content that is used or referenced to that is included within both Addressables, and the Player build through the?Scene data?and?Resource folders?is duplicated on disk and in memory if they are both loaded. Due to this limitation the recommended best practice is to convert all?Scene data?and?Resource folders?to the Addressables build system. Reducing the memory overhead due to duplication and allowing all content to be managed using Addressables. Allowing for the content to be either local or remote as well as updatable through?Content Update?builds.

譯:使用Addressables構(gòu)建的內(nèi)容只引用在該Addressables構(gòu)建中構(gòu)建的其他資產(chǎn)。使用或引用的內(nèi)容包含在兩個Addressables中,通過場景數(shù)據(jù)和資源文件夾構(gòu)建的播放器在磁盤和內(nèi)存中復制(如果它們都被加載)。由于這種限制,推薦的最佳實踐是將所有場景數(shù)據(jù)和資源文件夾轉(zhuǎn)換為Addressables構(gòu)建系統(tǒng)。減少由于復制造成的內(nèi)存開銷,并允許使用Addressables管理所有內(nèi)容。允許內(nèi)容是本地或遠程的,并且可以通過內(nèi)容更新構(gòu)建進行更新。

Converting Scenes

The easiest way to integrate Addressables into a project is to move your Scenes out of the?Build Settings?list and make those scenes Addressable. You do need to have one Scene in the list, which is the Scene Unity loads at application startup. You can make a new Scene for this that does nothing else than load your first Addressable Scene.

譯:將可尋址場景集成到項目中最簡單的方法是將場景移出構(gòu)建設(shè)置列表,并使這些場景可尋址。你需要在列表中有一個場景,這是Unity在應用啟動時加載的場景。你可以為此創(chuàng)建一個新的場景,除了加載你的第一個可尋址場景外什么都不做。

To convert your Scenes:

譯:轉(zhuǎn)換場景:

  1. Make a new "initialization" Scene.譯:創(chuàng)建一個新的初始化場景。

  2. Open the?Build Settings?window (menu:?File > Build Settings).譯:?File > Build Settings

  3. Add the initialization Scene to the Scene list.譯: 添加初始化場景到場景列表

  4. Remove the other Scenes from the list.譯:從列表中移除其他場景

  5. Click on each Scene in the project list and check the Addressable option in its Inspector window. Alternatively, you can drag Scene assets to a group in the Addressables Groups window. (Don't make your new initialization Scene Addressable.)譯:

  6. Update the code you use to load Scenes to use the?Addressables?class Scene loading methods rather than the SceneManager methods.譯:點擊項目列表中的每個場景,并在其檢查器窗口中檢查Addressable選項。或者,您可以將場景資產(chǎn)拖到Addressables Groups窗口中的一個組中。(不要讓你的新初始化場景可尋址。)

At this point, you have included all the assets you have in your Scenes in an Addressable group and the Addressables system packages them in an AssetBundle when you build your Addressables content. If you only use one group for all your Scenes, the runtime loading and memory performance should be roughly equivalent to your project’s pre-Addressables state.

譯:在這一點上,你已經(jīng)在一個Addressables組中包含了你在場景中的所有資產(chǎn),當你構(gòu)建你的Addressables內(nèi)容時,Addressables系統(tǒng)將它們打包在一個AssetBundle中。如果你只對所有的場景使用一個組,運行時加載和內(nèi)存性能應該大致相當于項目的pre-Addressables狀態(tài)。

You can now split your one, large Addressable Scene group into multiple groups. The best way to do that depends on the project goals. To proceed, you can move your Scenes into their own groups so that you can load and unload each of them independently of each other. As you do this, you can use the?Analyze tool?to check for duplicated assets that are shared between multiple Scenes. You can avoid duplicating an asset referenced from two different bundles by making the asset itself Addressable. It's often better to move shared assets to their own group as well to reduce interdependencies among your AssetBundles.

譯:你現(xiàn)在可以把一個大的可尋址場景組分成多個組。做到這一點的最佳方式取決于項目目標。接下來,你可以將你的場景移動到它們自己的組中,這樣你就可以獨立地加載和卸載每個場景。當您這樣做時,您可以使用Analyze工具來檢查在多個場景之間共享的重復資產(chǎn)。通過將資產(chǎn)本身設(shè)置為可尋址的,可以避免重復從兩個不同的bundle引用的資產(chǎn)。最好將共享資產(chǎn)移動到它們自己的組中,以減少您的AssetBundles之間的相互依賴。


Using Addressable assets in non-Addressable Scenes

For Scenes that you don't want to make Addressable, you can still use Addressable assets as part of the Scene data through?AssetReferences.

譯:對于你不想使用Addressable的場景,你仍然可以通過AssetReferences使用Addressable作為場景數(shù)據(jù)的一部分。

When you add an AssetReference field to a custom MonoBehaviour or ScriptableObject class, you can assign an Addressable asset to the field in the Unity Editor in much the same way that you would assign an asset as a direct reference. The main difference is that you need to add code to your class to load and release the asset assigned to the AssetReference field (whereas Unity loads direct references automatically when it instantiates your object in the Scene).

譯:當你將一個AssetReference字段添加到一個自定義MonoBehaviour或ScriptableObject類時,你可以在Unity Editor中將一個Addressable資產(chǎn)分配給該字段,就像你將資產(chǎn)分配為直接引用一樣。主要的區(qū)別是,你需要向你的類添加代碼來加載和釋放分配給AssetReference字段的資產(chǎn)(而Unity在場景中實例化你的對象時自動加載直接引用)。

NOTE

You cannot use Addressable assets for the fields of any UnityEngine components in a non-Addressable Scene. For example, if you assign an Addressable mesh asset to a MeshFilter component in a non-Addressable Scene, Unity does not use the Addressable version of that mesh data for the Scene. Instead, Unity copies the mesh asset and includes two versions of the mesh in your application, one in the AssetBundle built for the Addressable group containing the mesh and one in the built-in Scene data of the non-Addressable Scene. (When used in an Addressable Scene, Unity does not copy the mesh data and always loads it from the AssetBundle.)

譯:在非可尋址場景中,您不能為任何UnityEngine組件的字段使用可尋址資產(chǎn)。例如,如果你將可尋址網(wǎng)格資產(chǎn)分配給一個非可尋址場景中的MeshFilter組件,Unity不會為場景使用該網(wǎng)格數(shù)據(jù)的可尋址版本。相反,Unity復制了網(wǎng)格資產(chǎn),并在你的應用程序中包含了兩個版本的網(wǎng)格,一個在為包含網(wǎng)格的可尋址組構(gòu)建的AssetBundle中,一個在非可尋址場景的內(nèi)置場景數(shù)據(jù)中。(當在可尋址場景中使用時,Unity不會復制網(wǎng)格數(shù)據(jù),總是從AssetBundle中加載它。)

To replace direct references with AssetReferences in your custom classes, follow these steps:

譯:要在自定義類中使用AssetReferences替換直接引用,請遵循以下步驟:

  1. Replace your direct references to objects with asset references (for example,?public GameObject directRefMember;?becomes?public AssetReference assetRefMember;).譯:將對對象的直接引用替換為資產(chǎn)引用


  1. Drag assets onto the appropriate component’s Inspector, as you would for a direct reference.譯:將資產(chǎn)拖放到適當組件的檢查器上,就像直接引用一樣

  2. Add runtime code to load the assigned asset using the?Addressables?API.譯:添加運行時代碼,使用Addressables API加載分配的資產(chǎn)

  3. Add code to release the loaded asset when no longer needed.譯:添加代碼以在不再需要時釋放加載的資產(chǎn)。

See?Asset References?for more information about using AssetReference fields.

譯:有關(guān)使用AssetReference字段的更多信息,請參閱AssetReference?。

See?Loading Addressable assets?for more information about loading Addressable assets.

譯:

Converting Prefabs

To convert a Prefab into an Addressable asset, check the?Addressables?option in its Inspector window or drag it to a group in the Addressables?Groups?window.

譯:有關(guān)加載可尋址資產(chǎn)的更多信息,請參見加載可尋址資產(chǎn)。

You don't always need to make Prefabs Addressable when used in an Addressable Scene; Addressables automatically includes Prefabs that you add to the Scene hierarchy as part of the data contained in the Scene’s AssetBundle. If you use a Prefab in more than one Scene, however, you should make the Prefab into an Addressable asset so that the Prefab data isn't duplicated in each Scene that uses it. You must also make a Prefab Addressable if you want to load and instantiate it dynamically at runtime.

譯:當在可尋址場景中使用時,你并不總是需要使預置可尋址;Addressables自動包含你添加到場景層次結(jié)構(gòu)中的prefab,作為包含在場景的AssetBundle中的數(shù)據(jù)的一部分。但是,如果你在多個場景中使用了一個預制件,你應該將該預制件設(shè)置為可尋址資產(chǎn),這樣預制件數(shù)據(jù)就不會在每個使用它的場景中重復。如果你想在運行時動態(tài)加載和實例化它,你還必須創(chuàng)建一個Prefab Addressable。

NOTE

If you use a Prefab in a non-Addressable Scene, Unity copies the Prefab data into the built-in Scene data whether the Prefab is Addressable or not. You can identify assets duplicated between your Addressable asset groups and your non-Addressable Scene data using the?Check Scene to Addressable Duplicate Dependencies?rule in the?Analyze tool.

譯:如果你在不可尋址場景中使用預制,Unity將預制數(shù)據(jù)復制到內(nèi)置場景數(shù)據(jù)中,無論預制是否可尋址。您可以使用Analyze工具中的Check Scene to Addressable Duplicate Dependencies規(guī)則來識別可尋址資產(chǎn)組和非可尋址場景數(shù)據(jù)之間的重復資產(chǎn)。

Converting Resources folders

If your project loads assets in Resources folders, you can migrate those assets to the Addressables system:

譯:如果你的項目在Resources文件夾中加載資產(chǎn),你可以將這些資產(chǎn)遷移到Addressables系統(tǒng):

  1. Make the assets Addressable. To do this, either enable the?Addressable?option in each asset's Inspector window or drag the assets to groups in the Addressables?Groups?window.譯:使資產(chǎn)具有可尋址性。要做到這一點,要么在每個資產(chǎn)的檢查器窗口中啟用可尋址選項,要么將資產(chǎn)拖到可尋址組窗口中的組中。

  2. Change any runtime code that loads assets using the?Resources?API to load them with the?Addressables?API.譯:更改任何使用Resources API加載資產(chǎn)的運行時代碼,以使用Addressables API加載它們。

  3. Add code to release loaded assets when no longer needed.譯:添加代碼以在不再需要時釋放加載的資產(chǎn)。

As with Scenes, if you keep all the former Resources assets in one group, the loading and memory performance should be equivalent. Depending on your project, you can improve performance and flexibility by dividing your assets into separate groups. Use the?Analyze tool?to check for unwanted duplication across AssetBundles.

譯:與scene一樣,如果您將所有以前的Resources資產(chǎn)放在一個組中,那么加載和內(nèi)存性能應該是相等的。根據(jù)您的項目,您可以通過將資產(chǎn)劃分為單獨的組來提高性能和靈活性。使用Analyze工具檢查資產(chǎn)包之間不需要的重復。

When you mark an asset in a Resources folder as Addressable, the system automatically moves the asset to a new folder in your project named Resources_moved. The default address for a moved asset is the old path, omitting the folder name. For example, your loading code might change from:

譯:當您將資源文件夾中的資產(chǎn)標記為Addressable時,系統(tǒng)會自動將該資產(chǎn)移動到項目中名為Resources_moved的新文件夾中。移動資產(chǎn)的默認地址是舊路徑,省略文件夾名稱。例如,您的加載代碼可能從以下更改:

to:

You might have to implement some functionality of the?Resources?class differently after modifying your project to use the Addressables system.

譯:在修改項目以使用Addressables系統(tǒng)之后,您可能必須以不同的方式實現(xiàn)Resources類的某些功能。

For example, consider the?Resources.LoadAll?function. Previously, if you had assets in a folder Resources/MyPrefabs/, and ran Resources.LoadAll<SampleType>("MyPrefabs");, it would have loaded all the assets in Resources/MyPrefabs/ matching type?SampleType. The Addressables system doesn't support this exact functionality, but you can achieve similar results using Addressable?labels.

譯:例如,考慮參考資料。負荷函數(shù)。以前,如果你在Resources/MyPrefabs/文件夾中有資產(chǎn),并運行Resources. loadall <SampleType>("MyPrefabs");,它將加載Resources/MyPrefabs/匹配類型SampleType中的所有資產(chǎn)。Addressables系統(tǒng)并不支持這種確切的功能,但是您可以使用Addressable標簽實現(xiàn)類似的結(jié)果。

Converting AssetBundles

When you first open the?Addressables Groups?window, Unity offers to convert all AssetBundles into Addressables groups. This is the easiest way to migrate your AssetBundle setup to the Addressables system. You must still update your runtime code to load and release assets using the?Addressables?API.

譯:當你第一次打開Addressables Groups窗口時,Unity提供了將所有資產(chǎn)包轉(zhuǎn)換為Addressables組的功能。這是將您的AssetBundle設(shè)置遷移到Addressables系統(tǒng)的最簡單方法。您仍然必須更新運行時代碼以使用Addressables API加載和釋放資產(chǎn)。

If you want to convert your AssetBundle setup manually, click the?Ignore?button. The process for manually migrating your AssetBundles to Addressables is similar to that described for Scenes and the Resources folder:

譯:如果您想手動轉(zhuǎn)換您的AssetBundle設(shè)置,請單擊Ignore按鈕。手動遷移你的資產(chǎn)包到Addressables的過程類似于場景和資源文件夾的描述:

  1. Make the assets Addressable by enabling the?Addressable?option on each asset’s Inspector window or by dragging the asset to a group in the Addressables?Groups?window. The Addressables system ignores existing AssetBundle and Label settings for an asset.譯:通過在每個資產(chǎn)的檢查器窗口上啟用可尋址選項或?qū)①Y產(chǎn)拖到可尋址組窗口中的組中,使資產(chǎn)可尋址。Addressables系統(tǒng)忽略資產(chǎn)的現(xiàn)有AssetBundle和Label設(shè)置。

  2. Change any runtime code that loads assets using the?AssetBundle?or?UnityWebRequestAssetBundle?APIs to load them with the?Addressables?API. You don't need to explicitly load AssetBundle objects themselves or the dependencies of an asset; the Addressables system handles those aspects automatically.譯:更改任何使用AssetBundle或UnityWebRequestAssetBundle API加載資產(chǎn)的運行時代碼,以使用Addressables API加載它們。您不需要顯式地加載AssetBundle對象本身或資產(chǎn)的依賴項;Addressables系統(tǒng)自動處理這些方面。

  3. Add code to release loaded assets when no longer needed.譯:添加代碼以在不再需要時釋放加載的資產(chǎn)。

NOTE

The default path for the address of an asset is its file path. If you use the path as the asset's address, you'd load the asset in the same manner as you would load from a bundle. The Addressable Asset System handles the loading of the bundle and all its dependencies.

譯:資產(chǎn)地址的默認路徑為資產(chǎn)的文件路徑。如果您使用路徑作為資產(chǎn)的地址,您將以與從bundle加載相同的方式加載資產(chǎn)。可尋址資產(chǎn)系統(tǒng)(Addressable Asset System)處理bundle及其所有依賴項的加載。

If you chose the automatic conversion option or manually added your assets to equivalent Addressables groups, then, depending on your group settings, you end up with the same set of bundles containing the same assets. (The bundle files themselves won't be identical.) You can check for unwanted duplication and other potential issues using the?Analyze tool. You can make sure that asset loading and unloading behaves as you expect using the [Event viewer] window.

譯:如果您選擇了自動轉(zhuǎn)換選項,或者手動將資產(chǎn)添加到等效的Addressables組中,那么,根據(jù)您的組設(shè)置,您最終將得到包含相同資產(chǎn)的相同包集。(bundle文件本身不會完全相同。)您可以使用Analyze工具檢查不必要的重復和其他潛在問題。您可以使用[Event viewer]窗口確保資產(chǎn)的加載和卸載行為與您期望的一樣。

Files in StreamingAssets

You can continue to load files from the StreamingAssets folder when you use the Addressables system. However, files in this folder cannot be Addressable nor can files reference other assets in your project.

譯:當您使用Addressables系統(tǒng)時,您可以繼續(xù)從StreamingAssets文件夾加載文件。但是,此文件夾中的文件不能為可尋址文件,也不能引用項目中的其他資產(chǎn)。

The Addressables system does place its runtime configuration files and local AssetBundles in the StreamingAssets folder during a build. (Addressables removes these files at the conclusion of the build process; you won’t see them in the Editor.)

譯:Addressables系統(tǒng)在構(gòu)建過程中將其運行時配置文件和本地資產(chǎn)包放在StreamingAssets文件夾中。(Addressables在構(gòu)建過程結(jié)束時刪除這些文件;你不會在編輯器中看到它們。)



Unity_Addressable_升級到Addressables系統(tǒng)的評論 (共 條)

分享到微博請遵守國家法律
杭锦后旗| 涟源市| 富阳市| 化德县| 疏勒县| 西乡县| 鹤岗市| 仪征市| 新干县| 大石桥市| 南溪县| 澄城县| 大田县| 巴东县| 正蓝旗| 长子县| 正镶白旗| 玛沁县| 瑞昌市| 宣城市| 吴忠市| 大英县| 靖远县| 平邑县| 冕宁县| 东辽县| 九台市| 松江区| 双城市| 双江| 越西县| 静宁县| 炉霍县| 元朗区| 陆丰市| 庆阳市| 临泉县| 武鸣县| 岳西县| 兴城市| 西安市|