대충 만들어서 미구현된 부분이 많음..
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using System;
[Serializable]
//[SerializeField]
public class DataBase
{
public string id;
public int num;
}
[Serializable]
//[SerializeField]
public class ListToDIc: IDictionary<string, DataBase>,
ISerializationCallbackReceiver
{
public DataBase[] dataBase = new DataBase[2] { new DataBase() { id = "A" }, new DataBase() { id = "B" } };
IDictionary<string, DataBase> m_LevelDictionary;
#region IDictionary
public DataBase this[string key] { get => m_LevelDictionary[key]; set => throw new System.NotImplementedException(); }
public ICollection<string> Keys => throw new System.NotImplementedException();
public ICollection<DataBase> Values => throw new System.NotImplementedException();
public int Count => dataBase.Length;
public bool IsReadOnly => throw new System.NotImplementedException();
public void Add(string key, DataBase value)
{
throw new System.NotImplementedException();
}
public void Add(KeyValuePair<string, DataBase> item)
{
throw new System.NotImplementedException();
}
public void Clear()
{
throw new System.NotImplementedException();
}
public bool Contains(KeyValuePair<string, DataBase> item)
{
return m_LevelDictionary.Contains(item);
}
public bool ContainsKey(string key)
{
return m_LevelDictionary.ContainsKey(key);
}
public void CopyTo(KeyValuePair<string, DataBase>[] array, int arrayIndex)
{
throw new System.NotImplementedException();
}
public IEnumerator<KeyValuePair<string, DataBase>> GetEnumerator()
{
throw new System.NotImplementedException();
}
public bool Remove(string key)
{
throw new System.NotImplementedException();
}
public bool Remove(KeyValuePair<string, DataBase> item)
{
throw new System.NotImplementedException();
}
public bool TryGetValue(string key, out DataBase value)
{
throw new System.NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new System.NotImplementedException();
}
#endregion
public void OnAfterDeserialize()
{
m_LevelDictionary = dataBase.ToDictionary(l => l.id);
}
public void OnBeforeSerialize()
{
Debug.Log(dataBase.Length);
// throw new System.NotImplementedException();
}
}
public class ListToDIcExample : MonoBehaviour
{
public ListToDIc listToDic;
public int temp;
// Start is called before the first frame update
void Start()
{
//if (listToDic.ContainsKey("A"))
//{
// Debug.Log("A");
//}
//if (listToDic.ContainsKey("C"))
//{
// Debug.Log("A");
//}
//listToDic.dataBase[0].id = "A";
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyUp(KeyCode.A))
{
if (listToDic.ContainsKey("A"))
{
Debug.Log("A");
}
if (listToDic.ContainsKey("C"))
{
Debug.Log("A");
}
listToDic.dataBase[0].id = "A";
}
}
}
'Unity > 코드 예제들' 카테고리의 다른 글
com.unity.localization (0) | 2021.03.15 |
---|---|
폴더안 파일복사 (0) | 2021.02.18 |
모바일 네트워크 상태 확인 (0) | 2020.10.30 |
NGUI 게임도중에 orientation을 이용해 가로세로전환 (0) | 2020.06.16 |
타일맵의 셀좌표와 포지션 정보 얻어오기 (0) | 2019.10.10 |