add ready player me POC
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7cd98c6bf4887c42bd73ec2b3319b34
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace ReadyPlayerMe.Core.WebView
|
||||
{
|
||||
/// <summary>
|
||||
/// This class is responsible for displaying and updating a UI panel and message text.
|
||||
/// </summary>
|
||||
public class MessagePanel : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Text messageLabel;
|
||||
|
||||
/// <summary>
|
||||
/// Set message from a string value.
|
||||
/// </summary>
|
||||
/// <param name="message">Message to display.</param>
|
||||
public void SetMessage(string message)
|
||||
{
|
||||
messageLabel.text = message;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set message from a message type.
|
||||
/// </summary>
|
||||
/// <param name="type">Describes the option for the message that is to be displayed.</param>
|
||||
public void SetMessage(MessageType type)
|
||||
{
|
||||
messageLabel.text = type.GetValue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set message panel visibility.
|
||||
/// </summary>
|
||||
public void SetVisible(bool visible)
|
||||
{
|
||||
gameObject.SetActive(visible);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set message panel padding in pixels.
|
||||
/// </summary>
|
||||
public void SetMargins(int left, int top, int right, int bottom)
|
||||
{
|
||||
var rect = transform as RectTransform;
|
||||
if (rect != null)
|
||||
{
|
||||
rect.offsetMax = new Vector2(-right, -top);
|
||||
rect.offsetMin = new Vector2(left, bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da6aecf803b15f446ad259836bb2cf4f
|
||||
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/MessagePanel.cs
|
||||
uploadId: 704624
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace ReadyPlayerMe.Core.WebView
|
||||
{
|
||||
public struct AssetRecord
|
||||
{
|
||||
public string UserId;
|
||||
public string AssetId;
|
||||
}
|
||||
|
||||
public static class WebMessageHelper
|
||||
{
|
||||
private const string DATA_URL_FIELD_NAME = "url";
|
||||
private const string ID_KEY = "id";
|
||||
private const string USER_ID_KEY = "userId";
|
||||
private const string ASSET_ID_KEY = "assetId";
|
||||
|
||||
public static string GetAvatarUrl(this WebMessage webMessage)
|
||||
{
|
||||
webMessage.data.TryGetValue(DATA_URL_FIELD_NAME, out var avatarUrlObject);
|
||||
return (string) avatarUrlObject ?? string.Empty;
|
||||
}
|
||||
|
||||
public static string GetUserId(this WebMessage webMessage)
|
||||
{
|
||||
webMessage.data.TryGetValue(ID_KEY, out var userIdObject);
|
||||
return (string) userIdObject ?? string.Empty;
|
||||
}
|
||||
|
||||
public static AssetRecord GetAssetRecord(this WebMessage webMessage)
|
||||
{
|
||||
webMessage.data.TryGetValue(ASSET_ID_KEY, out var assetIdObject);
|
||||
webMessage.data.TryGetValue(USER_ID_KEY, out var userIdObject);
|
||||
var assetRecord = new AssetRecord();
|
||||
assetRecord.AssetId = (string) assetIdObject ?? string.Empty;
|
||||
assetRecord.UserId = (string) userIdObject ?? string.Empty;
|
||||
return assetRecord;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc0f294ec3d9d994ead938c7159b55d9
|
||||
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/WebMessageHelper.cs
|
||||
uploadId: 704624
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace ReadyPlayerMe.Core.WebView
|
||||
{
|
||||
// Event to call when avatar is created, receives GLB url.
|
||||
[Serializable] public class WebViewEvent : UnityEvent<string>
|
||||
{
|
||||
}
|
||||
|
||||
// Event to call when avatar is created, receives GLB url.
|
||||
[Serializable] public class AssetUnlockEvent : UnityEvent<AssetRecord>
|
||||
{
|
||||
}
|
||||
|
||||
public static class WebViewEvents
|
||||
{
|
||||
public const string AVATAR_EXPORT = "v1.avatar.exported";
|
||||
public const string USER_SET = "v1.user.set";
|
||||
public const string USER_AUTHORIZED = "v1.user.authorized";
|
||||
public const string ASSET_UNLOCK = "v1.asset.unlock";
|
||||
public const string USER_UPDATED = "v1.user.updated";
|
||||
public const string USER_LOGOUT = "v1.user.logout";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9437fef0b1489a04c9d987396b9c08b1
|
||||
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/WebViewEvents.cs
|
||||
uploadId: 704624
|
||||
Reference in New Issue
Block a user