- Home /
Best practice custom class with GameObject
Hi all
Conceptual question
I’m trying to get to grips with a custom class(es) to create different types of placeable tiles which I can then save the transform information of and the type of tile it is to then be able to reconstruct a level
So far I have a class with properties as
Serializae fields
Tiletype string(UNDER REVIEW)
location x float
Location y float
rotation y float
and non serializeable
GameObject
There’s also function that updates the game objects transform into the transform properties properties and saves to a static list in my SaveLoad class
My question is, how would you go about dealing with the tile type. Shall I extend this class? Ideally I’d like to be able to construct a tile by passing in the type. Am I on the right lines?
Also, is there a better way to deal with storing the transform information of the GameObject whilst still being able to use serialisation?
I’ve set up the binary format method for the serialisation by the way.
Would really appreciate some thoughts on this
Thanks
Use an enum for the tile type ins$$anonymous$$d of string and then create a Tile class to hold any data associated with given tile type, the association can be direct as the TileInfo class has a TileType field and create a List of TileInfo or through a dictionary($$anonymous$$ey:TileType, Value:TileInfo), you ll have to serialize this data so you could use a ScriptableObject (which will use Unity's serialization system) or some external method as is c# serializer or some database solution. Cheers.
Your answer
Follow this Question
Related Questions
How to save/load references to components and prefabs 1 Answer
Serialization - Variables won't change on original construction 1 Answer
Accessing a GameObject parent Object 2 Answers
Instantiating gameObject with custom Class properties 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers