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

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

Unity_Addressable_Build scripting(構(gòu)建腳本)

2023-04-04 10:20 作者:unity_某某師_高錦錦  | 我要投稿

There are a few ways in which you can use the Addressables API to customize your project build:

譯:有幾種方法可以使用Addressables API自定義項目構(gòu)建:

  • Start a build from a script譯:從腳本開始構(gòu)建

  • Override an existing script譯:覆蓋現(xiàn)有腳本

  • Extend?BuildScriptBase?or implement?IDataBuilder譯:擴展BuildScriptBase或?qū)崿F(xiàn)IDataBuilder

When you customize a build script to handle different asset types or handle assets in a different way, you might also need to customize the [Play Mode Scripts] so that the Editor can handle those assets in the same way during Play mode.

譯:當(dāng)您自定義構(gòu)建腳本以處理不同類型的資產(chǎn)或以不同方式處理資產(chǎn)時,您可能還需要自定義[Play Mode Scripts],以便在Play模式下編輯器可以以同樣的方式處理這些資產(chǎn)。

Starting an Addressables build from a script

To start an Addressables build from another script, call the?AddressableAssetSettings.BuildPlayerContent?method.

譯:要從另一個腳本開始Addressables構(gòu)建,請調(diào)用AddressableAssetSettings.BuildPlayerContent方法。

Before starting the build, you should set the active?Profile?and the active build script. You can also set a different?AddressableAssetSettings?object than the default, if desired.

譯:在開始構(gòu)建之前,您應(yīng)該設(shè)置活動配置文件和活動構(gòu)建腳本。如果需要,您還可以設(shè)置一個與默認(rèn)值不同的AddressableAssetSettings對象。

There are a few pieces of information that BuildPlayerContent takes into consideration when performing the build: the?AddressableAssetSettingsDefaultObject,?ActivePlayerDataBuilder, and the?addressables_content_state.bin?file.

譯:BuildPlayerContent在執(zhí)行構(gòu)建時考慮了一些信息:AddressableAssetSettingsDefaultObject,ActivePlayerDataBuilder和addressablescontentstate.bin文件。

Set the AddressableAssetSettings

The settings defined by?AddressableAssetSettings?include the list of groups and the profile to use.

譯:AddressableAssetSettings定義的設(shè)置包括要使用的組和配置文件列表。

To access the settings that you see in the Editor (menu:?Window > Asset Management > Addressables > Settings), use the static?AddressableAssetSettingsDefaultObject.Settings?property. However, if desired, you can use a different settings object for a build.

譯:要訪問您在編輯器中看到的設(shè)置(菜單:Window> Asset Management> Addressables> Settings),請使用靜態(tài)AddressableAssetSettingsDefaultObject.Settings屬性。但是,如果需要,您可以為構(gòu)建使用不同的設(shè)置對象。

To load a custom settings object in a build:

譯:要在構(gòu)建中加載自定義設(shè)置對象:

Set the active Profile

A build started with BuildContent uses the variable settings of the active Profile. To set the active Profile as part of your customized build script, assign the ID of the desired profile to the?activeProfileId?field of the?AddressableAssetSettingsDefaultObject.Settings?object.

譯:要設(shè)置活動配置文件,請使用BuildContent啟動的構(gòu)建使用活動配置文件的變量設(shè)置。為了在自定義構(gòu)建腳本中設(shè)置活動配置文件,將所需配置文件的ID分配給AddressableAssetSettingsDefaultObject.Settings對象的activeProfileId字段。

The?AddressableAssetSettings?object contains the list of profiles. Use the name of the desired profile to look up its ID value and then assign the ID to the?activeProfileId?variable:

譯:AddressableAssetSettings對象包含配置文件列表。使用所需配置文件的名稱查找其ID值,然后將ID分配給activeProfileId變量:

Set the active build script

The BuildContent method launches the build based on the current?ActivePlayerDataBuilder?setting. To use a specific build script, assign the index of the IDataBuilder object in the?AddressableAssetSetting.DataBuilders?list to the [ActivePlayerDataBuilderIndex] property.

