[SerializeField] privateAnimator myAnimator;[SerializeField] privatestring myConnectedUserID;privatevoidAwake() {KinetixCore.OnInitialized+= OnInitialize;KinetixCore.Initialize(newKinetixCoreConfiguration() { GameAPIKey ="yourGameAPIKey", PlayAutomaticallyAnimationOnAnimators =true, EnableAnalytics =true });}// This callback is used for the actions made after the SDK is initialized// Such as initializing the UI and Registering our LocalPlayer's animatorprivatevoidOnInitialize(){ // Register local player to receive animation // See "Animation System" documentationKinetixCore.Animation.RegisterLocalPlayerAnimator(myAnimator); // Now, we connect the current user's account to get his emotes // The userID is chosen by you, and must be unique to each user // See "Account Management" documentationKinetixCore.Account.ConnectAccount(myConnectedUserID, () => {Debug.Log("Account connected successfully"); }, () => {Debug.LogError("There was a problem during account connection. Is the GameAPIKey correct?"); });}
Next, we'll finalize it to provide you with a complete template for integrating UGE into your game:
[SerializeField] privateAnimator myAnimator;[SerializeField] privatestring myConnectedUserID;privatevoidAwake() {KinetixCore.OnInitialized+= OnInitialize;KinetixCore.Initialize(newKinetixCoreConfiguration() { GameAPIKey ="yourGameAPIKey", PlayAutomaticallyAnimationOnAnimators =true, EnableAnalytics =true });}// This callback is used for the actions made after the SDK is initialized// Such as initializing the UI and Registering our LocalPlayer's animatorprivatevoidOnInitialize(){ // Register local player to receive animation // See "Animation System" documentationKinetixCore.Animation.RegisterLocalPlayerAnimator(myAnimator); // Now, we connect the current user's account to get his emotes // The userID is chosen by you, and must be unique to each user // See "Account Management" documentationKinetixCore.Account.ConnectAccount(myConnectedUserID, () => {Debug.Log("Account connected successfully"); // You can subscribe to an event to refresh the link when it is expired // (after 5 minutes or when an UGE has been submitted with the current token)KinetixCore.UGC.OnUGCTokenExpired+= DisplayUGELink;DisplayUGELink(); }, () => {Debug.LogError("There was a problem during account connection. Is the GameAPIKey correct?"); });}IEnumeratorFetchEmotesAtInterval(){while (enabled) { // Fetch emotes every 5 minutesyieldreturnnewWaitForSeconds(300);GetPlayerEmotes(); }}publicvoidDisplayUGELink(){ // Example on how to get the linkKinetixCore.UGC.GetUgcUrl((_Url) => { // Enable your UI (a button somewhere in you GUI?) here and // assign it the url to the web app });}// Maybe use a coroutine to fetch the anim every 5 minutes ?publicvoidGetPlayerEmotes(){ // We get the animation KinetixCore.MetadataGetUserAnimationMetadatas(OnPlayerEmoteFetched);}publicvoidOnPlayerEmoteFetched(AnimationMetadata[] _Emotes){ // Let's play the last emote we fetchedPlayEmote(_Emotes[_Emotes.Length-1].Ids.UUID);}publicvoidPlayEmote(string _MyEmoteID){ // Finally we can play the animation on our local playerKinetixCore.Animation.PlayAnimationOnLocalPlayer(_MyEmoteID);}
Let's review the different steps of the code together!
1. Reminder: Initialize the SDK and register a callback
Before Initializing the SDK (which is an asynchronous process), you can register a callback to call subsequent functions of the SDK:
KinetixCore.OnInitialized+= OnInitialize;
Then, you can initialize the SDK with the configuration you want:
To play emotes, you can use an already configured character from your game which has an animator for exemple (custom animation systems are supported, please visit Animation System - Unityfor more info)
You can call the RegisterLocalPlayerAnimator method to easily register a character
// Register local player to receive animation// See "Animation System" documentation// myAvatarID is optionnal and allows you to play an emote specifically retargeted for your uploaded avatar in the Developer PortalKinetixCore.Animation.RegisterLocalPlayerAnimator(myAnimator, myAvatarID);
If you uploaded an avatar in our Developer Portal, you can also pass the avatarID matching the player character you registered to benefit from the Contact-Aware Retargeting.
3. Link your game's account system with Kinetix SDK
We will focus on this part of the code:
// Now, we connect the current user's account to get his emotes// The userID is chosen by you, and must be unique to each user// See "Account Management" documentationKinetixCore.Account.ConnectAccount(string myConnectedUserID, () => {Debug.Log("Account connected successfully");}, () => {Debug.LogError("There was a problem during account connection. Is the GameAPIKey correct?");});
We use the ConnectAccount method, establishing a link between the user account on your end and within Kinetix's system.
The userID you give to Kinetix must be reused each time you want to connect this specific user, and it must remain exclusive to them.
While it can be a hash or any string, we highly recommend anonymizing user data and refraining from incorporating any personal information.
Let's check the following code (inside the success callback of ConnectAccount)
// You can subscribe to an event to refresh the link when it is expired // (after 5 minutes or when an UGE has been submitted with the current token)KinetixCore.UGC.OnUGCTokenExpired+= DisplayUGELink;DisplayUGELink();[...]voidDisplayUGELink(){ // Example on how to get the linkKinetixCore.UGC.GetUgcUrl((_Url) { // Enable your UI (a button somewhere in you GUI?) here and // assign it the url to the web app });}
As you can see, we provide a way to know when a link / token to the Web Application is invalid (either because of the security token expiration or after usage).
You can then call a method to get the link to the Web Application, and attach it to a script to open the web browser (for example with Application.OpenURL)
5. (After processing) Get the emote of your player
To get your player's emotes, you can call GetUserAnimationMetadatas, which will return an array of AnimationMetadata, containing all the info you will ever need (name, thumbnail, file links, etc...)
// Maybe use a coroutine to fetch the anim every 5 minutes ?publicvoidGetPlayerEmotes(){ // We get the animation KinetixCore.MetadataGetUserAnimationMetadatas(OnPlayerEmoteFetched);}publicvoidOnPlayerEmoteFetched(AnimationMetadata[] _Emotes){ // Let's play the last emote we fetchedPlayEmote(_Emotes[_Emotes.Length-1].Ids.UUID);}
As you can see you can get the Id of an emote by accessing the Ids.UUID property of an AnimationMetadata
Once we have the id of the emote we want to play (and the local player has been registered), we can just call:
publicvoidPlayEmote(string _MyEmoteID){ // Finally we can play the animation on our local playerKinetixCore.Animation.PlayAnimationOnLocalPlayer(_MyEmoteID)}