Astra Unity 2.6.6
Astra Unity Plugin
Examples/Animation/AnimatingAnAvatar.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Astra;
using Astra.Core;
using Astra.Asset;
namespace Astra.Examples {
public class AnimatingAnAvatar : MonoBehaviour {
public AvatarItem Avatar = null;
public RuntimeAnimatorController Animation = null;
void Start () {
//Immediately attach an animation if we have an avatar already specified
if(Avatar != null)
{
LinkAnimation();
return;
}
//We didn't specify an avatar, so find one now
var queryJob = Catalog.GetAvatars();
queryJob.OnJobDoneMain += (_) =>
{
//the result list is an array of CatalogEntries which encapsulate an asset (in this case an avatar meta block)
var result = queryJob.GetResult();
var rand = UnityEngine.Random.Range(0,result.Count);
var catalogEntry = result[rand];
//now we can actually load the avatar
var avatarJob = Loader.LoadAvatar(catalogEntry);
avatarJob.OnJobDoneMain += (__) =>
{
Avatar = avatarJob.GetResult();
LinkAnimation();
};
};
}
void LinkAnimation()
{
//Astra avatars are procedural so we need a human definition built, this method handles that for you
Avatar.AnimationManager.GenerateHumanAvatar((bool success) => {
if(!success)
{
Astra.Logger.LogError("Failed to configure a humanoid");
return;
}
//our function will create the Animator component but it doesn't know which runtime aniimation controller to use, so we'll specify that here
var animator = Avatar.GetComponent<Animator>();
animator.runtimeAnimatorController = Animation;
});
}
}
}
AvatarItem Avatar
Provide an existing AvatarItem in your scene by dragging it into this reference
Definition: AnimatingAnAvatar.cs:20
RuntimeAnimatorController Animation
This is the animation that we'll be loading onto the Avatar, you must provide your own
Definition: AnimatingAnAvatar.cs:25
Handles Astra logging messages in C# allowing filtering and redirection
Definition: Logger.cs:15
static void LogError(object message)
A one-to-one with UnityEngine.Debug.LogError, records as Info level
Definition: Logger.cs:115
Definition: AnimationManager.cs:10
Definition: DB.cs:5
Definition: AnimatingAnAvatar.cs:9
Definition: AnimationManager.cs:10