Skip to content

Commit

Permalink
Merge branch 'develop' into release/v7.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisonHough committed Jan 10, 2025
2 parents f0d5de4 + ee7fa5f commit 028e472
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
44 changes: 44 additions & 0 deletions Runtime/AvatarCreator/Scripts/Managers/AvatarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,50 @@ public async Task<GameObject> UpdateAsset(AssetType assetType, object assetId)

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

public async Task<GameObject> UpdateAssets(Dictionary<AssetType, object> assetIdByType)
{
var payload = new AvatarProperties
{
Assets = new Dictionary<AssetType, object>()
};
// if it contains top, bottom or footwear, remove outfit
if (assetIdByType.ContainsKey(AssetType.Top) || assetIdByType.ContainsKey(AssetType.Bottom) || assetIdByType.ContainsKey(AssetType.Footwear))
{
payload.Assets.Add(AssetType.Outfit, string.Empty);
}

// Convert costume to outfit
foreach (var assetType in assetIdByType.Keys)
{
payload.Assets.Add(assetType == AssetType.Costume ? AssetType.Outfit : assetType, assetIdByType[assetType]);
}

byte[] data;
try
{
data = await avatarAPIRequests.UpdateAvatar(avatarId, payload, avatarConfigParameters);
}
catch (Exception e)
{
HandleException(e);
return null;
}

if (ctxSource.IsCancellationRequested)
{
return null;
}
foreach (var assetType in assetIdByType)
{
if (assetType.Key != AssetType.BodyShape)
{
await ValidateBodyShapeUpdate(assetType.Key, assetType.Value);
}
}

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

/// <summary>
/// Function that checks if body shapes are enabled in the studio. This validation is performed only in the editor.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ReadyPlayerMe.AvatarCreator;
Expand Down Expand Up @@ -35,7 +38,18 @@ public async Task LoadAvatar(string avatarId)
public async Task SelectAsset(IAssetData assetData)
{
OnAvatarLoading?.Invoke();
var newAvatar = await avatarManager.UpdateAsset(assetData.AssetType, assetData.Id);
GameObject newAvatar;
if(assetData.AssetType == AssetType.Headwear && ActiveAvatarProperties.Assets.ContainsKey(AssetType.HairStyle))
{
var assets = new Dictionary<AssetType, object>();
assets.Add(AssetType.HairStyle, ActiveAvatarProperties.Assets[AssetType.HairStyle]);
assets.Add(AssetType.Headwear, assetData.Id);
newAvatar = await avatarManager.UpdateAssets(assets);
}
else
{
newAvatar = await avatarManager.UpdateAsset(assetData.AssetType, assetData.Id);
}
SetupLoadedAvatar(newAvatar, ActiveAvatarProperties);
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 028e472

Please sign in to comment.