diff --git a/README.md b/README.md index 2a5a2078..adeec9a8 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ All the C++ code used to decode texture compression come from [AssetStudio/Textu - UnityAssetManager - The entry point of loading object. It contains all objects read from all files that are loaded through it, except `AssetBundle` objects. - Use `UnityAssetManager.new(...)` with two parameters `assetRootFolder` and `readerConfig` to get an instance. - - `assetRootFolder` is optional and it can be a `java.io.File`, `java.nio.file.Path` or just a `String`. When present, it will be used by `PPtr` to look for object according to the `mDependencies` property in the `AssetBundle` object of the file. + - `assetRootFolder` is optional and it can be a `java.io.File`, `java.nio.file.Path` or just a `String`. When present, it will be used by `PPtr` to look for object according to the `mDependencies` in the `AssetBundle` object of the file. - `readerConfig` is the loading configuration and is also optional. - Loading Configurations - When loading file(s)/folder/ByteArray, an optional `ReaderConfig` can also be passed to override the configuration given to the manager, or the configuration given to the manager will be used by default. @@ -43,7 +43,7 @@ All the C++ code used to decode texture compression come from [AssetStudio/Textu - e.g. Its `assetFile` which is a `SerializedFile`, `mPathID`, `unityVersion`, etc. Those are the fields enclosed in the metadata region. See [UnityObject class](https://github.com/Deficuet/UnityKt/blob/main/src/main/kotlin/io/github/deficuet/unitykt/classes/UnityObject.kt). - Shortcuts - See [utils.kt](https://github.com/Deficuet/UnityKt/blob/main/src/main/kotlin/io/github/deficuet/unitykt/utils.kt) and [PPtr.kt](https://github.com/Deficuet/UnityKt/blob/main/src/main/kotlin/io/github/deficuet/unitykt/classes/PPtr.kt) - - Should always use `PPtr.safeGetObj()` or `PPtr.getObj()` to get the object, or use `PPtr<*>.safeGetObjAs()` to get and cast. + - Should always use `PPtr.safeGetObj()` or `PPtr.getObj()` to get the object, or use `PPtr<*>.safeGetObjAs()` to get and cast. ## Export So far the objects that can export data includes: @@ -159,7 +159,7 @@ fun main() { // Then it will look for the file under the directory "C:/path/to/asset/system/root/folder" which was // given to the manager. The file name comes from the mDependecies property of the AssetBundle object // in the same file as this Material object being in. The target file will be loaded using the same - // reader config passed to the manager. Finally, PPtr will try to find the object in the new loaded file. + // reader config passed to the manager. Finally, PPtr will try to find the object in the new loaded files. ?.safeCast()?.getImage()?.let { image -> ImageIO.write(image, "png", File("C:/whatever/you/want/name.png")) } diff --git a/build.gradle b/build.gradle index d15e66b7..e6444bec 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group 'io.github.deficuet' -version '0.1.0_alpha.7' +version '0.1.0_alpha.8' repositories { mavenCentral() diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimationFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimationFields.java index 778600f7..3433656e 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimationFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimationFields.java @@ -1,9 +1,9 @@ package io.github.deficuet.unitykt.internal.impl; import io.github.deficuet.unitykt.classes.AnimationClip; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import org.jetbrains.annotations.NotNull; abstract class AnimationFields extends BehaviourImpl { diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimatorControllerFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimatorControllerFields.java index e788be2b..6be1f553 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimatorControllerFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimatorControllerFields.java @@ -2,9 +2,9 @@ import io.github.deficuet.unitykt.classes.AnimationClip; import io.github.deficuet.unitykt.classes.ControllerConstant; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import kotlin.UInt; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimatorFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimatorFields.java index 272755f0..8137e7f0 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimatorFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimatorFields.java @@ -1,10 +1,10 @@ package io.github.deficuet.unitykt.internal.impl; import io.github.deficuet.unitykt.classes.Avatar; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.classes.RuntimeAnimatorController; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import org.jetbrains.annotations.NotNull; abstract class AnimatorFields extends BehaviourImpl { diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimatorOverrideControllerFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimatorOverrideControllerFields.java index ff478215..48b7825c 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimatorOverrideControllerFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/AnimatorOverrideControllerFields.java @@ -1,10 +1,10 @@ package io.github.deficuet.unitykt.internal.impl; import io.github.deficuet.unitykt.classes.AnimationClipOverride; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.classes.RuntimeAnimatorController; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import org.jetbrains.annotations.NotNull; abstract class AnimatorOverrideControllerFields extends RuntimeAnimatorControllerImpl { diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/AssetBundleFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/AssetBundleFields.java index 1901816f..f3e3a1a0 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/AssetBundleFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/AssetBundleFields.java @@ -1,10 +1,10 @@ package io.github.deficuet.unitykt.internal.impl; import io.github.deficuet.unitykt.classes.AssetInfo; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.classes.UnityObject; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import kotlin.UInt; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/CanvasFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/CanvasFields.java index f850694c..3cac5337 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/CanvasFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/CanvasFields.java @@ -1,9 +1,9 @@ package io.github.deficuet.unitykt.internal.impl; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.classes.UnityObject; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import org.jetbrains.annotations.NotNull; abstract class CanvasFields extends BehaviourImpl { diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/ComponentFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/ComponentFields.java index 9f9f77d1..1296fc2a 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/ComponentFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/ComponentFields.java @@ -1,9 +1,9 @@ package io.github.deficuet.unitykt.internal.impl; import io.github.deficuet.unitykt.classes.GameObject; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import org.jetbrains.annotations.NotNull; abstract class ComponentFields extends EditorExtensionImpl { diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/MaterialFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/MaterialFields.java index 8f9b5dab..a06ad8ca 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/MaterialFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/MaterialFields.java @@ -1,10 +1,10 @@ package io.github.deficuet.unitykt.internal.impl; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.classes.Shader; import io.github.deficuet.unitykt.classes.UnityPropertySheet; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import org.jetbrains.annotations.NotNull; abstract class MaterialFields extends NamedObjectImpl { diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/MeshFilterFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/MeshFilterFields.java index 90104c3e..6dc2fe6e 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/MeshFilterFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/MeshFilterFields.java @@ -1,9 +1,9 @@ package io.github.deficuet.unitykt.internal.impl; import io.github.deficuet.unitykt.classes.Mesh; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import org.jetbrains.annotations.NotNull; abstract class MeshFilterFields extends ComponentImpl{ diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/MonoBehaviourFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/MonoBehaviourFields.java index 711b9a4a..67cfbe0c 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/MonoBehaviourFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/MonoBehaviourFields.java @@ -1,9 +1,9 @@ package io.github.deficuet.unitykt.internal.impl; import io.github.deficuet.unitykt.classes.MonoScript; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import org.jetbrains.annotations.NotNull; abstract class MonoBehaviourFields extends BehaviourImpl { diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/MovieTextureFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/MovieTextureFields.java index 0e058f62..df2657ab 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/MovieTextureFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/MovieTextureFields.java @@ -1,9 +1,9 @@ package io.github.deficuet.unitykt.internal.impl; import io.github.deficuet.unitykt.classes.AudioClip; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import org.jetbrains.annotations.NotNull; abstract class MovieTextureFields extends TextureImpl { diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/RendererFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/RendererFields.java index aa27adf1..1027c0fe 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/RendererFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/RendererFields.java @@ -1,10 +1,10 @@ package io.github.deficuet.unitykt.internal.impl; import io.github.deficuet.unitykt.classes.Material; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.classes.StaticBatchInfo; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import kotlin.UInt; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/ResourceManagerFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/ResourceManagerFields.java index a03d4f4e..815da918 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/ResourceManagerFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/ResourceManagerFields.java @@ -1,9 +1,9 @@ package io.github.deficuet.unitykt.internal.impl; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.classes.UnityObject; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import org.jetbrains.annotations.NotNull; import java.util.List; diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/SkinnedMeshRendererFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/SkinnedMeshRendererFields.java index e8669620..22723397 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/SkinnedMeshRendererFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/SkinnedMeshRendererFields.java @@ -1,10 +1,10 @@ package io.github.deficuet.unitykt.internal.impl; import io.github.deficuet.unitykt.classes.Mesh; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.classes.Transform; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import org.jetbrains.annotations.NotNull; abstract class SkinnedMeshRendererFields extends RendererImpl { diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/SpriteFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/SpriteFields.java index 6467cb50..cea20802 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/SpriteFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/SpriteFields.java @@ -1,6 +1,5 @@ package io.github.deficuet.unitykt.internal.impl; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.classes.SpriteAtlas; import io.github.deficuet.unitykt.classes.SpriteRenderData; import io.github.deficuet.unitykt.internal.file.ObjectInfo; @@ -8,6 +7,7 @@ import io.github.deficuet.unitykt.math.Rectangle; import io.github.deficuet.unitykt.math.Vector2; import io.github.deficuet.unitykt.math.Vector4; +import io.github.deficuet.unitykt.pptr.PPtr; import kotlin.Pair; import kotlin.UInt; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/TransformFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/TransformFields.java index 4f86efb6..abc3da0c 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/TransformFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/TransformFields.java @@ -1,11 +1,11 @@ package io.github.deficuet.unitykt.internal.impl; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.classes.Transform; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; import io.github.deficuet.unitykt.math.Quaternion; import io.github.deficuet.unitykt.math.Vector3; +import io.github.deficuet.unitykt.pptr.PPtr; import org.jetbrains.annotations.NotNull; abstract class TransformFields extends ComponentImpl { diff --git a/src/main/java/io/github/deficuet/unitykt/internal/impl/VideoClipFields.java b/src/main/java/io/github/deficuet/unitykt/internal/impl/VideoClipFields.java index 9bbeb28e..4f3b215a 100644 --- a/src/main/java/io/github/deficuet/unitykt/internal/impl/VideoClipFields.java +++ b/src/main/java/io/github/deficuet/unitykt/internal/impl/VideoClipFields.java @@ -1,10 +1,10 @@ package io.github.deficuet.unitykt.internal.impl; -import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.classes.Shader; import io.github.deficuet.unitykt.classes.StreamedResource; import io.github.deficuet.unitykt.internal.file.ObjectInfo; import io.github.deficuet.unitykt.internal.file.SerializedFile; +import io.github.deficuet.unitykt.pptr.PPtr; import io.github.deficuet.unitykt.util.ResourceReader; import kotlin.UInt; import kotlin.ULong; diff --git a/src/main/kotlin/io/github/deficuet/unitykt/UnityAssetManager.kt b/src/main/kotlin/io/github/deficuet/unitykt/UnityAssetManager.kt index 8f627f8f..1c3d456f 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/UnityAssetManager.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/UnityAssetManager.kt @@ -1,15 +1,16 @@ package io.github.deficuet.unitykt import io.github.deficuet.unitykt.classes.AssetBundle -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.classes.UnityObject import io.github.deficuet.unitykt.internal.UnityAssetManagerImpl +import io.github.deficuet.unitykt.pptr.PPtr import java.io.Closeable import java.io.File import java.nio.file.Path +import kotlin.io.path.isDirectory interface UnityAssetManager: Closeable { - val assetRootFolder: File? + val assetRootFolder: Path? val defaultReaderConfig: ReaderConfig /** @@ -116,15 +117,15 @@ interface UnityAssetManager: Closeable { /** * @see new */ - fun new(assetRootFolder: Path, readerConfig: ReaderConfig = ReaderConfig.default): UnityAssetManager { - return new(assetRootFolder.toFile(), readerConfig) + fun new(assetRootFolder: File, readerConfig: ReaderConfig = ReaderConfig.default): UnityAssetManager { + return new(assetRootFolder.toPath(), readerConfig) } /** * @see new */ - fun new(assetRootFolder: File, readerConfig: ReaderConfig = ReaderConfig.default): UnityAssetManager { - if (!assetRootFolder.isDirectory) { - throw IllegalArgumentException("${assetRootFolder.path} is not a valid folder") + fun new(assetRootFolder: Path, readerConfig: ReaderConfig = ReaderConfig.default): UnityAssetManager { + if (!assetRootFolder.isDirectory()) { + throw IllegalArgumentException("$assetRootFolder is not a valid folder") } return UnityAssetManagerImpl(assetRootFolder, readerConfig) } diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/UnityAssetManagerImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/UnityAssetManagerImpl.kt index 6215f4cb..091b8594 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/UnityAssetManagerImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/UnityAssetManagerImpl.kt @@ -15,7 +15,7 @@ import kotlin.io.path.isDirectory import kotlin.io.path.isRegularFile internal class UnityAssetManagerImpl( - override val assetRootFolder: File?, + override val assetRootFolder: Path?, override val defaultReaderConfig: ReaderConfig ): UnityAssetManager { init { UnityAssetManager.managers.add(this) } @@ -64,8 +64,7 @@ internal class UnityAssetManagerImpl( override fun loadFolder(folder: Path, config: ReaderConfig): Array { if (!folder.isDirectory()) throw IllegalArgumentException("parameter \"folder\" must be a directory") val files = Files.newDirectoryStream(folder).use { stream -> - stream.filter { it.isRegularFile() } - .toTypedArray() + stream.filter { it.isRegularFile() }.toTypedArray() } return loadFiles(*files, config = config) } diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AnimationImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AnimationImpl.kt index 895be1ac..e3305387 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AnimationImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AnimationImpl.kt @@ -2,9 +2,9 @@ package io.github.deficuet.unitykt.internal.impl import io.github.deficuet.unitykt.classes.Animation import io.github.deficuet.unitykt.classes.AnimationClip -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile +import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.util.readArrayOf internal class AnimationImpl( diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AnimatorImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AnimatorImpl.kt index da7ff61d..f6071c46 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AnimatorImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AnimatorImpl.kt @@ -2,10 +2,10 @@ package io.github.deficuet.unitykt.internal.impl import io.github.deficuet.unitykt.classes.Animator import io.github.deficuet.unitykt.classes.Avatar -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.classes.RuntimeAnimatorController import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile +import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.util.compareTo internal class AnimatorImpl( diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AnimatorOverrideControllerImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AnimatorOverrideControllerImpl.kt index e676eebb..61ca82d6 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AnimatorOverrideControllerImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/AnimatorOverrideControllerImpl.kt @@ -1,6 +1,9 @@ package io.github.deficuet.unitykt.internal.impl -import io.github.deficuet.unitykt.classes.* +import io.github.deficuet.unitykt.classes.AnimationClip +import io.github.deficuet.unitykt.classes.AnimationClipOverride +import io.github.deficuet.unitykt.classes.AnimatorOverrideController +import io.github.deficuet.unitykt.classes.RuntimeAnimatorController import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile import io.github.deficuet.unitykt.pptr.PPtr 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 49632406..541157b8 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 @@ -2,10 +2,10 @@ package io.github.deficuet.unitykt.internal.impl import io.github.deficuet.unitykt.classes.AssetBundle import io.github.deficuet.unitykt.classes.AssetInfo -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.classes.UnityObject import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile +import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.util.ObjectReader import io.github.deficuet.unitykt.util.compareTo import io.github.deficuet.unitykt.util.readArrayOf diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/CanvasImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/CanvasImpl.kt index 762bb285..fecc2a35 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/CanvasImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/CanvasImpl.kt @@ -1,10 +1,10 @@ package io.github.deficuet.unitykt.internal.impl import io.github.deficuet.unitykt.classes.Canvas -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.classes.UnityObject import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile +import io.github.deficuet.unitykt.pptr.PPtr internal class CanvasImpl( assetFile: SerializedFile, info: ObjectInfo diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/ComponentImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/ComponentImpl.kt index 8b284c49..88c490f2 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/ComponentImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/ComponentImpl.kt @@ -2,9 +2,9 @@ package io.github.deficuet.unitykt.internal.impl import io.github.deficuet.unitykt.classes.Component import io.github.deficuet.unitykt.classes.GameObject -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile +import io.github.deficuet.unitykt.pptr.PPtr internal abstract class ComponentImpl( assetFile: SerializedFile, info: ObjectInfo diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/MeshFilterImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/MeshFilterImpl.kt index 904a2998..90be0307 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/MeshFilterImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/MeshFilterImpl.kt @@ -2,9 +2,9 @@ package io.github.deficuet.unitykt.internal.impl import io.github.deficuet.unitykt.classes.Mesh import io.github.deficuet.unitykt.classes.MeshFilter -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile +import io.github.deficuet.unitykt.pptr.PPtr internal class MeshFilterImpl( assetFile: SerializedFile, info: ObjectInfo diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/MonoBehaviourImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/MonoBehaviourImpl.kt index d3c14049..4284a234 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/MonoBehaviourImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/MonoBehaviourImpl.kt @@ -2,9 +2,9 @@ package io.github.deficuet.unitykt.internal.impl import io.github.deficuet.unitykt.classes.MonoBehaviour import io.github.deficuet.unitykt.classes.MonoScript -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile +import io.github.deficuet.unitykt.pptr.PPtr internal class MonoBehaviourImpl( assetFile: SerializedFile, info: ObjectInfo diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/MovieTextureImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/MovieTextureImpl.kt index 2943e779..3ace78ac 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/MovieTextureImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/MovieTextureImpl.kt @@ -2,9 +2,9 @@ package io.github.deficuet.unitykt.internal.impl import io.github.deficuet.unitykt.classes.AudioClip import io.github.deficuet.unitykt.classes.MovieTexture -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile +import io.github.deficuet.unitykt.pptr.PPtr internal class MovieTextureImpl( assetFile: SerializedFile, info: ObjectInfo 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 2c5ad175..da318f35 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 @@ -2,10 +2,10 @@ 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.pptr.PPtr import io.github.deficuet.unitykt.classes.UnityObject import io.github.deficuet.unitykt.internal.file.FormatVersion import io.github.deficuet.unitykt.internal.file.SerializedFile +import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.util.ObjectReader @PublishedApi @@ -50,16 +50,16 @@ internal class PPtrImpl: PPtr { if (manager.assetRootFolder == null) return null val bundle = assetFile.objectMap[1L] ?: return null if (bundle !is AssetBundle) return null - if (fileIndex >= bundle.mDependencies.size) return null - val dependencyName = bundle.mDependencies[fileIndex] - try { - manager.loadFile( - manager.assetRootFolder.resolve(dependencyName), - assetFile.root.manager.defaultReaderConfig - ) - } catch (e: Exception) { - println("An error occurred during loading dependency file ${dependencyName}: ${e.message}") - 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 + } } return manager.assetFiles[assetFile.externals[fileIndex].name.lowercase()] } diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/ResourceManagerImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/ResourceManagerImpl.kt index 5e0d88fd..966b5054 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/ResourceManagerImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/ResourceManagerImpl.kt @@ -1,10 +1,10 @@ package io.github.deficuet.unitykt.internal.impl -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.classes.ResourceManager import io.github.deficuet.unitykt.classes.UnityObject import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile +import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.util.readArrayOf internal class ResourceManagerImpl( diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SkinnedMeshRendererImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SkinnedMeshRendererImpl.kt index 04a57934..76723c63 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SkinnedMeshRendererImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SkinnedMeshRendererImpl.kt @@ -1,6 +1,9 @@ package io.github.deficuet.unitykt.internal.impl -import io.github.deficuet.unitykt.classes.* +import io.github.deficuet.unitykt.classes.Animation +import io.github.deficuet.unitykt.classes.Mesh +import io.github.deficuet.unitykt.classes.SkinnedMeshRenderer +import io.github.deficuet.unitykt.classes.Transform import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile import io.github.deficuet.unitykt.pptr.PPtr diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SpriteAtlasImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SpriteAtlasImpl.kt index ef838eac..faade270 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SpriteAtlasImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SpriteAtlasImpl.kt @@ -1,7 +1,10 @@ package io.github.deficuet.unitykt.internal.impl import io.github.deficuet.unitykt.cast -import io.github.deficuet.unitykt.classes.* +import io.github.deficuet.unitykt.classes.Sprite +import io.github.deficuet.unitykt.classes.SpriteAtlas +import io.github.deficuet.unitykt.classes.SpriteAtlasData +import io.github.deficuet.unitykt.classes.Texture2D import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile import io.github.deficuet.unitykt.math.Vector2 diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SpriteImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SpriteImpl.kt index 8a9067b2..89f6addf 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SpriteImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/SpriteImpl.kt @@ -1,6 +1,9 @@ package io.github.deficuet.unitykt.internal.impl -import io.github.deficuet.jimage.* +import io.github.deficuet.jimage.flipX +import io.github.deficuet.jimage.flipY +import io.github.deficuet.jimage.quadrantRotate +import io.github.deficuet.jimage.resize import io.github.deficuet.unitykt.classes.* import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/TransformImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/TransformImpl.kt index b7dde5a3..5c55db37 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/TransformImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/TransformImpl.kt @@ -1,11 +1,11 @@ package io.github.deficuet.unitykt.internal.impl -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.classes.Transform import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile import io.github.deficuet.unitykt.math.Quaternion import io.github.deficuet.unitykt.math.Vector3 +import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.util.readArrayOf internal open class TransformImpl( diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/UnityObjectImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/UnityObjectImpl.kt index 31309d1f..370ece05 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/UnityObjectImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/UnityObjectImpl.kt @@ -1,10 +1,10 @@ package io.github.deficuet.unitykt.internal.impl -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.classes.UnityObject import io.github.deficuet.unitykt.enums.BuildTarget import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile +import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.util.ObjectReader import org.json.JSONObject diff --git a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/VideoClipImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/VideoClipImpl.kt index 16a5b41d..b423b425 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/VideoClipImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/internal/impl/VideoClipImpl.kt @@ -1,11 +1,11 @@ package io.github.deficuet.unitykt.internal.impl -import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.classes.Shader import io.github.deficuet.unitykt.classes.StreamedResource import io.github.deficuet.unitykt.classes.VideoClip import io.github.deficuet.unitykt.internal.file.ObjectInfo import io.github.deficuet.unitykt.internal.file.SerializedFile +import io.github.deficuet.unitykt.pptr.PPtr import io.github.deficuet.unitykt.util.ObjectReader import io.github.deficuet.unitykt.util.ResourceReader import io.github.deficuet.unitykt.util.compareTo diff --git a/src/main/kotlin/io/github/deficuet/unitykt/pptr/PPtr.kt b/src/main/kotlin/io/github/deficuet/unitykt/pptr/PPtr.kt index 0f393f12..480c14d7 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/pptr/PPtr.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/pptr/PPtr.kt @@ -24,24 +24,26 @@ inline fun PPtr.getObj(): T { } inline fun PPtr<*>.safeGetAs(): T? { - return (this as PPtrImpl).safeGetObjInternal() as? T + return (this as PPtrImpl).safeGetObjInternal().safeCast() } inline fun PPtr<*>.getAs(): T { - return (this as PPtrImpl).getObjInternal() as T + return (this as PPtrImpl).getObjInternal().cast() } -inline fun Iterable>.firstObjectOf() = - mapNotNull { it.safeGetObj() }.firstObjectOf() +inline fun Iterable>.firstObjectOf(): T { + return mapNotNull { it.safeGetObj() }.firstObjectOf() +} -inline fun Array>.firstObjectOf() = - mapNotNull { it.safeGetObj() }.firstObjectOf() +inline fun Array>.firstObjectOf(): T { + return mapNotNull { it.safeGetObj() }.firstObjectOf() +} -inline fun Iterable>.firstOfOrNull(): O? { +inline fun Iterable>.firstOfOrNull(): T? { return mapNotNull { it.safeGetObj() }.firstOfOrNull() } -inline fun Array>.firstOfOrNull(): O? { +inline fun Array>.firstOfOrNull(): T? { return mapNotNull { it.safeGetObj() }.firstOfOrNull() }