Skip to content

Commit ee7fa5f

Browse files
committed
Merge branch 'feature/headwear-equip-fix' into develop
2 parents d5a685d + 6d1302e commit ee7fa5f

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

Runtime/AvatarCreator/Scripts/Managers/AvatarManager.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,50 @@ public async Task<GameObject> UpdateAsset(AssetType assetType, object assetId)
229229

230230
return await inCreatorAvatarLoader.Load(avatarId, gender, data);
231231
}
232+
233+
public async Task<GameObject> UpdateAssets(Dictionary<AssetType, object> assetIdByType)
234+
{
235+
var payload = new AvatarProperties
236+
{
237+
Assets = new Dictionary<AssetType, object>()
238+
};
239+
// if it contains top, bottom or footwear, remove outfit
240+
if (assetIdByType.ContainsKey(AssetType.Top) || assetIdByType.ContainsKey(AssetType.Bottom) || assetIdByType.ContainsKey(AssetType.Footwear))
241+
{
242+
payload.Assets.Add(AssetType.Outfit, string.Empty);
243+
}
244+
245+
// Convert costume to outfit
246+
foreach (var assetType in assetIdByType.Keys)
247+
{
248+
payload.Assets.Add(assetType == AssetType.Costume ? AssetType.Outfit : assetType, assetIdByType[assetType]);
249+
}
250+
251+
byte[] data;
252+
try
253+
{
254+
data = await avatarAPIRequests.UpdateAvatar(avatarId, payload, avatarConfigParameters);
255+
}
256+
catch (Exception e)
257+
{
258+
HandleException(e);
259+
return null;
260+
}
261+
262+
if (ctxSource.IsCancellationRequested)
263+
{
264+
return null;
265+
}
266+
foreach (var assetType in assetIdByType)
267+
{
268+
if (assetType.Key != AssetType.BodyShape)
269+
{
270+
await ValidateBodyShapeUpdate(assetType.Key, assetType.Value);
271+
}
272+
}
273+
274+
return await inCreatorAvatarLoader.Load(avatarId, gender, data);
275+
}
232276

233277
/// <summary>
234278
/// Function that checks if body shapes are enabled in the studio. This validation is performed only in the editor.

Samples~/AvatarCreatorSamples/AvatarCreatorElements/Scripts/AvatarHandler.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
25
using System.Threading;
36
using System.Threading.Tasks;
47
using ReadyPlayerMe.AvatarCreator;
@@ -35,7 +38,18 @@ public async Task LoadAvatar(string avatarId)
3538
public async Task SelectAsset(IAssetData assetData)
3639
{
3740
OnAvatarLoading?.Invoke();
38-
var newAvatar = await avatarManager.UpdateAsset(assetData.AssetType, assetData.Id);
41+
GameObject newAvatar;
42+
if(assetData.AssetType == AssetType.Headwear && ActiveAvatarProperties.Assets.ContainsKey(AssetType.HairStyle))
43+
{
44+
var assets = new Dictionary<AssetType, object>();
45+
assets.Add(AssetType.HairStyle, ActiveAvatarProperties.Assets[AssetType.HairStyle]);
46+
assets.Add(AssetType.Headwear, assetData.Id);
47+
newAvatar = await avatarManager.UpdateAssets(assets);
48+
}
49+
else
50+
{
51+
newAvatar = await avatarManager.UpdateAsset(assetData.AssetType, assetData.Id);
52+
}
3953
SetupLoadedAvatar(newAvatar, ActiveAvatarProperties);
4054
}
4155

Samples~/AvatarCreatorSamples/AvatarCreatorWizard/Scripts/Utils/AssetTypeHelper.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)