I’m trying to make maps that can be loaded by file, and including a map editor in my engine. But for some reason when i load the map data, it has no value at all. can anyone tell me what i’m doing wrong?
public void load(string Name){
Debug.Log("Out -> "+Application.dataPath+"/Resoures/Data/Maps/"+Name+".MLWmap");
if(File.Exists(Application.dataPath+"/Resoures/Data/Maps/"+Name+".MLWmap")){
BinaryFormatter ibf = new BinaryFormatter();
FileStream file = File.Open(Application.dataPath + "/Resoures/Data/Maps/"+Name+".MLWmap", FileMode.Open);
MapData _data = (MapData) ibf.Deserialize(file);
file.Close();
xSize = _data.xSize;
ySize = _data.ySize;
Debug.Log(_data.xSize+":"+_data.ySize);
int ttt;
string tx;
Type = new int[_data.xSize,_data.ySize];
for(int i=0; i<_data.xSize; i++){
tx = "";
for(int j=0; j<_data.ySize; j++){
ttt = _data.Type[i,j];
Type[i,j] = ttt;
tx += _data.Type[i,j]+" ";
}
Debug.Log(tx);
}
}
}
public void save(string Name){
Debug.Log("Out -> "+Application.dataPath+"/Resoures/Data/Maps/"+Name+".MLWmap");
if(!Directory.Exists(Application.dataPath+"/Resources/Data/Maps")){
Directory.CreateDirectory(Application.dataPath+"/Resources/Data/Maps");
}
BinaryFormatter obf = new BinaryFormatter();
FileStream _file;
if(!File.Exists(Application.dataPath + "/Resources/Data/Maps/" + Name + ".MLWmap")){
_file = File.Create(Application.dataPath+"/Resources/Data/Maps/"+Name+".MLWmap");
}
else{
_file = File.Open(Application.dataPath+"/Resources/Data/Maps/"+Name+".MLWmap", FileMode.Open);
}
MapData _data = new MapData();
_data.xSize = xSize;
_data.ySize = ySize;
_data.Type = new int[xSize,ySize];
string tx;
int ttt;
for(int i=0; i<xSize; i++){
for(int j=0; j<ySize; j++){
ttt = Type[i,j];
_data.Type[i,j] = ttt;
}
}
Debug.Log(_data.xSize+":"+_data.ySize);
for(int a=0; a<_data.xSize; a++){
tx="";
for(int b=0; b<_data.ySize; b++){
tx +=_data.Type[a,b]+" ";
}
Debug.Log(tx);
}
obf.Serialize(_file, _data);
_file.Close();
}