Before you start
To access any assets, make sure the app has the right permissions. Read more about managing Identity.
Create an asset
To add an asset into a project, follow these steps:
- Use the method
create_asset
by passing all the information insideAssetCreation
. - At least define
Name
andType
values to create an asset. The possible values forType
are:2D Asset
3D Model
Audio
Material
Script
Video
Unity Editor
Other
The created asset is saved as a draft.
asset_creation = AssetCreation( name = "your-asset-name", description = "your-asset-description", type = unity_cloud.assets.AssetType.MODEL_3D, tags = ["your-tag-1", "your-tag-2", "your-tag-3"] ) asset = unity_cloud.assets.create_asset( asset_creation = asset_creation, org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef" )
Update an asset
To change the name, the description, the type, the tags, or the file used for the preview you need to:
- Create an
AssetUpdate
method. - Call the
update_asset
method.
asset_update = AssetUpdate( name = "your-asset-name", description = "your-asset-description", type = unity_cloud.assets.AssetType.MODEL_3D, tags = ["your-tag-1", "your-tag-2", "your-tag-3"], preview_file = "Path/To/File.ext" ) unity_cloud.assets.update_asset( asset_update = asset_update, org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789abcdefghijklmn", asset_version = '1234abcd-ab12-cd34-ef56-123456abcdef' )
Get an asset
To fetch a single asset, call get_asset
.
asset = unity_cloud.assets.get_asset( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789abcdefghijklmn", asset_version = '1234abcd-ab12-cd34-ef56-123456abcdef' )
Get an asset by its label
When the version of the asset is not known, you can fetch an asset by its label using the get_asset_by_label
method. Keep the label
parameter empty to fetch the default version of the asset.
asset = unity_cloud.assets.get_asset_by_label( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789abcdefghijklmn", label = "your-asset-label" )
Get a list of all assets within a project
To fetch all assets contained in a given project, call get_asset_list
.
assets = unity_cloud.assets.get_asset_list( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef" )
Perform an advanced search for assets
To search for assets across an organization, follow these steps:
- Create your filters as dictionnaries or objects that will contain the conditions.
- Create an array that will contain the projects in which to look up. Leave the array empty to search across all projects in the organization.
- Create an array that will contain the collections in which to look up. Leave the array empty to search across all collections and assets not linked to a collection.
- Call
search_assets_in_projects
with the organization ID, your project IDs, your filters, the amount of matches required in the any_filter, the collections, and optionally the maximum number of results returned and the amount to skip for paging purpose.
include_filter = dict() exclude_filter = dict() any_filter = dict() include_filter[SearchableProperties.NAME] = StringFilter(StringLookUpTypes.REGEX, "asset\-.*") project_ids = [] collections = [] search_result = unity_cloud.assets.search_assets_in_projects(org_id, project_ids, include_filter = include_filter, exclude_filter = exclude_filter, any_filter = any_filter, any_query_minimum_match = 1, collections = collections, limit_to = 10, skip = 0)
Create filter for a search query
To create an include_filter
, an exclude_filter
, or an any_filter
, you can use the enum SearchableProperties
as a helper. This enum is provided with a comment on how each each properties should be created. You are not limited to properties in this enum and can write your own, as long as the properties you're writing exist either in an asset, dataset, or file.
To create a filter on a string property, you can either write a simple equal condition, or use an advanced StringFilter
.
include_filter = dict() include_filter[SearchableProperties.DESCRIPTION] = "Description must be exactly equals to this" include_filter[SearchableProperties.NAME] = StringFilter(StringLookUpTypes.wildcard, "incompl*te n*me")
To create a filter on a date property, you can either write a simple equal condition, or use an advanced DateRangeCondition
. Date must be passed.
date_to_compare = datetime.now().isoformat() exclude_filter = dict() exclude_filter[SearchableProperties.DATASETS_CREATED] = date_to_compare exclude_filter[SearchableProperties.FILES_UPDATED] = DateRangeCondition(DateConditionTypes.LESS_THAN, date_to_compare)
Link assets to a project
To link assets to multiple projects, use the link_assets_to_project
method with the project_id
argument.
unity_cloud.assets.link_asset_to_project( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_ids = ["0123456789abcdefghijklmn"], new_project_id = "4567efgh-ab12-cd34-ef56-123456abcdef" )
Remove assets link to a project
To remove assets link to multiple projects, use the unlink_assets_from_project
method with the project_id
argument.
unity_cloud.assets.unlink_asset_from_project( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_ids = ["0123456789abcdefghijklmn"] )
Get an asset preview file URL
To get the URL of the preview file of an asset, use the get_preview_file_url
method.
preview_file_url = unity_cloud.assets.get_preview_file_url( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789abcdefghijklmn", asset_version = '1234abcd-ab12-cd34-ef56-123456abcdef' )
Add an asset reference to an asset
To add a reference to an asset, use the add_asset_reference
method. You can either add a reference by using an asset version or a version label assigned to it.
unity_cloud.assets.add_asset_reference( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", source_asset_id = "0123456789abcdefghijklmn", source_asset_version = '1234abcd-ab12-cd34-ef56-123456abcdef', target_asset_id = "4567efgh-ab12-cd34-ef56-123456abcdef", target_asset_version = '4567efgh-ab12-cd34-ef56-123456abcdef', target_asset_label = "your-asset-label" )
List the references of an asset
To list the references of an asset, use the list_asset_references
method. The context
parameter can be Context.SOURCE
, Context.TARGET
or Context.BOTH
if you want everything.
references = unity_cloud.assets.list_asset_references( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789abcdefghijklmn", asset_version = '1234abcd-ab12-cd34-ef56-123456abcdef', context = Context.SOURCE )
Remove an asset reference
Using the result of the previous method, you can remove a reference to an asset by using the remove_asset_reference
method with the id of a reference.
unity_cloud.assets.remove_asset_reference( org_id = "012345678912", project_id = "1234abcd-ab12-cd34-ef56-123456abcdef", asset_id = "0123456789abcdefghijklmn", asset_version = '1234abcd-ab12-cd34-ef56-123456abcdef', reference_id = "4567efgh-ab12-cd34-ef56-123456abcdef" )