譯:BuildContent方法根據(jù)當(dāng)前的ActivePlayerDataBuilder設(shè)置啟動構(gòu)建。要使用特定的構(gòu)建腳本,請將AddressableAssetSetting.DataBuilders列表中的IDataBuilder對象的索引分配給[ActivePlayerDataBuilderIndex]屬性。

The build script must be a ScriptableObject that implements?IDataBuilder?and you must add it to the?DataBuilders?list in the?AddressableAssetSettings?instance. Once added to the list, use the standard?List.IndexOf?method to get the index of the object.

譯:構(gòu)建腳本必須是實現(xiàn)IDataBuilder的ScriptableObject,并且必須將其添加到AddressableAssetSettings實例的DataBuilders列表中。添加到列表后,請使用標(biāo)準(zhǔn)的List.IndexOf方法獲取對象的索引。

Launch a build

After setting the profile and builder to use (if desired), you can launch the build:

譯:在將概要文件和構(gòu)建器設(shè)置為使用之后(如果需要的話),您可以啟動構(gòu)建。

To check for success, use BuildPlayerContent(out AddressablesPlayerBuildResult result). result.Error contains any error message returned if the Addressables build failed. If string.IsNullOrEmpty(result.Error) is true, the build was successful.

譯:要檢查是否成功,請使用BuildPlayerContent(out AddressablesPlayerBuildResult result)。如果Addressables構(gòu)建失敗,則result.Error包含任何錯誤消息。如果string.IsNullOrEmpty(result.Error)為true,則構(gòu)建成功。

Example script to launch build

The following example adds a couple of menu commands to the Asset Management > Addressables menu in the Editor. The first command builds the Addressable content using the preset profile and build script. The second command builds the Addressable content, and, if it succeeds, builds the Player, too.

譯:以下示例將一些菜單命令添加到編輯器中的Asset Management>Addressables菜單中。第一個命令使用預(yù)設(shè)配置文件和構(gòu)建腳本構(gòu)建Addressable內(nèi)容。第二個命令構(gòu)建Addressable內(nèi)容,并且如果成功,則也構(gòu)建Player。

Note that if your build script makes setting changes that require a domain reload, you should run the build script using Unity command line options, instead of running it interactively in the Editor. See?Domain reloads and Addressable builds?for more information.

譯:請注意,如果您的構(gòu)建腳本進行了需要重新加載域的設(shè)置更改,則應(yīng)使用Unity命令行選項運行構(gòu)建腳本,而不是在編輯器中進行交互式運行。有關(guān)更多信息,請參見重新加載域和Addressable構(gòu)建。

Domain reloads and Addressables builds

If your scripted build process involves changing settings that trigger a domain reload before it makes an Addressables build, then you should script such builds to use?Unity's command line arguments?rather than interactively running a script in the Editor. These types of settings include:

譯:如果您的腳本化構(gòu)建過程涉及更改設(shè)置,會在進行Addressables構(gòu)建之前觸發(fā)重新加載域,則應(yīng)該編寫腳本以使用Unity的命令行參數(shù),而不是在編輯器中交互式運行腳本。這些類型的設(shè)置包括:

  • Changing the defined compiler symbols譯:更改定義的編譯器符號

  • Changing platform target or target group譯:更改平臺目標(biāo)或目標(biāo)組

When you run a script that triggers a domain reload interactively in the Editor (using a menu command, for example), your Editor script finishes executing before the domain reload occurs. Thus, if you immediately start an Addressables build, both your code and imported assets are still in their original state. You must wait for the domain reload to complete before you start the content build.

譯:當(dāng)您交互式在編輯器中運行觸發(fā)重新加載域的腳本(例如使用菜單命令)時,您的編輯器腳本在重新加載域發(fā)生之前就完成執(zhí)行了。因此,如果您立即啟動Addressables構(gòu)建,則您的代碼和導(dǎo)入的資產(chǎn)仍處于其原始狀態(tài)。在開始內(nèi)容構(gòu)建之前,您必須等待重新加載域完成。

Waiting for the domain reload to finish is relatively straightforward when you run the build from the command line, but can be difficult or impossible to accomplish reliably in an interactive script (for a variety of reasons).

譯:當(dāng)您從命令行運行構(gòu)建時,等待重新加載域完成相對簡單,但在交互式腳本中可靠地完成可能很難或不可能(由于各種原因)。

