/// <summary> /// Update the avatar of a UMA character. /// </summary> /// <param name="umaData">UMA data.</param> public virtual void UpdateAvatar(UMAData umaData) { if (umaData) { if (umaData.animationController != null) { var umaTransform = umaData.transform; var oldParent = umaTransform.parent; var originalRot = umaTransform.localRotation; var originalPos = umaTransform.localPosition; var animator = umaData.animator; umaTransform.SetParent(null, false); umaTransform.localRotation = Quaternion.identity; umaTransform.localPosition = Vector3.zero; if (animator == null) { animator = umaData.gameObject.GetComponent <Animator>(); if (animator == null) { animator = umaData.gameObject.AddComponent <Animator>(); } SetAvatar(umaData, animator); animator.runtimeAnimatorController = umaData.animationController; umaData.animator = animator; umaTransform.SetParent(oldParent, false); umaTransform.localRotation = originalRot; umaTransform.localPosition = originalPos; } else { AnimatorState snapshot = new AnimatorState(); #if UNITY_EDITOR snapshot.FreezeTime = FreezeTime; #endif snapshot.SaveAnimatorState(animator, umaData); if (!umaData.KeepAvatar || animator.avatar == null) { UMAUtils.DestroyAvatar(animator.avatar); SetAvatar(umaData, animator); } umaTransform.SetParent(oldParent, false); umaTransform.localRotation = originalRot; umaTransform.localPosition = originalPos; if (animator.runtimeAnimatorController != null) { snapshot.RestoreAnimatorState(animator, umaData); } if (umaData.KeepAvatar) { animator.Rebind(); } } } } }