Skip to content

Improve handing of headwear equipping #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading