User Interface
You can import this example in the Package Manager window
Managing Samples
In this example we will use the SDK UI to create and load avatars.
First, open the Avatar UI Example scene. You can find it in:
User Interface → Scenes
Requirements
Add a new layer "Avatar”
First add a new layer called Avatar. To do this go to the Inspector -> Layer -> Add Layer
Then add the name “Avatar” to an empty field
You don't need to care about the layer number, just make sure "Avatar" is written correctly
Using the UI
Variable | Description |
---|---|
UI Prefab | Only change this is you have a custom version of the interface |
Open Interface Key | The interface will open when this key is pressed |
Load UI On Start | If true, the UI will appear when the game starts |
If you want to customize the UI we recommend you to clone our prefab. You can find it in:
User Interface/Prefabs/GUI/Modules
You should make a duplicate of the whole folder since the UI is split in mutliple sub-modules
Now you can create and load your custom avatars inside your game!
Code walkthrough
Open AvatarLoaderUI.cs
csharp
private void Start(){// Initialize a Union Avatars session// We will use this object as our main interface to perform operations// Ex: Login, Downloading Avatars,...session = new ServerSession(logToUnity: true,ct: cancellationToken.Token,organization: Organization // Pass the organization ID here);if(LoadUIOnStart) LoadUI();}private void LoadUI(){if (isUILoaded)return;isUILoaded = true;// Create an instance of the UI prefab. The instance contains a AvatarUIManager// We can use this manager to setup and interact with the interface easilyAvatarUIManager unionUI = Instantiate(uiPrefab).GetComponent<AvatarUIManager>();//First we initialize/setup the UI with our sessionunionUI.SetupUI(session);// The onAvatarSelected event will trigger once an avatar is selected or created// It will return its Avatar MetadataunionUI.onAvatarSelected += BuildAvatar;unionUI.onClose += () => isUILoaded = false;}private async void BuildAvatar(AvatarMetadata avatar){if (avatar == null)throw new System.ArgumentNullException("avatar");session.LogHandler.Info($"Importing avatar: {avatar.Name} ...");try{// Use the AvatarImporter helper to Instantiate and convert avatarsGameObject newAvatar = await AvatarImporter.ImportAvatarAsHumanoid(avatar, null, cancellationToken.Token);session.LogHandler.Info("Avatar Loaded!");SetupAvatarObject(newAvatar);}catch (System.Exception){session.LogHandler.AvatarWarning("Avatar import failed");}}
csharp
private void Start(){// Initialize a Union Avatars session// We will use this object as our main interface to perform operations// Ex: Login, Downloading Avatars,...session = new ServerSession(logToUnity: true,ct: cancellationToken.Token,organization: Organization // Pass the organization ID here);if(LoadUIOnStart) LoadUI();}private void LoadUI(){if (isUILoaded)return;isUILoaded = true;// Create an instance of the UI prefab. The instance contains a AvatarUIManager// We can use this manager to setup and interact with the interface easilyAvatarUIManager unionUI = Instantiate(uiPrefab).GetComponent<AvatarUIManager>();//First we initialize/setup the UI with our sessionunionUI.SetupUI(session);// The onAvatarSelected event will trigger once an avatar is selected or created// It will return its Avatar MetadataunionUI.onAvatarSelected += BuildAvatar;unionUI.onClose += () => isUILoaded = false;}private async void BuildAvatar(AvatarMetadata avatar){if (avatar == null)throw new System.ArgumentNullException("avatar");session.LogHandler.Info($"Importing avatar: {avatar.Name} ...");try{// Use the AvatarImporter helper to Instantiate and convert avatarsGameObject newAvatar = await AvatarImporter.ImportAvatarAsHumanoid(avatar, null, cancellationToken.Token);session.LogHandler.Info("Avatar Loaded!");SetupAvatarObject(newAvatar);}catch (System.Exception){session.LogHandler.AvatarWarning("Avatar import failed");}}