v0lt13 / EditorAttributes

EditorAttributes is a unity package that adds some extra editor attributes to your project to easily customize your editors without having to write any editor code.
https://editorattributesdocs.readthedocs.io/
The Unlicense
88 stars 7 forks source link

Issue with the layout when trying to add a new element to a list #4

Closed seeman4o closed 4 months ago

seeman4o commented 5 months ago

I have this code:

#region █ EACH DAY AVERAGES █
[Space(20)]
[Title("<b>〇  Each Day Averages</b>", 15, false, TextAnchor.MiddleLeft)]
#endregion

[SerializeField] public List<EachDayAveragesStruct> eachDayAveragesDataList = new List<EachDayAveragesStruct>();
[System.Serializable]
public struct EachDayAveragesStruct
{
    public float dailyHigh_Highest;
    public float dailyHigh_Average; 
    public float dailyHigh_Lowest;
    [Space]
    public float dailyLow_Highest;
    public float dailyLow_Average;
    public float dailyLow_Lowest;
}

private void GenNewMonthOverview()
{
eachDayAveragesDataList.Clear();
eachDayAveragesDataList = new List<EachDayAveragesStruct>();
for (int day = 1; day <= monthTotalDays; day++)
{
...
EachDayAveragesStruct dayData = new EachDayAveragesStruct();
...
eachDayAveragesDataList.Add(dayData);
}

Which breaks the inspector:

image

And the console returns:

ArgumentException: Getting control 104's position in a group with only 104 controls when doing repaint Aborting

And I am not really sure why it is adding a Title for each Element in the list...

seeman4o commented 5 months ago

Stupid fix from me:

#region █ EACH DAY AVERAGES █
[Space(20)]
[Title("<b>〇  Each Day Averages</b>", 15, false, TextAnchor.MiddleLeft)]
#endregion

#region []
[SerializeField, HideInEditMode, HideInPlayMode] private string emptyString;
#endregion

// This will hold generated 6 averages for each day. With them we can generate each day all hours.
[SerializeField] public List<EachDayAveragesStruct> eachDayAveragesDataList = new List<EachDayAveragesStruct>();
[System.Serializable]
public struct EachDayAveragesStruct
{
    public float dailyHigh_Highest;
    public float dailyHigh_Average; 
    public float dailyHigh_Lowest;
    [Space]
    public float dailyLow_Highest;
    public float dailyLow_Average;
    public float dailyLow_Lowest;
}

Still, there are some issues with the [Title] and putting elements before/after it. For example, the [Space] is always added before the [Title] never after.

v0lt13 commented 5 months ago

The error is cause due to the EditorGUILayout function inside arrays, in the next update I'm porting the package to UI toolkit so issues like that shouldn't exist anymore.

Unity only supports property attributes on arrays starting with unity 2023.3/6 preview, right now the attributes will only affect the array elements, I already added support for that version to the package, you will just have to update your project to that version to be able to affect arrays, but take note of this bug

The space attribute will never work after the title because the title is a property drawer not a decorator drawer to be able to support dynamic text, so it draws the title then the property attached to it in the same drawer, I can add an offset parameter to it to be able to have some space between the title and property in the next update

seeman4o commented 5 months ago

Thank you! Yes, I am currently using 2023.3.22f1

I just played with the TitleDrawer and managed to customize the headers/titles in line with what I was having before (I was using my own stuff to style them). I think it would be a nice touch if you could add some additional parameters to that, in case people want to style them a bit more (like me). Adding space after a title would help the most imo. I hardcoded my old styles in the script and have these variations now:

image

You can easily achieve that by adding a color parameter for the line, call EditorGUI.DrawRect before the LabelField, change the height and have some position.y offset... just sharing my thoughts that may give you some ideas on what to improve in the future. I think I can add an image as well, but that is too much even for me :) Cheers and thank you for the work, it is great!

v0lt13 commented 5 months ago

Yeah that's a good idea, I will add some styles to the header attribute, will do in the next update. If you have anymore suggestion or issues feel free to join my discord server and we can talk there