mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-03-21 18:05:03 -05:00
Fix compilation error due to Awaitable not being referenced. Use IAwaitable with no external dependencies.
This commit is contained in:
parent
43bad5636f
commit
3b3756af89
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UniGLTF;
|
||||
using UniGLTF.Utils;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -51,14 +53,16 @@ namespace UniHumanoid
|
|||
x => x);
|
||||
|
||||
/// <summary>
|
||||
/// Avatar を保持する既存の Animatorヒエラルキーの Transform を変更したのちに、
|
||||
/// HumanBone のマッピングを流用して、新たな Avatar を作り直す。
|
||||
/// 古い Avatar は破棄する。
|
||||
/// Recreates an animiator's humanoid avatar.
|
||||
/// The old Avatar is discarded.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method runs asynchronously only in play mode.
|
||||
/// </remarks>
|
||||
public static async Awaitable RebuildHumanAvatar(Animator animator)
|
||||
public static void RebuildHumanAvatar(Animator animator)
|
||||
{
|
||||
var task = RebuildHumanAvatarAsync(animator, new ImmediateCaller());
|
||||
task.Wait();
|
||||
}
|
||||
|
||||
public static async Task RebuildHumanAvatarAsync(Animator animator, IAwaitCaller awaitCaller)
|
||||
{
|
||||
if (animator == null)
|
||||
{
|
||||
|
|
@ -76,19 +80,22 @@ namespace UniHumanoid
|
|||
newAvatar.name = "re-created";
|
||||
|
||||
// var newAvatar = LoadHumanoidAvatarFromAnimator(animator);
|
||||
// Animator.avatar を代入したときに副作用でTransformが変更されるのを回避するために削除します。
|
||||
// 1. Delete this to avoid changing Transform as a side effect when assigning Animator.avatar.
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
GameObject.Destroy(animator);
|
||||
|
||||
// https://github.com/vrm-c/UniVRM/pull/2764
|
||||
// Require IAwaitCaller that has NextFrame capability. RuntimeOnlyAwaitCaller etc. not ImmediateCaller.
|
||||
// Else, the following AddComponent call will fail.
|
||||
await Awaitable.NextFrameAsync();
|
||||
await awaitCaller.NextFrame();
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject.DestroyImmediate(animator);
|
||||
}
|
||||
// 新たに AddComponent する
|
||||
|
||||
// 2. Attach a new one
|
||||
target.AddComponent<Animator>().avatar = newAvatar;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UniGLTF;
|
||||
using UniGLTF.MeshUtility;
|
||||
using UniGLTF.Utils;
|
||||
|
|
@ -53,10 +54,13 @@ namespace VRM
|
|||
/// <param name="go">対象モデルのルート</param>
|
||||
/// <param name="forceTPose">強制的にT-Pose化するか</param>
|
||||
/// <param name="useCurrentBlendShapeWeight">BlendShape の現状をbakeするか</param>
|
||||
/// <remarks>
|
||||
/// This method runs asynchronously only in play mode.
|
||||
/// </remarks>
|
||||
public static async Awaitable Execute(GameObject go, bool forceTPose, bool useCurrentBlendShapeWeight)
|
||||
public static void Execute(GameObject go, bool forceTPose, bool useCurrentBlendShapeWeight)
|
||||
{
|
||||
var task = ExecuteAsync(go, forceTPose, useCurrentBlendShapeWeight, new ImmediateCaller());
|
||||
task.Wait();
|
||||
}
|
||||
|
||||
public static async Task ExecuteAsync(GameObject go, bool forceTPose, bool useCurrentBlendShapeWeight, IAwaitCaller awaitCaller)
|
||||
{
|
||||
if (forceTPose)
|
||||
{
|
||||
|
|
@ -86,7 +90,7 @@ namespace VRM
|
|||
// 回転とスケールが除去された新しいヒエラルキーからAvatarを作る
|
||||
if (go.TryGetComponent<Animator>(out var animator))
|
||||
{
|
||||
await HumanoidLoader.RebuildHumanAvatar(animator);
|
||||
await HumanoidLoader.RebuildHumanAvatarAsync(animator, awaitCaller);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user