Skip to content

Commit

Permalink
feat: log error, when bodyshapes are not enabled in studio (#281)
Browse files Browse the repository at this point in the history
## [SDK-907](https://ready-player-me.atlassian.net/browse/SDK-907)

## Description

-   Throw error, when body shapes are not enabled in the studio
<img width="1415" alt="image"
src="https://github.com/readyplayerme/rpm-unity-sdk-core/assets/107070960/dd264de4-63ea-45b1-a32a-84d207bc5804">


## How to Test

- Enable body shapes in the studio and test, that shapes are applied and
that no error is thrown
- Disable body shapes in the studio and verify, that error is shown and
avatar is not updated

<!-- Update your progress with the task here -->

## Checklist

-   [ ] Tests written or updated for the changes.
-   [ ] Documentation is updated.
-   [ ] Changelog is updated.

<!--- Remember to copy the Changes Section into the commit message when
you close the PR -->





[SDK-907]:
https://ready-player-me.atlassian.net/browse/SDK-907?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
rk132 authored May 27, 2024
2 parents f78b30f + d901613 commit d1cd6ec
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Runtime/AvatarCreator/Scripts/Managers/AvatarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public AvatarCreationResponse(GameObject avatarObject, AvatarProperties properti
/// </summary>
public class AvatarManager : IDisposable
{
private const string ERROR_BODYSHAPES_NOT_ENABLED = "Failed to apply body shapes to the avatar. Please ensure body shapes are enabled in your studio application.";

private const string TAG = nameof(AvatarManager);
private readonly AvatarAPIRequests avatarAPIRequests;
private readonly string avatarConfigParameters;
Expand Down Expand Up @@ -288,9 +290,33 @@ public async Task<GameObject> UpdateAsset(AssetType assetType, BodyType bodyType
{
return null;
}
await ValidateBodyShapeUpdate(assetType, assetId);


return await inCreatorAvatarLoader.Load(avatarId, bodyType, gender, data);
}

/// <summary>
/// Function that checks if body shapes are enabled in the studio. This validation is performed only in the editor.
/// </summary>
/// <param name="assetType">Assets type that was updated</param>
/// <param name="assetId">Asset ID</param>
private async Task ValidateBodyShapeUpdate(AssetType assetType, object assetId)
{
if (assetType != AssetType.BodyShape)
{
return;
}

var data = await avatarAPIRequests.GetAvatarMetadata(avatarId, true);
var hasUpdatedAvatarWithAsset = data.Assets.ContainsKey(assetType) && data.Assets[assetType] == assetId;
if (hasUpdatedAvatarWithAsset)
{
return;
}
Debug.LogError(ERROR_BODYSHAPES_NOT_ENABLED);
}


public async Task<Dictionary<AssetType, AssetColor[]>> LoadAvatarColors()
{
Expand Down

0 comments on commit d1cd6ec

Please sign in to comment.