The following example script defines two functions that can be invoked when running Unity on the command line. The?ChangeSettings?example sets the specified define symbols. The?BuildContentAndPlayer?function runs the Addressables build and the Player build.

譯:以下示例腳本定義了兩個函數(shù),可以在運行Unity時調(diào)用。ChangeSettings示例設(shè)置指定的定義符號。 BuildContentAndPlayer函數(shù)運行Addressables構(gòu)建和Player構(gòu)建。

To call these functions, use?Unity's command line arguments?in a terminal or command prompt or in a shell script:

譯:以下示例腳本定義了兩個函數(shù),可以在運行Unity時調(diào)用。ChangeSettings示例設(shè)置指定的定義符號。 BuildContentAndPlayer函數(shù)運行Addressables構(gòu)建和Player構(gòu)建。

NOTE

If you specify the platform target as a command line parameter, you can perform an Addressables build in the same command. However, if you wanted to change the platform in a script, you should do it in a separate command, such as the?ChangeSettings?function in this example.

譯:如果將平臺目標(biāo)指定為命令行參數(shù),則可以在同一命令中執(zhí)行Addressables構(gòu)建。但是,如果要在腳本中更改平臺,則應(yīng)在單獨的命令中執(zhí)行此操作,例如此示例中的ChangeSettings函數(shù)。

Custom Build Scripting

To configure a new custom script, add it to the?Build and Play Mode Scripts?list.

譯:要配置新的自定義腳本,請將其添加到Build and Play Mode Scripts列表中。

Custom scripts extend the?BuildScriptBase?class or implement the?IDataBuilder?interface. There are several overridable methods, such as?ClearCachedData?and?CanBuildData<T>. If extending the?BuildScriptBase?class, the most notable method to override is?BuildDataImplementation<TResult>. This is the method that is used to setup or build content.

譯:自定義腳本擴展BuildScriptBase類或?qū)崿F(xiàn)IDataBuilder接口。有幾種可重寫的方法,例如ClearCachedData和CanBuildData。如果擴展BuildScriptBase類,則要重寫的最重要的方法是BuildDataImplementation。這是用于設(shè)置或構(gòu)建內(nèi)容的方法。

A custom script is either a Build Script or a Play Mode Script. This is determined by how the?CanBuildData<T>?method is implemented. Build scripts can only build data of the type?AddressablesPlayerBuildResult, so the method is implemented in this way:

譯:自定義腳本是構(gòu)建腳本或播放模式腳本。這取決于CanBuildData方法的實現(xiàn)方式。構(gòu)建腳本只能構(gòu)建AddressablesPlayerBuildResult類型的數(shù)據(jù),因此該方法是以這種方式實現(xiàn)的:

This allows the script to be listed in the?Build/New Build/?menu.

譯:這允許在Build / New Build /菜單中列出腳本。

Play Mode Scripts can only build data of the type?AddressablesPlayModeBuildResult, so the method is implemented in this way:

譯:播放模式腳本只能構(gòu)建AddressablesPlayModeBuildResult類型的數(shù)據(jù),因此該方法是以下方式實現(xiàn)的:

This allows the script to be listed in the?Play Mode Scripts?menu.

譯:這允許在播放模式腳本菜單中列出腳本。

See the?Custom Build and Playmode Scripts Sample?for an example.

譯:有關(guān)示例,請參見Custom Build and Playmode Scripts示例。

Extend the default build script

If you want to use the same basic build as the default build script?BuildScriptPackedMode, but want to treat specific groups or types of assets differently, you can extend the default build script and override the functions within it. If the group or asset the build script is processing is one that you want to treat differently, you can run your own code, otherwise you can call the base class version of the function to use the default algorithm.

譯:如果要使用與默認(rèn)構(gòu)建腳本BuildScriptPackedMode相同的基本構(gòu)建,但要對特定組或類型的資產(chǎn)進行不同的處理,則可以擴展默認(rèn)構(gòu)建腳本并覆蓋其中的函數(shù)。如果構(gòu)建腳本正在處理的組或資產(chǎn)是您想要不同處理的組或資產(chǎn),則可以運行自己的代碼,否則可以調(diào)用該函數(shù)的基類版本以使用默認(rèn)算法。

