Loading Avatars
Developers are able to load a user’s Genie Avatar into an Experience.
Avatar SDK API
There are methods in GeniesAvatarsSdk
API library to initialize the SDK and load a Genies Avatar. Once loaded, it will return a GeniesAvatar
class object with properties to manage the animations.
import { GeniesAvatar, GeniesAvatarsSdk } from 'Genies.Avatars.Sdk';
import { Transform, RuntimeAnimatorController } from 'UnityEngine';
//Optional parameters for loading Avatar
let name: string;
let parent: Transform;
let animatorController: RuntimeAnimatorController;
//Genies Avatar SDK Methods
GeniesAvatarsSdk.InitializeAsync();
GeniesAvatarsSdk.LoadUserAvatarAsync(name, parent, animatorController);
let userAvatar: GeniesAvatar;
//GeniesAvatar Get and Set Animator
userAvatar.Animator;
userAvatar.SetAnimatorController(animator);
TypeScript Example
Load User Avatar
Here is an example that initializes the SDK and loads the user Avatar:
import { GeniesAvatar, GeniesAvatarsSdk } from 'Genies.Avatars.Sdk';
import { MonoBehaviour } from 'UnityEngine'
export default class MyScript extends MonoBehaviour {
async Start() {
//Initialize the SDK
await GeniesAvatarsSdk.InitializeAsync();
//Load the user Avatar
let userAvatar: GeniesAvatar = await GeniesAvatarsSdk.LoadUserAvatarAsync("UserAvatar");
}
}
Animate an Avatar
Here is an example that adds an Animator to the user Avatar and triggers an animation:
import { GeniesAvatar } from 'Genies.Avatars.Sdk';
import { MonoBehaviour, RuntimeAnimatorController, Animator } from 'UnityEngine'
export default class MyScript extends MonoBehaviour {
public animatorController: RuntimeAnimatorController;
public userAvatar: GeniesAvatar;
public TriggerUserAnimation() {
//Set the Avatar's Animator Controller
this.userAvatar.SetAnimatorController(this.animatorController);
//Get the Avatar's Animator
let animator: Animator = this.userAvatar.Animator;
//Trigger an animation
animator.SetTrigger("animationParameterName");
}
}