[유니티] 다차원 List inspector 창에 표시

jh Seo·2025년 1월 21일
0

유니티

목록 보기
60/62

개요

기본적으로 유니티는 2차원부터 다차원에 해당하는 배열이나 자료구조를 inspector에 표기하지 않는다.

[Serializable]
public struct CutsceneInfo
{
    public ECutsceneType cutsceneType;
    public int arg;
    public PrimaryCutscene primaryCutscene;
}

public List<CutsceneInfo> cutsceneInfos;

위처럼 커스텀 구조체 cutsceneinfo를 serializable 매크로를 사용한 직렬화를 통해
인스펙터에 표시하고 있었다.

하지만

public List<List<CutsceneInfo>> cutsceneInfos;

이런식으로 2차원을 선언하면 인스펙터 창에 표기되지 않는다.

해결

unity document의 serialization rules 문서에서 본 일종의 트릭을 써서 해결했다.
바로 해당 List를 wrapping한 다른 구조체를 선언 후 serializable매크로를 또 사용하면 된다.

[Serializable]
public struct NestedCutsceneInfo
{
    public List<CutsceneInfo> cutsceneInfos;
}

이렇게 한 후,

public List<NestedCutsceneInfo> Cutscenes;

이런식으로 wrapping한 구조체의 List를 선언하면 inspector 창에 잘 표시된다!

레퍼런스

Unity Docs

Note: Unity doesn’t support serialization of multilevel types (multidimensional arrays, jagged arrays, dictionaries, and nested container types). If you want to serialize these, you have two options:

  • Wrap the nested type in a class or struct
  • Use serialization callbacks, by implementing ISerializationCallbackReceiver, to perform custom serialization.
profile
코딩 창고!

0개의 댓글

관련 채용 정보