From f966abb9e4d8beb2bd661822cf4d3c00a12fa041 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 26 Jan 2022 12:49:53 +0900 Subject: [PATCH] =?UTF-8?q?NativeArray=3F=20=E3=82=84=E3=82=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * コンストラクターで初期化 * Dispose上の方 --- Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs | 56 ++++++++----------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs index fdddbf823..287df0e95 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs @@ -39,32 +39,12 @@ namespace UniGLTF /// public glTF GLTF { get; } - public NativeArray? _bin; - /// /// BIN chunk /// > This chunk MUST be the second chunk of the Binary glTF asset /// /// - public NativeArray Bin - { - get - { - if (!_bin.HasValue) - { - // init - if (Chunks != null) - { - if (Chunks.Count >= 2) - { - _bin = CreateNativeArray(Chunks[1].Bytes); - } - } - - } - return _bin.GetValueOrDefault(); - } - } + public NativeArray Bin { get; } /// /// Migration Flags used by ImporterContext @@ -83,6 +63,8 @@ namespace UniGLTF /// Dictionary> _UriCache = new Dictionary>(); + List m_disposables = new List(); + public GltfData(string targetPath, string json, glTF gltf, IReadOnlyList chunks, IStorage storage, MigrationFlags migrationFlags) { TargetPath = targetPath; @@ -91,6 +73,25 @@ namespace UniGLTF Chunks = chunks; _storage = storage; MigrationFlags = migrationFlags; + + // init + if (Chunks != null) + { + if (Chunks.Count >= 2) + { + Bin = CreateNativeArray(Chunks[1].Bytes); + } + } + } + + public void Dispose() + { + foreach (var disposable in m_disposables) + { + disposable.Dispose(); + } + m_disposables.Clear(); + _UriCache.Clear(); } public static GltfData CreateFromExportForTest(ExportingGltfData data) @@ -403,18 +404,5 @@ namespace UniGLTF array.CopyFrom(data); return array; } - - List m_disposables = new List(); - - public void Dispose() - { - foreach (var disposable in m_disposables) - { - disposable.Dispose(); - } - m_disposables.Clear(); - _UriCache.Clear(); - _bin = null; - } } }