add ready player me POC

This commit is contained in:
2024-11-22 07:08:52 +02:00
parent 855639487b
commit 7c4e48f388
1033 changed files with 224048 additions and 28 deletions
@@ -0,0 +1,98 @@
using System;
using System.Reflection;
namespace ReadyPlayerMe.Core.WebView
{
/// <summary>
/// Defines all the options for the language translation of the Ready Player Me website.
/// </summary>
public enum Language
{
[StringValue("")] Default,
[StringValue("ch")] Chinese,
[StringValue("de")] German,
[StringValue("en-IE")] EnglishIreland,
[StringValue("en")] English,
[StringValue("es-MX")] SpanishMexico,
[StringValue("es")] Spanish,
[StringValue("fr")] French,
[StringValue("it")] Italian,
[StringValue("jp")] Japanese,
[StringValue("kr")] Korean,
[StringValue("pt-BR")] PortugueseBrazil,
[StringValue("pt")] Portuguese,
[StringValue("tr")] Turkish
}
/// <summary>
/// Defines the options for the avatar body type.
/// </summary>
public enum BodyTypeOption
{
Selectable,
[StringValue("fullbody")] FullBody,
[StringValue("halfbody")] HalfBody
}
/// <summary>
/// Defines the options used for the avatars gender.
/// </summary>
public enum Gender
{
None,
[StringValue("male")] Male,
[StringValue("female")] Female
}
/// <summary>
/// Defines the options used for the WebView and Message panel UI.
/// </summary>
public enum MessageType
{
[StringValue("Loading...")]
Loading,
[StringValue("Network is not reachable.")]
NetworkError,
[StringValue("WebView is only supported on Android and iOS.\nBuild and run on a mobile device.")]
NotSupported
}
// Attribute for storing a string value in the enum field
public class StringValueAttribute : Attribute
{
public StringValueAttribute(string value)
{
Value = value;
}
public string Value { get; }
}
// Extension methods and helpers for enums
public static class EnumHelpers
{
// Helps extracting the string value stored in the StringValue attribute of the enum field
public static string GetValue<T>(this T enumerationValue) where T : struct
{
Type type = enumerationValue.GetType();
if (!type.IsEnum)
{
throw new ArgumentException("EnumerationValue must be of Enum type", nameof(enumerationValue));
}
MemberInfo[] memberInfo = type.GetMember(enumerationValue.ToString());
if (memberInfo.Length > 0)
{
var attrs = memberInfo[0].GetCustomAttributes(typeof(StringValueAttribute), false);
if (attrs.Length > 0)
{
return ((StringValueAttribute) attrs[0]).Value;
}
}
return enumerationValue.ToString();
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 852f772df746d354090fa33a897207f1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 259814
packageName: Ready Player Me Avatar and Character Creator
packageVersion: 7.3.1
assetPath: Assets/Ready Player Me/Core/Runtime/WebView/Data/Enums.cs
uploadId: 704624
@@ -0,0 +1,14 @@
namespace ReadyPlayerMe.Core.WebView
{
/// <summary>
/// A simple class used to define the padding properties used by the WebView UI.
/// </summary>
[System.Serializable]
public class ScreenPadding
{
public int left = 0;
public int top = 0;
public int right = 0;
public int bottom = 0;
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: d156c0f4d728b8f4493c7664a4473772
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 259814
packageName: Ready Player Me Avatar and Character Creator
packageVersion: 7.3.1
assetPath: Assets/Ready Player Me/Core/Runtime/WebView/Data/ScreenPadding.cs
uploadId: 704624
@@ -0,0 +1,63 @@
using System.Text;
using UnityEngine;
using UnityEngine.Serialization;
namespace ReadyPlayerMe.Core.WebView
{
/// <summary>
/// This class is used to define all the settings related to the URL that is used for creating the URL to be loaded in the WebView browser.
/// </summary>
[System.Serializable]
public class UrlConfig
{
private const string TAG = nameof(UrlConfig);
private const string CLEAR_CACHE_PARAM = "clearCache";
private const string FRAME_API_PARAM = "frameApi";
private const string SOURCE_PARAM = "source";
private const string SELECT_BODY_PARAM = "selectBodyType";
private const string LOGIN_TOKEN_PARAM = "token";
[Tooltip("Language of the RPM website.")]
public Language language = Language.Default;
[Tooltip("Check if you want user to create a new avatar every visit. If not checked, avatar editor will continue from previously created avatar.")]
public bool clearCache;
[Tooltip("Skip gender selection and create avatars with selected gender. Ignored if Quick Start is checked.")]
public Gender gender = Gender.None;
[FormerlySerializedAs("bodyType"), Tooltip("Skip body type selection and create avatars with selected body type. Ignored if Quick Start is checked.")]
public BodyTypeOption bodyTypeOption = BodyTypeOption.Selectable;
/// <summary>
/// Builds RPM website URL for partner with given parameters.
/// </summary>
/// <returns>The Url to load in the WebView.</returns>
public string BuildUrl(string loginToken = "")
{
var builder = new StringBuilder($"https://{CoreSettingsHandler.CoreSettings.Subdomain}.readyplayer.me/");
builder.Append(language != Language.Default ? $"{language.GetValue()}/" : string.Empty);
builder.Append($"avatar?{FRAME_API_PARAM}");
#if !UNITY_EDITOR && UNITY_ANDROID
builder.Append($"&{SOURCE_PARAM}=unity-android-avatar-creator");
#elif !UNITY_EDITOR && UNITY_IOS
builder.Append($"&{SOURCE_PARAM}=unity-ios-avatar-creator");
#else
builder.Append($"&{SOURCE_PARAM}=unity-avatar-creator");
#endif
builder.Append(clearCache ? $"&{CLEAR_CACHE_PARAM}" : string.Empty);
if (loginToken != string.Empty)
{
builder.Append($"&{LOGIN_TOKEN_PARAM}={loginToken}");
}
builder.Append(gender != Gender.None ? $"&gender={gender.GetValue()}" : string.Empty);
builder.Append(bodyTypeOption == BodyTypeOption.Selectable ? $"&{SELECT_BODY_PARAM}" : $"&bodyType={bodyTypeOption.GetValue()}");
var url = builder.ToString();
SDKLogger.AvatarLoaderLogger.Log(TAG, url);
return url;
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 109e041e67cd7274c86eabd46af564ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 259814
packageName: Ready Player Me Avatar and Character Creator
packageVersion: 7.3.1
assetPath: Assets/Ready Player Me/Core/Runtime/WebView/Data/UrlConfig.cs
uploadId: 704624
@@ -0,0 +1,12 @@
using System.Collections.Generic;
namespace ReadyPlayerMe.Core.WebView
{
public struct WebMessage
{
public string type;
public string source;
public string eventName;
public Dictionary<string, object> data;
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 02b9cae38652cf34085cec61e073c265
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 259814
packageName: Ready Player Me Avatar and Character Creator
packageVersion: 7.3.1
assetPath: Assets/Ready Player Me/Core/Runtime/WebView/Data/WebMessage.cs
uploadId: 704624