Last active
December 19, 2015 14:09
-
-
Save tsubaki/5966919 to your computer and use it in GitHub Desktop.
同一オブジェクト上でデータを共有する為のクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class DataStrage : MonoBehaviour { | |
Dictionary<string, object> dataList = new Dictionary<string, object>(); | |
public void OnDestroy (){ Clear (); } | |
public void SetInt(string key, int value){ SetParam<int>(key, value); } | |
public int GetInt(string key, int def) { return GetParam<int>(key, def); } | |
public int GetInt(string key) { return GetParam<int>(key, 0); } | |
public void SetString(string key, string value){ SetParam<string>(key, value); } | |
public string GetString(string key, string def) { return GetParam<string>(key, def); } | |
public string GetString(string key) { return GetParam<string>(key, null); } | |
public void SetBool(string key, bool value){ SetParam<bool>(key, value); } | |
public bool GetBool(string key, bool def) { return GetParam<bool>(key, def); } | |
public bool GetBool(string key) { return GetParam<bool>(key, false); } | |
public void SetObject(string key, Object value){ SetParam<Object>(key, value); } | |
public Object GetObject(string key, Object def) { return GetParam<Object>(key, def); } | |
public Object GetObject(string key) { return GetParam<Object>(key, null); } | |
public void RemoveKey(string key){ dataList.Remove(key); } | |
public void Clear () { dataList.Clear (); } | |
protected void SetParam<T>(string key, T value) { dataList[key] = (object) value; } | |
protected T GetParam<T>(string key, T def){ return dataList.ContainsKey(key) == true ? (T) dataList[key] : def; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment