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

[SDK-943] Feature/template filter #270

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 24 additions & 2 deletions Runtime/AvatarCreator/Scripts/AvatarTemplateFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,28 @@

namespace ReadyPlayerMe.AvatarCreator
{
public enum TemplateVersions
{
All,
V1,
V2
}

/// <summary>
/// This class can be used to fetch avatar template data including icon renders from the avatarAPI.
/// </summary>
public class AvatarTemplateFetcher
{
private readonly CancellationToken ctx;
private readonly AvatarAPIRequests avatarAPIRequests;
private const string TEMPLATE_ONBOARDING_USAGE_TYPE = "onboarding";
private const string TEMPLATE_RANDOMIZE_USAGE_TYPE = "randomize";
HarrisonHough marked this conversation as resolved.
Show resolved Hide resolved
private readonly TemplateVersions templateVersions;

public AvatarTemplateFetcher(CancellationToken ctx = default)
public AvatarTemplateFetcher(CancellationToken ctx = default, TemplateVersions templateVersions = TemplateVersions.V2)
{
this.ctx = ctx;
this.templateVersions = templateVersions;
avatarAPIRequests = new AvatarAPIRequests(ctx);
}

Expand All @@ -27,7 +38,18 @@ public AvatarTemplateFetcher(CancellationToken ctx = default)
/// <returns></returns>
public async Task<List<AvatarTemplateData>> GetTemplates()
{
return await avatarAPIRequests.GetAvatarTemplates();
var templates = await avatarAPIRequests.GetAvatarTemplates();
switch (templateVersions)
{
case TemplateVersions.V2:
return templates.Where(template => template.UsageType.Contains(TEMPLATE_ONBOARDING_USAGE_TYPE)).ToList();
case TemplateVersions.V1:
var filteredTemplates = templates.Where(template => template.UsageType.Contains(TEMPLATE_RANDOMIZE_USAGE_TYPE)).ToList();
return filteredTemplates;
case TemplateVersions.All:
default:
return templates;
}
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions Runtime/AvatarCreator/Scripts/Data/AvatarTemplateData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public class AvatarTemplateData : IAssetData
[JsonConverter(typeof(GenderConverter))]
public OutfitGender Gender;
public Texture Texture;
public string UsageType;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ReadyPlayerMe.Core;
using UnityEngine;
using UnityEngine.Serialization;
HarrisonHough marked this conversation as resolved.
Show resolved Hide resolved

namespace ReadyPlayerMe.AvatarCreator
{
Expand All @@ -13,12 +16,14 @@ namespace ReadyPlayerMe.AvatarCreator
public class TemplateSelectionElement : SelectionElement
{
private const string TAG = nameof(TemplateSelectionElement);
[SerializeField] private TemplateVersions templateVersions = TemplateVersions.V2;
private List<AvatarTemplateData> avatarTemplates;
private AvatarTemplateFetcher avatarTemplateFetcher;
private CancellationToken ctx;

private void Awake()
{
avatarTemplateFetcher = new AvatarTemplateFetcher();
avatarTemplateFetcher = new AvatarTemplateFetcher(ctx, templateVersions);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class AvatarAPIRequests
private const string PARTNER = "partner";
private const string DATA = "data";
private const string ID = "id";
private const string TEMPLATE_ONBOARDING_USAGE_TYPE = "onboarding";
HarrisonHough marked this conversation as resolved.
Show resolved Hide resolved

private readonly AuthorizedRequest authorizedRequest;
private readonly CancellationToken ctx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,11 @@ PrefabInstance:
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6589403854911528366, guid: f50201018cf1fde428ce508968a48aab,
type: 3}
propertyPath: templateVersions
value: 2
objectReference: {fileID: 0}
- target: {fileID: 6589403854911528366, guid: f50201018cf1fde428ce508968a48aab,
type: 3}
propertyPath: OnAssetSelected.m_PersistentCalls.m_Calls.Array.size
Expand Down Expand Up @@ -7202,7 +7207,7 @@ PrefabInstance:
- target: {fileID: 1536621870556083727, guid: 2bb6b08b8e48b2d4ca36bf901b0b1a2e,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 100.00006
value: 99.999985
objectReference: {fileID: 0}
- target: {fileID: 1536621870556083728, guid: 2bb6b08b8e48b2d4ca36bf901b0b1a2e,
type: 3}
Expand Down
Loading