When fetching metadata by tags, a key will supersede the tag, so if you want to search by tags it’s best to avoid using keys and vice versa. When fetching metadata by tags you will get all metadata on that object with the same corresponding tag.
// Create an array of sources and keys that we want to fetch
LootLockerMetadataSourceAndKeys[] sourcesAndKeys = new LootLockerMetadataSourceAndKeys[]{
new LootLockerMetadataSourceAndKeys
{
source = LootLockerMetadataSources.currency,
id = "01J7S0CED5K0THCB1ENN9XKQWZ",
keys = new string[] { "icon" }
},
new LootLockerMetadataSourceAndKeys
{
source = LootLockerMetadataSources.catalog_item,
id = "01J9RE51T32WNXSQADNJ5RGQCX",
keys = new string[] { "icon", "featured" }
}
};
// Base64 can be set to content_type "application/x-redacted", use this to avoid accidentally fetching large data files
bool ignoreFiles = true;
LootLockerSDKManager.GetMultisourceMetadata(sourcesAndKeys, (response) =>
{
if (response.success)
{
// Handle the received metadata differently depending on the use cases
foreach (var entry in response.Metadata)
{
// Currency
if (entry.source == LootLockerMetadataSources.currency)
{
// Get the first entry as a base64 (file), this is an image so we convert it to a sprite to be displayed
LootLockerMetadataBase64Value base64String = null;
entry.entries[0].TryGetValueAsBase64(out base64String);
byte[] imageBytes = Convert.FromBase64String(base64String.content);
Texture2D tex = new Texture2D(291, 302);
tex.LoadImage(imageBytes);
tex.filterMode = FilterMode.Point;
Sprite sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
// Add your own code here to display the sprite
}
// Catalog Item
if (entry.source == LootLockerMetadataSources.catalog_item)
{
// Multiple keys requested: loop through to find the correct one
foreach (var catalogItemMetadata in entry.entries)
{
// Handle the image
if (catalogItemMetadata.type == LootLockerMetadataTypes.Base64)
{
// Look above in how LootLockerMetadataSources.currency is handled to see how to handle an image
}
// Handle a bool
if (catalogItemMetadata.type == LootLockerMetadataTypes.Bool)
{
bool featured = catalogItemMetadata.TryGetValueAsBool(out featured);
// Add your own code here to make us of the returned bool value
}
}
}
}
}
else
{
// If it failed, output the error to the console
Debug.Log(response.errorData.message);
}
}, ignoreFiles);
Check out our SDK for more ways of handling the received metadata entries.