In this How-to we will demonstrate how to fetch an Asset from the backend to be displayed in your game.
Prerequisites
A created game in the web console
Retrieve Asset
To start retrieving assets you can run following:
Unity Unreal
Copy int count = 10;
LootLockerSDKManager.GetAssetListWithCount(count, (response) =>
{
if (response.success)
{
Debug.Log("Successfully retrieved " + response.assets.Length + " assets");
}
else
{
Debug.Log("Error retrieving assets");
}
});
After the initial method has completed retrieving assets you can call this method to get more:
Unity
Copy LootLockerSDKManager.GetAssetNextList(count, (response) =>
{
if (response.success)
{
Debug.Log("Successfully retrieved second batch of " + response.assets.Length + " assets");
}
else
{
Debug.Log("Error retrieving assets");
}
});
If you want to retrieve all you assets you can keep calling the method until you stop receiving assets.
After finishing retrieving the assets you need, it's best practice to run the following code, as if you try to get assets later, you might start from your previous last retrieved asset.
Unity
This is only relevant for Unity! This is not the case for Unreal.
Copy LootLockerSDKManager.ResetAssetCalls();
Retrieve Assets With Filter
Unity Unreal
Copy int count = 10;
List<LootLocker.LootLockerEnums.AssetFilter> filter = new List<LootLocker.LootLockerEnums.AssetFilter>() { LootLocker.LootLockerEnums.AssetFilter.nonpurchasable };
LootLockerSDKManager.GetAssetListWithCount(count, (response) =>
{
if (response.success)
{
Debug.Log("Successfully retrieved " + response.assets.Length + " assets");
}
else
{
Debug.Log("Error retrieving assets");
}
}, filter);
To use Filters, simply specify the filter you want to retrieve assets with, through the same blueprint as before.
Retrieve Assets by IDs
If you already know the IDs of the assets you wish to get, you can use this method to retrieve them specifically.
Unity Unreal
Copy string[] list = new string[] { "8111" };
LootLockerSDKManager.GetAssetsById(list, (response) =>
{
if (response.success)
{
Debug.Log("Successfully retrieved " + response.assets.Length + " assets");
Debug.Log("First Asset ID: " + response.assets[0].id);
}
else
{
Debug.Log("Error retrieving assets");
}
});
Retrieve Favourite Assets
Unity Unreal
Copy LootLockerSDKManager.ListFavouriteAssets((response) =>
{
if (response.success)
{
Debug.Log("Successfully retrieved " + response.favourites.Length + " assets");
if (response.favourites.Length > 0)
{
Debug.Log("First Asset ID: " + response.favourites[0]);
} else
{
Debug.Log("No favourite assets");
}
}
else
{
Debug.Log("Error retrieving assets");
}
});
Add Favorite Asset
Unity Unreal
Copy LootLockerSDKManager.AddFavouriteAsset("8111", (response) =>
{
if (response.success)
{
Debug.Log("Successfully favourited asset");
}
else
{
Debug.Log("Error favouriting asset");
}
});
Remove Favourite Asset
Unity Unreal
Copy LootLockerSDKManager.RemoveFavouriteAsset("8111", (response) =>
{
if (response.success)
{
Debug.Log("Successfully removed favourite asset");
}
else
{
Debug.Log("Error removing favourite asset");
}
});
Working With Assets For Player in Game
Get All Key Value Pairs to an Instance
Unity Unreal
Copy LootLockerSDKManager.GetAllKeyValuePairsToAnInstance(45781352, (response) =>
{
if (response.success)
{
if (response.storage.Length > 0)
{
Debug.Log("Successfully retrieved " + response.storage.Length + " key value pairs");
}
else
{
Debug.Log("No key value pairs for asset instance");
}
}
else
{
Debug.Log("Error retrieving assets");
}
});
Get A Key Value Pair By Id
Unity Unreal
Copy int assetInstanceID = 84;
int keyValueID = 1;
LootLockerSDKManager.GetAKeyValuePairByIdForAssetInstances(assetInstanceID, keyValueID, (response) =>
{
if (response.success)
{
Debug.Log("Successfully retrieved key value pair");
}
else
{
Debug.Log("Error retrieving key value pair");
}
});
Create A Key Value Pair
Unity Unreal
Copy LootLockerSDKManager.CreateKeyValuePairForAssetInstances(45781352, "some-new-key", "value here", (response) =>
{
if (response.success)
{
Debug.Log("Successfully created key value pair for asset instance");
}
else
{
Debug.Log("Error creating key value pair");
}
});
Update One Or More Key Value Pairs
Unity Unreal
Copy int assetInstanceID = 84;
Dictionary<string, string> multipleTestKeys = new Dictionary<string, string>();
multipleTestKeys.Add("some-new-key", "Some value");
multipleTestKeys.Add("some-other-key", "Some other value");
LootLockerSDKManager.UpdateOneOrMoreKeyValuePairForAssetInstances(assetInstanceID, multipleTestKeys, (response) =>
{
if (response.success)
{
Debug.Log("Successfully updated key value pairs");
}
else
{
Debug.Log("Error updating key value pairs");
}
});
Delete Key Value Pair
Unity Unreal
Copy int assetInstanceID = 84;
int keyValuePairID = 1;
LootLockerSDKManager.DeleteKeyValuePairForAssetInstances(assetInstanceID, keyValuePairID, (response) =>
{
if (response.success)
{
Debug.Log("Successfully removed key value pair");
}
else
{
Debug.Log("Error removing key value pair");
}
});