Hello, can you please tell me if I can decrease the depth of neting in inspector, because i dont like the way it is now.
I have a structure like this:
public class PartCore : MonoBehaviour
{
public ConnectedParts connectedParts;
}
[System.Serializable]
public class ConnectedParts
{
public LeftPart left;
public RightPart right;
public BottomPart bottom;
public UpperPart upper;
}
[System.Serializable]
public class LeftPart : SidedPart
{
}
[System.Serializable]
public class RightPart : SidedPart
{
}
[System.Serializable]
public class BottomPart : SidedPart
{
}
[System.Serializable]
public class UpperPart : SidedPart
{
}
public class SidedPart
{
public PartCore part;
}
Can you please tell me if i can decrease it to just showing parts straightforward, without showing side of a part?
UPD: thanks for respond! Sorry for my terrible question format. Basically, I just want my variables to have a nice look, not like it’s done now. Now I have to expand every single “Left” or “Right” to somehow edit “Part” field. The thing I want to do is to reposition Part fields the way it would be eazier to edit ConnectedParts. For example it would be very nice if Parts were side by side just like if they vere positioned there:
[System.Serializable]
public class FourFloats
{
public float a;
public float b;
public float c;
public float d
}
Your current code does only contain type definitions but no actual fields. You probably have a ConnectedParts instance in your PartCore class? Also your ConnectedParts class probably has 4 fields (named left, right, bottom, upper) of type SidedPart? Also SidedPart probably has a field named “part” of type PartCore? Why have you omitted all that information? It makes it really difficult to actually follow your issue.
Well, assuming my summary is more or less correct, I don’t quite understand what you mean by decreasing the nesting. You have setup that kind of nesting, so how do you imagine that could look differently? If the SidedPart class has only a single field, you could implement a property drawer which draws the SidedPart class inline. Not sure if that’s already what you wanted?
We can’t even show you an example property drawer for your classes since your classes are missing all the fields. If you need any further help with this, please edit your question, add all the relevant code and also format your code properly. When you copy&pasted your code, just select all your code and press the 101 / 010 button. The code formatting requires an empty line before and after the code section and each line has to be indented by 4 spaces. That’s what this button does.
edit
If I understood you correctly you simply want a property drawer like this:
#if UNITY_EDITOR
namespace Editor
{
using UnityEditor;
[CustomPropertyDrawer(typeof(SidedPart), true)]
public class SidedPartDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.PropertyField(position, property.FindPropertyRelative("part"), label);
}
}
}
#endif
You can include this in your script file but it’s better to put that class into its own file inside an editor folder. This will simply display the part field inline. Of course if you add more fields to your SidedPart class or any of the derived classes, those would not show up in the inspector since our custom property drawer only draws that one nested property.