N
N
n_fridman2021-08-25 03:15:06
Unity
n_fridman, 2021-08-25 03:15:06

Unity Property Drawer. How to make custom property output for each element in a list?

Hello everyone, here is such a structure:

[System.Serializable]
    public struct LocalizationResource
    {
        public string name;
        
        public string resourceName;
        public string filename;
        public string webResourceUrl;

        public LocalizationProviderType type;
    }

And here is such an Enum:
[System.Serializable]
    public enum LocalizationProviderType
    {
        UnityResourcesSystem = 0,
        FileSystem = 1,
        WebResourcesSystem = 2
    }


There is also a class in which a list of structures is declared, in which there is a list of LocalizationResource structures, this is how it looks:
61258a2f23ec1691436425.png

You need to somehow contrive and make sure that the fields of the LocalizationResource structure are displayed depending on the value of the type field. Something like this:
61258ab55b8df400684315.png
61258ae854645070122620.png
61258b3387038733714019.png

Each enam value displays its own structure field, as far as I know this is done somehow through the PropertyDrawer, but I can’t figure it out myself. Maybe someone can help with this issue?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pashara, 2021-08-25
@n_fridman

This task can be solved with the help of field attributes.
Here, for example, this .
This is how to use it.

[SerializeField] LocalizationProviderType type;

[ConditionalField("NextState", LocalizationProviderType.WebResourcesSystem )] 
[SerializeField] private string webResourceUrl;

PS IMHO, the approach for each sneeze to have its own field is not entirely correct. In fact, this is a path field, and not some data specific to each type of data. How this data is used further is the responsibility of other components.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question