[유니티3D엔진] C# 어레이리스트 dat 파일 로드 및 저장 (바이너리 파일로 변환)
1. 먼저 클래스 직렬화로 만들기
using UnityEngine;
using System.Collections;
using System;
// ( 이것 때문에 하루 걸렸다 ㅠ 클래스 앞에 꼭 [Serializable] 붙이기 )
[Serializable]
public class Sm_mlevel_st_entry
{
private string stl1;
private string stl2;
private string stl3;
private string stl4;
private string stl5;
public Sm_mlevel_st_entry(string _stl1, string _stl2, string _stl3, string _stl4, string _stl5)
{
this.stl1 = _stl1; //ml_level
this.stl2 = _stl2; //ml_1
this.stl3 = _stl3; //ml_2
this.stl4 = _stl4; //ml_3
this.stl5 = _stl5; //ml_4
}
public string getStl1()
{
return stl1;
}
public string getStl2()
{
return stl2;
}
public string getStl3()
{
return stl3;
}
public string getStl4()
{
return stl4;
}
public string getStl5()
{
return stl5;
}
}
2. 저장 및 로드 함수
public object LoadData(string file_Name)
{
if (File.Exists(Application.dataPath + "/Sm_data_table/" + file_Name + ".dat"))
{
var b = new BinaryFormatter();
var f = File.Open(Application.dataPath + "/Sm_data_table/" + file_Name + ".dat", FileMode.Open);
object obj = b.Deserialize(f);
f.Close();
return obj;
}
else
{
return null;
}
}
public void SaveData( string file_Name, object tmp_list )
{
var b = new BinaryFormatter();
var f = File.Create(Application.dataPath + "/Sm_data_table/" + file_Name + ".dat");
b.Serialize(f, tmp_list);
f.Close();
}
3. 사용하기
List<Sm_mlevel_st_entry> tmpList = new List<Sm_mlevel_st_entry>();
for (int i = 0; i < 5; i++)
{
Sm_mlevel_st_entry entry1 = new Sm_mlevel_st_entry("1q " + i.ToString(), "2w " + i.ToString(), "3e " + i.ToString(), "4r " + i.ToString(), "5t " + i.ToString());
tmpList.Add(entry1);
}
Sm_data_table.instance.SaveData("sm_mlevel_st", tmpList); // 세이브
List<Sm_mlevel_st_entry> tmpList2 = new List<Sm_mlevel_st_entry>();
tmpList2 = (List<Sm_mlevel_st_entry>) Sm_data_table.instance.LoadData("sm_mlevel_st"); // 로드
-
[CentOS] NTFS마운트하기
-
CentOS 6.x 설치 시 BIOS RAID metadata 문제
-
XE 속도개선 (XE 캐시파일 초기화 시간 줄이는 팁) - 다국어 제거
-
Chrome on Centos
-
INSTALLING NVIDIA LINUX DRIVERS IN A XEN ENABLED KERNEL
-
Install NVIDIA Drivers in XEN Kernel
-
XE 속도 개선팁 모음
-
memcached 설치 및 설정
-
XE 쇼핑몰 솔루션
-
알아두면 유용한 무료사이트 20선
-
Ubuntu, HWP 2008 installation on x86 and x64 (only Link)
-
USB 저장장치에 의한 데이터 유출 방지 방법
-
파일검색 루틴 (개발용)
-
Realtek 8723be-bt 무선랜 드라이버 (한성 u44x )
-
[LINK] 윈도우 8 관리자 권한 설정으로 항상 관리자 권한 얻기
-
C# How to make a simple MP3 player in C#
-
[ 유니티3D엔진 ] FPS 프레임 조절
-
[ OS X ] 폴더 숨김파일 표시
-
C#에서 무료 TTS 사용하기
-
우분투 sudo 비밀번호 안물어보게 하기