From faebd437713f8722607fd92ecf5e2339e11608cb Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 21 Feb 2022 16:47:44 +0900 Subject: [PATCH] remove `awaitCaller ?? new ImmediateCaller()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上流の awaitCaller を下流に使ってないことも修正 --- .../Runtime/MeshUtility/BoneMeshEraser.cs | 8 +------- .../Runtime/UniGLTF/IO/ImporterContext.cs | 18 ++++++++++++------ .../Editor/Format/VRMEditorImporterContext.cs | 4 ++-- Assets/VRM/Runtime/IO/VRMImporterContext.cs | 17 ++++++++++++----- Assets/VRM/Runtime/IO/VrmUtility.cs | 2 +- .../VRM10Object/VRM10ObjectFirstPerson.cs | 4 ++-- Assets/VRM10/Runtime/IO/Vrm10.cs | 4 +--- Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 7 +++++-- .../FirstPersonSample/VRMRuntimeLoader.cs | 2 +- 9 files changed, 37 insertions(+), 29 deletions(-) diff --git a/Assets/UniGLTF/Runtime/MeshUtility/BoneMeshEraser.cs b/Assets/UniGLTF/Runtime/MeshUtility/BoneMeshEraser.cs index c480d0d4a..fd34c2584 100644 --- a/Assets/UniGLTF/Runtime/MeshUtility/BoneMeshEraser.cs +++ b/Assets/UniGLTF/Runtime/MeshUtility/BoneMeshEraser.cs @@ -143,15 +143,9 @@ namespace UniGLTF.MeshUtility { if (awaitCaller == null) { - awaitCaller = new ImmediateCaller(); + throw new ArgumentNullException(); } - /* - Debug.LogFormat("{0} exclude: {1}", - src.name, - String.Join(", ", eraseBoneIndices.Select(x => x.ToString()).ToArray()) - ); - */ var mesh = new Mesh(); mesh.name = src.name + "(erased)"; diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index 7d3f514eb..fdbaff4c0 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -75,11 +75,11 @@ namespace UniGLTF }; #region Load. Build unity objects - public virtual async Task LoadAsync(IAwaitCaller awaitCaller = null, Func MeasureTime = null) + public virtual async Task LoadAsync(IAwaitCaller awaitCaller, Func MeasureTime = null) { if (awaitCaller == null) { - awaitCaller = new ImmediateCaller(); + throw new ArgumentNullException(); } if (MeasureTime == null) @@ -248,9 +248,12 @@ namespace UniGLTF await awaitCaller.NextFrame(); } - public async Task LoadTexturesAsync(IAwaitCaller awaitCaller = null) + public async Task LoadTexturesAsync(IAwaitCaller awaitCaller) { - awaitCaller = awaitCaller ?? new ImmediateCaller(); + if (awaitCaller == null) + { + throw new ArgumentNullException(); + } var textures = TextureDescriptorGenerator.Get().GetEnumerable(); foreach (var param in textures) @@ -259,9 +262,12 @@ namespace UniGLTF } } - public async Task LoadMaterialsAsync(IAwaitCaller awaitCaller = null) + public async Task LoadMaterialsAsync(IAwaitCaller awaitCaller) { - awaitCaller = awaitCaller ?? new ImmediateCaller(); + if (awaitCaller == null) + { + throw new ArgumentNullException(); + } if (Data.GLTF.materials == null || Data.GLTF.materials.Count == 0) { diff --git a/Assets/VRM/Editor/Format/VRMEditorImporterContext.cs b/Assets/VRM/Editor/Format/VRMEditorImporterContext.cs index ae0946d36..eac3d5d8d 100644 --- a/Assets/VRM/Editor/Format/VRMEditorImporterContext.cs +++ b/Assets/VRM/Editor/Format/VRMEditorImporterContext.cs @@ -75,7 +75,7 @@ namespace VRM // // convert images(metallic roughness, occlusion map) // - var task = m_context.LoadMaterialsAsync(); + var task = m_context.LoadMaterialsAsync(new ImmediateCaller()); if (!task.IsCompleted) { throw new Exception(); @@ -93,7 +93,7 @@ namespace VRM } // Convert thumbnail image - var task2 = m_context.ReadMetaAsync(); + var task2 = m_context.ReadMetaAsync(new ImmediateCaller()); if (!task2.IsCompleted || task2.IsCanceled || task2.IsFaulted) { throw new Exception(); diff --git a/Assets/VRM/Runtime/IO/VRMImporterContext.cs b/Assets/VRM/Runtime/IO/VRMImporterContext.cs index ced6f815d..7510d6095 100644 --- a/Assets/VRM/Runtime/IO/VRMImporterContext.cs +++ b/Assets/VRM/Runtime/IO/VRMImporterContext.cs @@ -39,7 +39,7 @@ namespace VRM using (MeasureTime("VRM LoadMeta")) { - await LoadMetaAsync(); + await LoadMetaAsync(awaitCaller); } await awaitCaller.NextFrame(); @@ -68,9 +68,13 @@ namespace VRM } } - async Task LoadMetaAsync() + async Task LoadMetaAsync(IAwaitCaller awaitCaller) { - var meta = await ReadMetaAsync(); + if (awaitCaller == null) + { + throw new ArgumentNullException(); + } + var meta = await ReadMetaAsync(awaitCaller); var _meta = Root.AddComponent(); _meta.Meta = meta; Meta = meta; @@ -276,9 +280,12 @@ namespace VRM public BlendShapeAvatar BlendShapeAvatar; public VRMMetaObject Meta; - public async Task ReadMetaAsync(IAwaitCaller awaitCaller = null, bool createThumbnail = false) + public async Task ReadMetaAsync(IAwaitCaller awaitCaller, bool createThumbnail = false) { - awaitCaller = awaitCaller ?? new ImmediateCaller(); + if (awaitCaller == null) + { + throw new ArgumentNullException(); + } var meta = ScriptableObject.CreateInstance(); meta.name = "Meta"; diff --git a/Assets/VRM/Runtime/IO/VrmUtility.cs b/Assets/VRM/Runtime/IO/VrmUtility.cs index 431ca1d1f..a29f96762 100644 --- a/Assets/VRM/Runtime/IO/VrmUtility.cs +++ b/Assets/VRM/Runtime/IO/VrmUtility.cs @@ -36,7 +36,7 @@ namespace VRM { if (metaCallback != null) { - var meta = await loader.ReadMetaAsync(new ImmediateCaller(), true); + var meta = await loader.ReadMetaAsync(awaitCaller, true); metaCallback(meta); } return await loader.LoadAsync(awaitCaller); diff --git a/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectFirstPerson.cs b/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectFirstPerson.cs index ad7bcc8ab..cae4eb1e0 100644 --- a/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectFirstPerson.cs +++ b/Assets/VRM10/Runtime/Components/VRM10Object/VRM10ObjectFirstPerson.cs @@ -136,11 +136,11 @@ namespace UniVRM10 /// layer VRMThirdPersonOnly ir 10 /// Headless mesh creation task scheduler. By default, creation is immediate /// - public async Task SetupAsync(GameObject go, bool isSelf = true, int? firstPersonOnlyLayer = default, int? thirdPersonOnlyLayer = default, IAwaitCaller awaitCaller = default) + public async Task SetupAsync(GameObject go, IAwaitCaller awaitCaller, bool isSelf = true, int? firstPersonOnlyLayer = default, int? thirdPersonOnlyLayer = default) { if (awaitCaller == null) { - awaitCaller = new ImmediateCaller(); + throw new ArgumentNullException(); } var layer = ( diff --git a/Assets/VRM10/Runtime/IO/Vrm10.cs b/Assets/VRM10/Runtime/IO/Vrm10.cs index 1d4f214a8..daf3b51c6 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10.cs @@ -108,9 +108,7 @@ namespace UniVRM10 if (awaitCaller == null) { - awaitCaller = Application.isPlaying - ? (IAwaitCaller) new RuntimeOnlyAwaitCaller() - : (IAwaitCaller) new ImmediateCaller(); + throw new ArgumentNullException(); } using (var gltfData = new GlbLowLevelParser(name, bytes).Parse()) diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index e7d7aa314..df8cce83a 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -79,9 +79,12 @@ namespace UniVRM10 } } - public override async Task LoadAsync(IAwaitCaller awaitCaller = null, Func MeasureTime = null) + public override async Task LoadAsync(IAwaitCaller awaitCaller, Func MeasureTime = null) { - awaitCaller = awaitCaller ?? new ImmediateCaller(); + if (awaitCaller == null) + { + throw new ArgumentNullException(); + } // NOTE: VRM データに対して、Load 前に必要なヘビーな変換処理を行う. // ヘビーなため、別スレッドで Run する. diff --git a/Assets/VRM_Samples/FirstPersonSample/VRMRuntimeLoader.cs b/Assets/VRM_Samples/FirstPersonSample/VRMRuntimeLoader.cs index ed4c36a07..3e19933bc 100644 --- a/Assets/VRM_Samples/FirstPersonSample/VRMRuntimeLoader.cs +++ b/Assets/VRM_Samples/FirstPersonSample/VRMRuntimeLoader.cs @@ -114,7 +114,7 @@ namespace VRM.FirstPersonSample var loaded = default(RuntimeGltfInstance); if (m_loadAsync) { - loaded = await context.LoadAsync(); + loaded = await context.LoadAsync(new VRMShaders.RuntimeOnlyAwaitCaller()); } else {