Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with displaying List<MyStruct> in EditorWindow #8

Open
michalfialadev opened this issue Dec 31, 2018 · 0 comments
Open

Help with displaying List<MyStruct> in EditorWindow #8

michalfialadev opened this issue Dec 31, 2018 · 0 comments

Comments

@michalfialadev
Copy link

michalfialadev commented Dec 31, 2018

Im really sorry to be filing an "issue", where there is none, perhaps it would be best to have a Unity Forums thread where i could place this instead..

Anyway, I'm really bad at writing Editor scripts, and what i need is to display List of MyStruct Items, where MyStruct is:
[System.Serializable] public struct ContainerItemDefinition { public Texture2D texture; public string prefabName; }

Its in a separate Class that extends ScriptableObject, then this is instantiated into Assets/xyz folder, and EditorWindow uses EditorGUIUtility.Load to load that as it's data model. Then the EditorWindow calls this in its Awake function (to initialize the data model for rotorz):
serializedObject = new SerializedObject(data); ciDefinitionsProperty = serializedObject.FindProperty("containerItemDefinitions");

Where containerItemDefinitions is
[SerializeField] public List<ContainerItemDefinition> containerItemDefinitions;

So far so good. Tracing the data reveals, all was successful. Now to display the data, in OnGUI:
`if (this.serializedObject == null) {
return;
}

    this.serializedObject.Update();
    
    ReorderableListGUI.ListField(this.ciDefinitionsProperty, DrawMyItem);

    serializedObject.ApplyModifiedProperties();`

But i dont know the proper syntax or what objects to create here to properly list the struct items inside the list for rotorz. Specifically the DrawMyItem method (which i suppose should be used to draw one single item?) Im a bit lost when it comes to Editor GUI Labels/input fields/Object Picker/.. drawings of display elements. Can someone help me?

PS: I can simply use
EditorGUILayout.PropertyField(ciDefinitionsProperty, true); //-> show children true!!!
which works okay for me, except it doesnt use Rotorz and so it doesnt support item reordering and the other fancy stuff ReorderableList gives you. I read somewhere, that the ",showChildren" is a new parameter, and before users had to write their own "PropertyDrawers" i guess is the name, ans thats what i need help with - how to draw those same GUI elements (string label and Texture2D picker) manually so rotorz can use them in the list display? Bit of code would be apprecciated, or guide that i could read to learn some Editor GUI scripting, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant