Created
September 17, 2020 14:53
-
-
Save polytropoi/91c1625826783a3ad283bccf6ffccf30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using Siccity.GLTFUtility; | |
using Animancer; | |
public class GLTFAnimancerTest : MonoBehaviour | |
{ | |
public AnimancerComponent animancer; | |
public GameObject result; | |
GameObject armature; | |
AnimationClip[] animClips; | |
Animator animator; | |
IEnumerator Start() { | |
WWW wwwGLTF = new WWW("http://example.com/example.glb"); //your url here | |
yield return new WaitUntil(()=> wwwGLTF.isDone); | |
byte[] gltfBytes = null; | |
gltfBytes = wwwGLTF.bytes; | |
result = Importer.LoadFromBytes(gltfBytes, new ImportSettings(), out animClips); | |
yield return new WaitUntil(()=> result != null); | |
for (int i = 0; i < animClips.Length; i++) { | |
Debug.Log("gots anim clips named " + animClips[i].name); | |
} | |
if (animClips.Length > 0) { | |
armature = result.transform.Find("armature").gameObject; | |
animator = armature.AddComponent<Animator>(); | |
animancer = armature.AddComponent<AnimancerComponent>(); | |
animancer.Animator = animator; | |
PlayAnimation(); | |
} | |
} | |
void PlayAnimation() { | |
Debug.Log("tryna play"); | |
var state = animancer.Play(animClips[0]); | |
state.Time = 0; | |
state.Events.OnEnd = OnAnimationEnd; | |
} | |
void OnAnimationEnd() { | |
PlayAnimation(); | |
Debug.Log("animation ended"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
loads model using https://github.com/Siccity/GLTFUtility with coroutines, but uses the animation control package Animancer -https://kybernetik.com.au/animancer/ -instead of Unity's legacy internal system.