diff --git a/Runtime/AvatarCreator/AvatarManager.cs b/Runtime/AvatarCreator/AvatarManager.cs index 74638da4..5aa46d29 100644 --- a/Runtime/AvatarCreator/AvatarManager.cs +++ b/Runtime/AvatarCreator/AvatarManager.cs @@ -14,25 +14,22 @@ public class AvatarManager : IDisposable { private const string TAG = nameof(AvatarManager); private readonly BodyType bodyType; - private readonly OutfitGender gender; private readonly AvatarAPIRequests avatarAPIRequests; private readonly string avatarConfigParameters; private readonly InCreatorAvatarLoader inCreatorAvatarLoader; private readonly CancellationTokenSource ctxSource; - + private OutfitGender gender; public Action OnError { get; set; } public string AvatarId => avatarId; private string avatarId; /// Body type of avatar - /// Gender of avatar /// Config for downloading preview avatar /// Cancellation token - public AvatarManager(BodyType bodyType, OutfitGender gender, AvatarConfig avatarConfig = null, CancellationToken token = default) + public AvatarManager(BodyType bodyType, AvatarConfig avatarConfig = null, CancellationToken token = default) { this.bodyType = bodyType; - this.gender = gender; if (avatarConfig != null) { @@ -49,15 +46,16 @@ public AvatarManager(BodyType bodyType, OutfitGender gender, AvatarConfig avatar /// /// Properties which describes avatar /// Avatar gameObject - public async Task CreateAvatar(AvatarProperties avatarProperties) + public async Task<(GameObject, AvatarProperties)> CreateAvatar(AvatarProperties avatarProperties) { GameObject avatar = null; try { avatarProperties = await avatarAPIRequests.CreateNewAvatar(avatarProperties); + gender = avatarProperties.Gender; if (ctxSource.IsCancellationRequested) { - return null; + return (null, avatarProperties); } avatarId = avatarProperties.Id; @@ -66,19 +64,18 @@ public async Task CreateAvatar(AvatarProperties avatarProperties) catch (Exception e) { OnError?.Invoke(e.Message); - return avatar; + return (avatar, avatarProperties); } - return avatar; + return (avatar, avatarProperties); } /// /// Create a new avatar from a provided template. /// /// Template id - /// Partner name /// Avatar gameObject - public async Task<(GameObject, AvatarProperties)> CreateAvatarFromTemplate(string id, string partner) + public async Task<(GameObject, AvatarProperties)> CreateAvatarFromTemplate(string id) { GameObject avatar = null; var avatarProperties = new AvatarProperties(); @@ -86,9 +83,10 @@ public async Task CreateAvatar(AvatarProperties avatarProperties) { avatarProperties = await avatarAPIRequests.CreateFromTemplateAvatar( id, - partner, + CoreSettingsHandler.CoreSettings.Subdomain, bodyType ); + gender = avatarProperties.Gender; if (ctxSource.IsCancellationRequested) { return (null, avatarProperties); diff --git a/Runtime/AvatarCreator/WebRequests/AvatarAPIRequests.cs b/Runtime/AvatarCreator/WebRequests/AvatarAPIRequests.cs index 290a894e..0d247eb5 100644 --- a/Runtime/AvatarCreator/WebRequests/AvatarAPIRequests.cs +++ b/Runtime/AvatarCreator/WebRequests/AvatarAPIRequests.cs @@ -138,7 +138,7 @@ public async Task CreateNewAvatar(AvatarProperties avatarPrope { Url = AvatarEndpoints.GetCreateEndpoint(), Method = HttpMethod.POST, - Payload = avatarProperties.ToJson() + Payload = avatarProperties.ToJson(true) }, ctx: ctx ); @@ -154,7 +154,7 @@ public async Task GetAvatar(string avatarId, bool isPreview = false, str var response = await authorizedRequest.SendRequest( new RequestData { - Url =AvatarEndpoints.GetAvatarModelEndpoint(avatarId, isPreview, parameters), + Url = AvatarEndpoints.GetAvatarModelEndpoint(avatarId, isPreview, parameters), Method = HttpMethod.GET }, ctx: ctx); diff --git a/Samples~/AvatarCreatorSamples/Scripts/ProfileManager.cs b/Samples~/AvatarCreatorSamples/Scripts/ProfileManager.cs index 040738e5..2ba9bacb 100644 --- a/Samples~/AvatarCreatorSamples/Scripts/ProfileManager.cs +++ b/Samples~/AvatarCreatorSamples/Scripts/ProfileManager.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Text; using Newtonsoft.Json; using ReadyPlayerMe.AvatarCreator; @@ -26,14 +27,11 @@ private void Awake() private void OnEnable() { - profileUI.SignedOut += AuthManager.Logout; AuthManager.OnSignedOut += DeleteSession; } - private void OnDisable() { - profileUI.SignedOut -= AuthManager.Logout; AuthManager.OnSignedOut -= DeleteSession; } @@ -48,9 +46,10 @@ public bool LoadSession() var json = Encoding.UTF8.GetString(bytes); var userSession = JsonConvert.DeserializeObject(json); AuthManager.SetUser(userSession); + SetProfileData(userSession); - SDKLogger.Log(TAG, $"Loaded session from {filePath}"); + SDKLogger.Log(TAG, $"Loaded session from {filePath}"); return true; } @@ -60,7 +59,7 @@ public void SaveSession(UserSession userSession) DirectoryUtility.ValidateDirectory(directoryPath); File.WriteAllBytes(filePath, Encoding.UTF8.GetBytes(json)); SetProfileData(userSession); - + SDKLogger.Log(TAG, $"Saved session to {filePath}"); } @@ -71,7 +70,7 @@ private void SetProfileData(UserSession userSession) char.ToUpperInvariant(userSession.Name[0]).ToString() ); } - + private void DeleteSession() { if (File.Exists(filePath)) @@ -79,7 +78,7 @@ private void DeleteSession() File.Delete(filePath); } profileUI.ClearProfile(); - + SDKLogger.Log(TAG, $"Deleted session at {filePath}"); } } diff --git a/Samples~/AvatarCreatorSamples/Scripts/UI/SelectionScreens/AvatarCreatorSelection.cs b/Samples~/AvatarCreatorSamples/Scripts/UI/SelectionScreens/AvatarCreatorSelection.cs index 67812156..0392025b 100644 --- a/Samples~/AvatarCreatorSamples/Scripts/UI/SelectionScreens/AvatarCreatorSelection.cs +++ b/Samples~/AvatarCreatorSamples/Scripts/UI/SelectionScreens/AvatarCreatorSelection.cs @@ -65,7 +65,6 @@ private async void Setup() avatarManager = new AvatarManager( AvatarCreatorData.AvatarProperties.BodyType, - AvatarCreatorData.AvatarProperties.Gender, inCreatorConfig, ctxSource.Token); avatarManager.OnError += OnErrorCallback; @@ -158,15 +157,14 @@ private async Task LoadAvatar() if (string.IsNullOrEmpty(AvatarCreatorData.AvatarProperties.Id)) { AvatarCreatorData.AvatarProperties.Assets ??= GetDefaultAssets(); - avatar = await avatarManager.CreateAvatar(AvatarCreatorData.AvatarProperties); + (avatar, _) = await avatarManager.CreateAvatar(AvatarCreatorData.AvatarProperties); } else { if (!AvatarCreatorData.IsExistingAvatar) { (avatar, AvatarCreatorData.AvatarProperties) = await avatarManager.CreateAvatarFromTemplate( - AvatarCreatorData.AvatarProperties.Id, - AvatarCreatorData.AvatarProperties.Partner + AvatarCreatorData.AvatarProperties.Id ); } else