See the?Addressable variants project?for an example.

譯:有關(guān)示例,請參見Addressable variants項目。

Save the content state

If you support?remote content distribution?and update your content between player releases, you must record the state of your Addressables groups at the time of the build. Recording the state allows you to perform a differential build using the?Update a Previous Build?script.

譯:如果支持遠程內(nèi)容分發(fā)并在播放器發(fā)布之間更新內(nèi)容,則必須記錄構(gòu)建時Addressables組的狀態(tài)。記錄狀態(tài)允許您使用Update a Previous Build腳本執(zhí)行差分構(gòu)建。

See the implementation of?BuildScriptPackedMode?and?ContentUpdateScript, for details.

譯:有關(guān)詳細信息,請參見BuildScriptPackedMode和ContentUpdateScript的實現(xiàn)。

Can I build Addressables when recompiling scripts?

If you have a pre-build step that triggers a domain reload, then you must take special care that the Addressables build itself does not start until after the domain reload is finished.

譯:

如果有預(yù)構(gòu)建步驟觸發(fā)域重新加載,那么必須特別注意在域重新加載完成之后才啟動Addressables構(gòu)建本身。

Using methods such as setting scripting define symbols (PlayerSettings.SetScriptingDefineSymbolsForGroup) or switching active build target (EditorUserBuildSettings.SwitchActiveBuildTarget), triggers scripts to recompile and reload.

譯:使用設(shè)置腳本定義符號(PlayerSettings.SetScriptingDefineSymbolsForGroup)或切換活動構(gòu)建目標(biāo)(EditorUserBuildSettings.SwitchActiveBuildTarget)等方法會觸發(fā)腳本重新編譯和重新加載。

The execution of the Editor code will continue with the currently loaded domain until the domain reloads and execution stops. Any?platform dependent compilation?or custom defines will not be set until after the domain reloads. This can lead to unexpected issues where code relies on these defines to build correctly, and can be easily missed.

譯:編輯器代碼的執(zhí)行將繼續(xù)使用當(dāng)前加載的域,直到重新加載域并停止執(zhí)行為止。任何平臺相關(guān)的編譯或自定義定義都不會在域重新加載之前設(shè)置。這可能會導(dǎo)致意外問題,其中代碼依賴于這些定義來正確構(gòu)建,并且很容易忽略。

Is there a safe way to change scripts before building?

To switch Platform, or modify Editor scripts in code and then continue with the defines set, a domain reload must be performed. Note in this case, -quit argument should not be used or the Editor will exit immediately after execution of the invoked method.

譯:要切換平臺或在代碼中修改編輯器腳本,然后繼續(xù)使用已設(shè)置的定義,必須執(zhí)行域重新加載。請注意,在這種情況下,不應(yīng)使用-quit參數(shù),否則編輯器將在調(diào)用的方法執(zhí)行后立即退出。

When the domain reloads, InitializeOnLoad is invoked. The code below demonstrates how to set scripting define symbols and react to those in the Editor code, building Addressables after the domain reload completes. The same process can be done for switching platforms and?platform dependent compilation.

譯:重新加載域時,將調(diào)用InitializeOnLoad。下面的代碼演示了如何設(shè)置腳本定義符號并在域重新加載完成后構(gòu)建Addressables??梢允褂孟嗤倪^程來切換平臺和平臺相關(guān)的編譯。


Unity_Addressable_Build scripting(構(gòu)建腳本)的評論 (共 條)

分享到微博請遵守國家法律
通州市| 庆元县| 绩溪县| 岑巩县| 贵溪市| 平罗县| 酒泉市| 抚宁县| 长春市| 茶陵县| 道孚县| 藁城市| 深水埗区| 岐山县| 吉木萨尔县| 永修县| 宜城市| 西华县| 颍上县| 宜黄县| 高阳县| 孝感市| 红安县| 钦州市| 黔江区| 丹寨县| 梅州市| 临西县| 内江市| 浮山县| 开封县| 安顺市| 南皮县| 常宁市| 佛坪县| 葫芦岛市| 行唐县| 吐鲁番市| 阆中市| 昭觉县| 南皮县|