Unity_Addressable_Getting addresses at runtime(在運(yùn)行時(shí)獲取addresses )
Getting addresses at runtime
By default, Addressables uses the address you assign to an asset as the?PrimaryKey?value of its?IResourceLocation?instance. (If you disable the?Include Addresses in Catalog?option of the Addressables group to which the asset belongs, the PrimaryKey could be a GUID, label, or an empty string.) If you want to get the address of an asset that you load with an AssetReference or label, you can first load the asset's locations, as described in?Loading Assets by Location. You can then use the IResourceLocation instance to both access the PrimaryKey value and to load the asset.
譯:默認(rèn)情況下,Addressables將您為資產(chǎn)分配的地址用作其IResourceLocation實(shí)例的PrimaryKey值。(如果禁用了所屬于資產(chǎn)的Addressables組中的Include Addresses in Catalog選項(xiàng),則PrimaryKey可能是GUID、標(biāo)簽或空字符串。)如果要獲取使用AssetReference或標(biāo)簽加載的資產(chǎn)的地址,可以首先加載資產(chǎn)的位置,如“按位置加載資產(chǎn)”所述。然后可以使用IResourceLocation實(shí)例來訪問PrimaryKey值和加載資產(chǎn)。
The following example gets the address of the asset assigned to an?AssetReference?object named?MyRef1
:以下示例獲取分配給名為MyRef1的AssetReference對(duì)象的資產(chǎn)的地址:
譯:
Labels often refer to multiple assets. The following example illustrates how to load multiple Prefab assets and use their primary key value to add them to a dictionary:
譯:標(biāo)簽通常引用多個(gè)資產(chǎn)。以下示例說明如何加載多個(gè)Prefab資產(chǎn)并使用它們的主鍵值將它們添加到字典中: