Skip to content

Commit

Permalink
create Canvas object
Browse files Browse the repository at this point in the history
  • Loading branch information
Deficuet authored and Deficuet committed Dec 25, 2022
1 parent a72adcc commit 9b1e4a9
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 8 deletions.
29 changes: 29 additions & 0 deletions src/main/kotlin/io/github/deficuet/unitykt/data/Canvas.kt
Original file line number Diff line number Diff line change
@@ -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<CanvasImpl>
): 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<Object> 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@ class MonoBehaviour private constructor(

val mScript: PPtr<MonoScript> 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
}
7 changes: 6 additions & 1 deletion src/main/kotlin/io/github/deficuet/unitykt/data/Object.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObjectImpl>) {
internal constructor(assetFile: SerializedFile, info: ObjectInfo):
Expand All @@ -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]
Expand All @@ -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
}
29 changes: 29 additions & 0 deletions src/main/kotlin/io/github/deficuet/unitykt/dataImpl/CanvasImpl.kt
Original file line number Diff line number Diff line change
@@ -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<Object>(reader) //PPtr<Camera>
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@ import io.github.deficuet.unitykt.util.toJSONObject
class MonoBehaviourImpl internal constructor(reader: ObjectReader): BehaviourImpl(reader) {
val mScript = PPtr<MonoScript>(reader)
val mName = reader.readAlignedString()

val json by lazy { toType()?.toJSONObject() }

val jsonString by lazy { json?.toString(4) ?: "null" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9b1e4a9

Please sign in to comment.