Skip to content

Commit

Permalink
Merge pull request #1551 from ousttrue/fix/awaitcaller
Browse files Browse the repository at this point in the history
UnitTest の修正
  • Loading branch information
ousttrue authored Feb 24, 2022
2 parents 7cb05f0 + e387eb4 commit 9693708
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
14 changes: 14 additions & 0 deletions Assets/UniGLTF/Runtime/Extensions/UnityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,28 @@ public BlendShape(string name, int vertexCount, bool hasPositions, bool hasNorma
{
Positions = new List<Vector3>(vertexCount);
}
else
{
Positions = new List<Vector3>();
}

if (hasNormals)
{
Normals = new List<Vector3>(vertexCount);
}
else
{
Normals = new List<Vector3>();
}

if (hasTangents)
{
Tangents = new List<Vector3>(vertexCount);
}
else
{
Tangents = new List<Vector3>();
}
}

public List<Vector3> Positions { get; private set; }
Expand Down
27 changes: 26 additions & 1 deletion Assets/VRM10/Runtime/IO/Vrm10.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public static async Task<Vrm10Instance> LoadPathAsync(
VrmMetaInformationCallback vrmMetaInformationCallback = null,
CancellationToken ct = default)
{
if (awaitCaller == null)
{
awaitCaller = Application.isPlaying
? (IAwaitCaller)new RuntimeOnlyAwaitCaller()
: (IAwaitCaller)new ImmediateCaller();
}

return await LoadAsync(
path,
System.IO.File.ReadAllBytes(path),
Expand Down Expand Up @@ -81,6 +88,13 @@ public static async Task<Vrm10Instance> LoadBytesAsync(
VrmMetaInformationCallback vrmMetaInformationCallback = null,
CancellationToken ct = default)
{
if (awaitCaller == null)
{
awaitCaller = Application.isPlaying
? (IAwaitCaller)new RuntimeOnlyAwaitCaller()
: (IAwaitCaller)new ImmediateCaller();
}

return await LoadAsync(
string.Empty,
bytes,
Expand All @@ -105,7 +119,6 @@ private static async Task<Vrm10Instance> LoadAsync(
CancellationToken ct)
{
ct.ThrowIfCancellationRequested();

if (awaitCaller == null)
{
throw new ArgumentNullException();
Expand Down Expand Up @@ -172,6 +185,10 @@ private static async Task<Vrm10Instance> TryLoadingAsVrm10Async(
CancellationToken ct)
{
ct.ThrowIfCancellationRequested();
if (awaitCaller == null)
{
throw new ArgumentNullException();
}

var vrm10Data = await awaitCaller.Run(() => Vrm10Data.Parse(gltfData));
ct.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -203,6 +220,10 @@ private static async Task<Vrm10Instance> TryMigratingFromVrm0XAsync(
CancellationToken ct)
{
ct.ThrowIfCancellationRequested();
if (awaitCaller == null)
{
throw new ArgumentNullException();
}

Vrm10Data migratedVrm10Data = default;
MigrationData migrationData = default;
Expand Down Expand Up @@ -243,6 +264,10 @@ private static async Task<Vrm10Instance> LoadVrm10DataAsync(
CancellationToken ct)
{
ct.ThrowIfCancellationRequested();
if (awaitCaller == null)
{
throw new ArgumentNullException();
}

if (vrm10Data == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async void LoadVRMClicked()

async Task<Vrm10Instance> LoadAsync(string path, VRMShaders.IAwaitCaller awaitCaller)
{
var instance = await Vrm10.LoadPathAsync(path);
var instance = await Vrm10.LoadPathAsync(path, awaitCaller: awaitCaller);

// VR用 FirstPerson 設定
await instance.Vrm.FirstPerson.SetupAsync(instance.gameObject, awaitCaller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async void LoadVRMClicked()

async Task<Vrm10Instance> LoadAsync(string path, VRMShaders.IAwaitCaller awaitCaller)
{
var instance = await Vrm10.LoadPathAsync(path);
var instance = await Vrm10.LoadPathAsync(path, awaitCaller: awaitCaller);

// VR用 FirstPerson 設定
await instance.Vrm.FirstPerson.SetupAsync(instance.gameObject, awaitCaller);
Expand Down

0 comments on commit 9693708

Please sign in to comment.