Unity3D - 데이터 저장하기

Programming/Unity3D 2013.05.07 20:30 Posted by 파란크리스마스

출처 : 유니티에서 데이터 저장하기 #1

DataUser.cs

using UnityEngine;
using System.Collections;

public class DataUser {

	private string m_user_name;
	public string UserName {
		get {
			return m_user_name;
		}
		set {
			m_user_name = value;
		}
	}
	
	private string m_nick_name;
	public string NickName {
		get {
			return m_nick_name;
		}
		set {
			m_nick_name = value;
		}
	}
	
}

Main.cs

using UnityEngine;
using System.Collections;

public class Main : MonoBehaviour {
	
	// Use this for initialization
	void Start () {
		/*
		DataUser user = GetUserData();
		user.UserName = "test";
		user.NickName = "blue";
		
		SaveUserData(user);
		*/
		
		DataUser user = GetUserData();
		Debug.Log( user.UserName );
		
	}
	
	void SaveUserData(DataUser user) {
		PlayerPrefs.SetString("UserName", user.UserName);
		PlayerPrefs.SetString("NickName", user.NickName);		
	}
	
	DataUser GetUserData() {
		DataUser user = new DataUser();
		user.UserName = PlayerPrefs.GetString("UserName");
		user.NickName = PlayerPrefs.GetString("NickName");
		return user;
	}
}

 

신고
TAG


 

티스토리 툴바