Hello guys! I have some problem. Please help me.
This my ScriptableObject
[System.Serializable]
public class dm_MapTiles : ScriptableObject
{
public dm_MapTiles() { }
public string mapName;
public Sprite[,] mapSprites;
}
And this is my Custom Editor Script
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
[CustomEditor(typeof(dm_MapTiles))]
public class dm_MapTilesEditor : Editor {
dm_MapTiles comp;
static bool showTileEditor = false;
public void OnEnable()
{
comp = (dm_MapTiles)target;
if (comp.mapSprites == null)
{
comp.mapSprites = new Sprite[1,1];
}
}
public override void OnInspectorGUI()
{
//MAP DEFAULT INFORMATION
comp.mapName = EditorGUILayout.TextField("Name", comp.mapName);
//WIDTH - HEIGHT
int width = EditorGUILayout.IntField("Map Sprite Width", comp.mapSprites.GetLength(0));
int height = EditorGUILayout.IntField("Map Sprite Height", comp.mapSprites.GetLength(1));
if (width != comp.mapSprites.GetLength(0) || height != comp.mapSprites.GetLength(1))
{
comp.mapSprites = new Sprite[width, height];
}
showTileEditor = EditorGUILayout.Foldout(showTileEditor, "Tile Editor");
if (showTileEditor)
{
for (int h = 0; h < height; h++)
{
EditorGUILayout.BeginHorizontal();
for (int w = 0; w < width; w++)
{
comp.mapSprites[w, h] = (Sprite)EditorGUILayout.ObjectField(comp.mapSprites[w, h], typeof(Sprite), false, GUILayout.Width(65f), GUILayout.Height(65f));
}
EditorGUILayout.EndHorizontal();
}
}
}
}
And this my screenshot
If I Play game, my scriptableobject lost all data. Please help me.
