Unity SerializableDictionary
유니티에서 쓰는 Dictionary는 직렬화가 되지 않기 때문에 Inspector에서 제어가 되지 않는다. key-value 쌍으로 관리해야 하는 데이터가 있는 경우 불편함이 있는데, 이전에 검색을 통해 적용했던 Dictionary 보다 사용성이 좋아서 테스트 해 보았다. (2021년 3월에 업데이트 된 것으로 보인다.)
관련 사이트: https://wiki.unity3d.com/index.php/SerializableDictionary
SerializableDictionary - Unify Community Wiki
Author: Fredrik Ludvigsen (Steinbitglis) Notice 1 This collection has been updated (as of Mar. 2021). Check the document history for the old version. Notice 2 A much more advanced version is now available at Rain Games office server. This can be added as a
wiki.unity3d.com
설치
Project Settings > Package Manager에 새로운 Registry를 추가한다. (2020 이상 버전부터 사용 가능)
- Name: Rain Office
- URL: https://office.rain-games.com:4873
- Scope(s): com.beetlecircus
Package Manager에서 SerializableDictionary 패키지를 설치한다.
사용 예
public class 클래스이름 : MonoBehaviour
{
[SerializeField] private SerializableDictionary<int, GameObject> m_MonsterRepository;
...
}
위와 같이 public이나 SerializeField로 선언되면 Inspector에 아래와 같이 표시가 된다.
key가 enum으로도 지원이 되는지는 별도로 테스트 해 볼 예정이다.