diff --git a/src/main/kotlin/io/github/deficuet/unitykt/data/Canvas.kt b/src/main/kotlin/io/github/deficuet/unitykt/data/Canvas.kt new file mode 100644 index 00000000..61773de5 --- /dev/null +++ b/src/main/kotlin/io/github/deficuet/unitykt/data/Canvas.kt @@ -0,0 +1,29 @@ +package io.github.deficuet.unitykt.data + +import io.github.deficuet.unitykt.dataImpl.CanvasImpl +import io.github.deficuet.unitykt.file.ObjectInfo +import io.github.deficuet.unitykt.file.SerializedFile +import io.github.deficuet.unitykt.util.ObjectReader + +/** + * Errors may occur for bundles with version before `2018.4.34f1` + */ +class Canvas private constructor( + private val container: ImplementationContainer +): Behaviour(container) { + internal constructor(assetFile: SerializedFile, info: ObjectInfo): + this(ImplementationContainer(assetFile, info) { CanvasImpl(ObjectReader(assetFile, info)) }) + + val mRenderMode: Int get() = container.impl.mRenderMode + val mCamera: PPtr get() = container.impl.mCamera + val mPlaneDistance: Float get() = container.impl.mPlaneDistance + val mPixelPerfect: Boolean get() = container.impl.mPixelPerfect + val mReceivesEvent: Boolean get() = container.impl.mReceivesEvent + val mOverrideSorting: Boolean get() = container.impl.mOverrideSorting + val mOverridePixelPerfect: Boolean get() = container.impl.mOverridePixelPerfect + val mSortingBucketNormalizedSize: Float get() = container.impl.mSortingBucketNormalizedSize + val mAdditionalShaderChannelsFlag: Int get() = container.impl.mAdditionalShaderChannelsFlag + val mSortingLayerID: Int get() = container.impl.mSortingLayerID + val mSortingOrder: Short get() = container.impl.mSortingOrder + val mTargetDisplay: Byte get() = container.impl.mTargetDisplay +} \ No newline at end of file diff --git a/src/main/kotlin/io/github/deficuet/unitykt/data/MonoBehaviour.kt b/src/main/kotlin/io/github/deficuet/unitykt/data/MonoBehaviour.kt index 7e95b0b5..48e29191 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/data/MonoBehaviour.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/data/MonoBehaviour.kt @@ -14,7 +14,4 @@ class MonoBehaviour private constructor( val mScript: PPtr get() = container.impl.mScript val mName: String get() = container.impl.mName - - val json: JSONObject? get() = container.impl.json - val jsonString: String get() = container.impl.jsonString } \ No newline at end of file diff --git a/src/main/kotlin/io/github/deficuet/unitykt/data/Object.kt b/src/main/kotlin/io/github/deficuet/unitykt/data/Object.kt index 88f02eb3..5b4fab4d 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/data/Object.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/data/Object.kt @@ -3,6 +3,7 @@ package io.github.deficuet.unitykt.data import io.github.deficuet.unitykt.dataImpl.ObjectImpl import io.github.deficuet.unitykt.file.* import io.github.deficuet.unitykt.util.ObjectReader +import org.json.JSONObject open class Object internal constructor(private val container: ImplementationContainer) { internal constructor(assetFile: SerializedFile, info: ObjectInfo): @@ -15,7 +16,8 @@ open class Object internal constructor(private val container: ImplementationCont val byteSize: UInt = container.info.byteSize val platform: BuildTarget = assetFile.targetPlatform val serializedType: SerializedType? = container.info.serializedType - val bytes: ByteArray get() = container.impl.bytes + + val bytes: ByteArray get() = container.impl.bytes /** * @see [SerializedType.Tree.readTypeString] @@ -26,4 +28,7 @@ open class Object internal constructor(private val container: ImplementationCont * @see [SerializedType.Tree.readType] */ fun toType() = container.impl.toType() + + val typeTreeJson: JSONObject? get() = container.impl.typeTreeJson + val typeTreeJsonString: String get() = container.impl.typeTreeJsonString } \ No newline at end of file diff --git a/src/main/kotlin/io/github/deficuet/unitykt/dataImpl/CanvasImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/dataImpl/CanvasImpl.kt new file mode 100644 index 00000000..0cb8e430 --- /dev/null +++ b/src/main/kotlin/io/github/deficuet/unitykt/dataImpl/CanvasImpl.kt @@ -0,0 +1,29 @@ +package io.github.deficuet.unitykt.dataImpl + +import io.github.deficuet.unitykt.data.* +import io.github.deficuet.unitykt.util.ObjectReader + +/** + * Errors may occur for bundles with version before `2018.4.34f1` + */ +class CanvasImpl internal constructor(reader: ObjectReader): BehaviourImpl(reader) { + val mRenderMode = reader.readInt() + val mCamera = PPtr(reader) //PPtr + val mPlaneDistance = reader.readFloat() + val mPixelPerfect = reader.readBool() + val mReceivesEvent = reader.readBool() + val mOverrideSorting = reader.readBool() + val mOverridePixelPerfect = reader.readBool() + val mSortingBucketNormalizedSize = reader.readFloat() + val mAdditionalShaderChannelsFlag = reader.readInt() + val mSortingLayerID: Int + val mSortingOrder: Short + val mTargetDisplay: Byte + + init { + reader.alignStream() + mSortingLayerID = reader.readInt() + mSortingOrder = reader.readShort() + mTargetDisplay = reader.readSByte() + } +} \ No newline at end of file diff --git a/src/main/kotlin/io/github/deficuet/unitykt/dataImpl/MonoBehaviourImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/dataImpl/MonoBehaviourImpl.kt index 728016d3..902a1d1b 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/dataImpl/MonoBehaviourImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/dataImpl/MonoBehaviourImpl.kt @@ -8,8 +8,4 @@ import io.github.deficuet.unitykt.util.toJSONObject class MonoBehaviourImpl internal constructor(reader: ObjectReader): BehaviourImpl(reader) { val mScript = PPtr(reader) val mName = reader.readAlignedString() - - val json by lazy { toType()?.toJSONObject() } - - val jsonString by lazy { json?.toString(4) ?: "null" } } \ No newline at end of file diff --git a/src/main/kotlin/io/github/deficuet/unitykt/dataImpl/ObjectImpl.kt b/src/main/kotlin/io/github/deficuet/unitykt/dataImpl/ObjectImpl.kt index 73090813..042bbf2d 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/dataImpl/ObjectImpl.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/dataImpl/ObjectImpl.kt @@ -2,6 +2,8 @@ package io.github.deficuet.unitykt.dataImpl import io.github.deficuet.unitykt.file.BuildTarget import io.github.deficuet.unitykt.util.ObjectReader +import io.github.deficuet.unitykt.util.toJSONObject +import org.json.JSONObject open class ObjectImpl internal constructor(private val reader: ObjectReader) { val assetFile = reader.assetFile @@ -20,4 +22,7 @@ open class ObjectImpl internal constructor(private val reader: ObjectReader) { fun dump() = serializedType?.typeTree?.readTypeString(reader) fun toType() = serializedType?.typeTree?.readType(reader) + + val typeTreeJson: JSONObject? get() = toType()?.toJSONObject() + val typeTreeJsonString: String get() = typeTreeJson?.toString(4) ?: "null" } \ No newline at end of file diff --git a/src/main/kotlin/io/github/deficuet/unitykt/file/SerializedFile.kt b/src/main/kotlin/io/github/deficuet/unitykt/file/SerializedFile.kt index b9bd7217..d23238e1 100644 --- a/src/main/kotlin/io/github/deficuet/unitykt/file/SerializedFile.kt +++ b/src/main/kotlin/io/github/deficuet/unitykt/file/SerializedFile.kt @@ -335,6 +335,7 @@ class SerializedFile( ClassIDType.AssetBundle -> AssetBundle(this, info) ClassIDType.AudioClip -> AudioClip(this, info) ClassIDType.Avatar -> Avatar(this, info) + ClassIDType.Canvas -> Canvas(this, info) ClassIDType.Font -> Font(this, info) ClassIDType.GameObject -> GameObject(this, info) ClassIDType.Material -> Material(this, info)