- Home /
Having trouble styling custom UI
I want to make a two-column UI in unity to manage a pair of fields so I made a custom UI. Howerver, I came up with this inconvenient view and can't help myself. This is what it looks like.
My trouble is: I can't remove the "Element" tag. Is there a way to remove them? Besides, I'd like to know how to add a little space between these two columns.
This is my code in my custom editor:
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(_itemNumber);
GUILayout.BeginHorizontal();
GUILayout.BeginVertical();
GUILayout.Label("Item Name");
for (int i=0; i<_itemNumberToShow; i++)
{
SerializedProperty itemProperty = _items.GetArrayElementAtIndex(i);
EditorGUILayout.PropertyField(itemProperty);
}
GUILayout.EndVertical();
GUILayout.BeginVertical();
GUILayout.Label("Drop Chance");
for(int i=0; i<_itemNumberToShow; i++)
{
SerializedProperty chanceProperty = _chances.GetArrayElementAtIndex(i);
if (chanceProperty.floatValue < 0)
chanceProperty.floatValue = 0;
EditorGUILayout.PropertyField(chanceProperty);
}
GUILayout.EndVertical();
GUILayout.EndHorizontal();
if (_itemNumber.intValue < 0)
_itemNumber.intValue = 0;
serializedObject.ApplyModifiedProperties();
}
,I want to make a two-column UI in unity to manage a pair of fields so I made a custom UI. Howerver, I came up with this inconvenient view and can't help myself. This is what it looks like.
My trouble is: I can't remove the "Element" tag. Is there a way to remove them? Besides, I'd like to know how to add a little space between these two columns.
This is my code in my custom editor(I did't use property drawer for it didn't seem to work):
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(_itemNumber);
GUILayout.BeginHorizontal();
GUILayout.BeginVertical();
GUILayout.Label("Item Name");
for (int i=0; i<_itemNumberToShow; i++)
{
SerializedProperty itemProperty = _items.GetArrayElementAtIndex(i);
EditorGUILayout.PropertyField(itemProperty);
}
GUILayout.EndVertical();
GUILayout.BeginVertical();
GUILayout.Label("Drop Chance");
for(int i=0; i<_itemNumberToShow; i++)
{
SerializedProperty chanceProperty = _chances.GetArrayElementAtIndex(i);
if (chanceProperty.floatValue < 0)
chanceProperty.floatValue = 0;
EditorGUILayout.PropertyField(chanceProperty);
}
GUILayout.EndVertical();
GUILayout.EndHorizontal();
if (_itemNumber.intValue < 0)
_itemNumber.intValue = 0;
serializedObject.ApplyModifiedProperties();
}
Thank you for reading!
Answer by Hellium · May 31, 2020 at 09:42 AM
EditorGUILayout.PropertyField
accepts a 2nd argument as label. Try with GUIContent.none
.
Your answer
Follow this Question
Related Questions
Project contains compiler errors 0 Answers
Split animation array like for Custom Editor 0 Answers
Custom HUD Hierarchy in Editor Window 2 Answers
How can I display another enum? 1 Answer
Display list of 2D arrays 1 Answer