From 5af65aa48fdaea535f616d97b77170f323bfc3f4 Mon Sep 17 00:00:00 2001 From: Deficuet Date: Sun, 7 Jan 2024 21:23:21 -0700 Subject: [PATCH] update PPtr --- .../unitykt/internal/impl/AssetBundleImpl.kt | 2 ++ .../unitykt/internal/impl/PPtrImpl.kt | 24 ++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AssetBundleImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AssetBundleImpl.kt index 541157b8..9d38ba59 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AssetBundleImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AssetBundleImpl.kt @@ -50,6 +50,8 @@ internal class AssetBundleImpl( return fmPathFlags } + internal var dependenciesLoaded = false + override fun read() { super.read() fmPreloadTable = reader.readArrayOf { PPtrImpl(this) } diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/PPtrImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/PPtrImpl.kt index da318f35..cdc84c60 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/PPtrImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/PPtrImpl.kt @@ -1,7 +1,6 @@ package io.github.deficuet.unitykt.internal.impl import io.github.deficuet.unitykt.cast -import io.github.deficuet.unitykt.classes.AssetBundle import io.github.deficuet.unitykt.classes.UnityObject import io.github.deficuet.unitykt.internal.file.FormatVersion import io.github.deficuet.unitykt.internal.file.SerializedFile @@ -49,17 +48,20 @@ internal class PPtrImpl: PPtr { if (result != null) return result if (manager.assetRootFolder == null) return null val bundle = assetFile.objectMap[1L] ?: return null - if (bundle !is AssetBundle) return null - for (dependencyName in bundle.mDependencies) { - try { - manager.loadFile( - manager.assetRootFolder.resolve(dependencyName), - manager.defaultReaderConfig - ) - } catch (e: Exception) { - println("An error occurred during loading dependency file ${dependencyName}: ${e.message}") - continue + if (bundle !is AssetBundleImpl) return null + if (!bundle.dependenciesLoaded) { + for (dependencyName in bundle.mDependencies) { + try { + manager.loadFile( + manager.assetRootFolder.resolve(dependencyName), + manager.defaultReaderConfig + ) + } catch (e: Exception) { + println("An error occurred during loading dependency file ${dependencyName}: ${e.message}") + continue + } } + bundle.dependenciesLoaded = true } return manager.assetFiles[assetFile.externals[fileIndex].name.lowercase()] }