[Unity3D] Unity에서 xml이용하여 Dictionary 데이터 저장 불러오기 하기

|
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using System.Runtime.Serialization;


[DataContract]
public class GohnVariables 
{
 	private Dictionary

_varInt = new Dictionary(); [DataMember(Name = "VarInt")] public Dictionary VarInt { get { return _varInt; } set { _varInt = value; } } public string _autosavePath = Application.dataPath + Path.DirectorySeparatorChar + "StrumpyGohnEditor" + Path.DirectorySeparatorChar + "Editor" + Path.DirectorySeparatorChar + "Resources" + Path.DirectorySeparatorChar + "Internal" + Path.DirectorySeparatorChar + "Temp" + Path.DirectorySeparatorChar; public void Start() { _varInt.add("a",1); _varInt.add("b",2); _varInt.add("c",3); } // Save와 Load 함수는 입맛에 맞게 호출 해서 사용하면 됩니다. public void Save() { var writeInt = new FileStream(_autosavePath + "VarInt.xml", FileMode.Create); var serInt = new DataContractSerializer(typeof(Dictionary)); serInt.WriteObject(writeInt, VarInt); writeInt.Close(); } public void Load() { var fi = new FileInfo(_autosavePath + "VarInt.xml"); if (fi.Exists) { try { var fs = fi.OpenRead(); var reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas()); var ser = new DataContractSerializer(typeof(Dictionary)); var loaded = ser.ReadObject(reader, true) as Dictionary; _varInt = loaded; reader.Close(); fs.Close(); } catch( Exception e ) { Debug.Log( e ); EditorUtility.DisplayDialog("Load xml Error", "Could not Int xml", "Ok"); } } } }
저작자 표시 비영리 변경 금지
신고
Trackback 1 And Comment 0
prev | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ··· | 30 | next

티스토리 툴바