From a9f1f0a353ae38c869c995922d7ab64cde6d60b7 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 25 Jan 2022 18:38:12 +0900 Subject: [PATCH] =?UTF-8?q?CreateNativeArray=20=E3=82=92=E9=81=85=E5=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs index eeccc501e..fdddbf823 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs @@ -39,12 +39,32 @@ namespace UniGLTF /// public glTF GLTF { get; } + public NativeArray? _bin; + /// /// BIN chunk /// > This chunk MUST be the second chunk of the Binary glTF asset /// /// - public readonly NativeArray Bin; + public NativeArray Bin + { + get + { + if (!_bin.HasValue) + { + // init + if (Chunks != null) + { + if (Chunks.Count >= 2) + { + _bin = CreateNativeArray(Chunks[1].Bytes); + } + } + + } + return _bin.GetValueOrDefault(); + } + } /// /// Migration Flags used by ImporterContext @@ -71,14 +91,6 @@ namespace UniGLTF Chunks = chunks; _storage = storage; MigrationFlags = migrationFlags; - - if (Chunks != null) - { - if (Chunks.Count >= 2) - { - Bin = CreateNativeArray(Chunks[1].Bytes); - } - } } public static GltfData CreateFromExportForTest(ExportingGltfData data) @@ -402,6 +414,7 @@ namespace UniGLTF } m_disposables.Clear(); _UriCache.Clear(); + _bin = null; } } }