Skip to content
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

Feature/dont replace existing avatar on load #138

Merged
merged 16 commits into from
Oct 26, 2023
Merged
5 changes: 0 additions & 5 deletions Runtime/Operations/AvatarProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ public Task<AvatarContext> Execute(AvatarContext context, CancellationToken toke
/// <returns>The <see cref="AvatarContext" />.</returns>
private AvatarContext ProcessAvatarGameObject(AvatarContext context)
{
GameObject oldInstance = GameObject.Find(context.AvatarUri.Guid);
if (oldInstance)
{
Object.DestroyImmediate(oldInstance);
}

((Object) context.Data).name = context.AvatarUri.Guid;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ private async void UpdateAvatar(object assetId, Category category)
}

ProcessAvatar(avatar);
Destroy(currentAvatar);
currentAvatar = avatar;
LoadingManager.DisableLoading();
SDKLogger.Log(TAG, $"Avatar updated in {Time.time - startTime:F2}s");
Expand Down
33 changes: 3 additions & 30 deletions Tests/Editor/AvatarLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,33 +93,6 @@ public IEnumerator AvatarLoader_Fail_Load()
Assert.AreNotEqual(FailureType.None, failureType);
}

[UnityTest]
public IEnumerator AvatarLoader_Replace_Old_Avatar_Instance()
{
GameObject avatarA = null;
GameObject avatarB = null;
var failureType = FailureType.None;

var loaderA = new AvatarObjectLoader();
loaderA.OnCompleted += (_, args) => avatarA = args.Avatar;
loaderA.OnFailed += (_, args) => failureType = args.Type;
loaderA.LoadAvatar(TestAvatarData.DefaultAvatarUri.ModelUrl);

yield return new WaitUntil(() => avatarA != null || failureType != FailureType.None);

var loaderB = new AvatarObjectLoader();
loaderB.OnCompleted += (_, args) => avatarB = args.Avatar;
loaderB.OnFailed += (_, args) => failureType = args.Type;
loaderB.LoadAvatar(TestAvatarData.DefaultAvatarUri.ModelUrl);

yield return new WaitUntil(() => avatarB != null || failureType != FailureType.None);

Animator[] objects = Object.FindObjectsOfType<Animator>();

Assert.AreEqual(1, objects.Length);
Assert.AreEqual(FailureType.None, failureType);
}

[UnityTest]
public IEnumerator AvatarLoader_Clears_Persistent_Cache()
{
Expand Down Expand Up @@ -179,12 +152,12 @@ public IEnumerator AvatarLoader_Cancel_Loading()
public IEnumerator AvatarLoader_Low_LOD_Smaller_than_High_LOD()
{
var failureType = FailureType.None;

var avatarConfig = ScriptableObject.CreateInstance<AvatarConfig>();
avatarConfig.Lod = Lod.Low;
avatarConfig.TextureAtlas = TextureAtlas.Low;
avatarConfig.TextureChannel = Array.Empty<TextureChannel>();

var loader = new AvatarObjectLoader();
loader.OnCompleted += (sender, args) =>
{
Expand All @@ -201,7 +174,7 @@ public IEnumerator AvatarLoader_Low_LOD_Smaller_than_High_LOD()
loader = new AvatarObjectLoader();
avatarConfig.Lod = Lod.High;
loader.AvatarConfig = avatarConfig;

loader.OnCompleted += (sender, args) =>
{
avatar = args.Avatar;
Expand Down