Search Unity

Tree view in unity

Discussion in 'Visual Scripting' started by zzk1996, Jan 14, 2021.

  1. zzk1996

    zzk1996

    Joined:
    Aug 28, 2020
    Posts:
    13
    Hi I am new to unity and would like to ask if there exist assets or unity built-in components to achieve a tree view display given a dictionary of
    Code (CSharp):
    1. Dictionary<List<string>, string>
    . For e.g, a dictionary with 2 pairs of keys & values will display something similar to the image below, assuming that the List<string> only has 3 elements. Any suggestions such as existing guides/videos/ideas will be appreciated. Thank you!
     

    Attached Files:

  2. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    I have never seen a dictionary which uses a List as a key. If your intention is to have a compound key (each key is made of three strings), then this will not work as you want because List is a reference type (it's a class). When a reference type is used as a key in a dictionary, by default the key is the reference itself, not it's contents. This means that even if you create two separate lists with the same three strings, they'll be considered as two different keys on the dictionary because what is used as a key is the reference to the List, not the List contents.

    For compound keys, you can use C# 7 tuples:
    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-tuples

    Also, read the Microsoft documentation about the Dictionary type to know more about how key lookup is done and the requirements:
    https://docs.microsoft.com/en-us/do...ons.generic.dictionary-2?view=net-5.0#remarks