Hi all,
I want to create a plugin but I have some problem with serialization.
I read a lot of documentation, but still I could not understand it well.
I have this problem:
I have in my script (extend MonoBehavior) an Array of TileDraw objects:
public TileDraw[] tileToDraw;
Tile Draw is a list of Tile that I have to paint on screen everytime a launche my game.
This is the class:
This is the TileDraw class:
[System.Serializable]
public class TileDraw : ScriptableObject
{
public TileSet tile;
public int positionInTexture;
public void OnEnable() {
hideFlags = HideFlags.HideAndDontSave;
}
public static TileDraw Instance(string n, Texture2D s, int p){
TileDraw tileDraw = ScriptableObject.CreateInstance<TileDraw>();
tileDraw.Init(n, s, p);
return tileDraw;
}
public void Init(string n, Texture2D s, int p){
if (tile == null)
{
tile = TileSet.Instance(n, s);
}
this.positionInTexture = p;
}
}
In TileDraw I have a TileSet class for store(for now) texture of the tile that I have to draw in this position.
This it the TileSet class:
[System.Serializable]
public class TileSet : ScriptableObject
{
public string tileName;
public Texture2D texture;
public void OnEnable() {
hideFlags = HideFlags.HideAndDontSave;
}
public static TileSet Instance(string n, Texture2D s){
TileSet tileDraw = ScriptableObject.CreateInstance<TileSet>();
tileDraw.Init(n, s);
return tileDraw;
}
public void Init(string n, Texture2D s){
this.tileName = n;
this.texture = s;
}
}
When I execute the script in EditorMode it works fine, I’m able to create Map and draw Tile directly in SceneView, but when i play the game and stop it, my data is lost… TileDraw in tileToDraw are zero…
I have two other list in my class, and they work well.
I think because there is TileSet in TileDraw.
How can I fix this? Someone explained to me how it works?
Thank You guys ![]()