As outlined in the comments in Snippet 1.3 the agenda for the OnGUI() method is to find all the scene names (listed in the build settings), check if the current value of the string corresponds to one of those scene names, and of course actually draw the nice little dropdown. As always when working with SerializedProperties (of SerializedObjects), we wanna start by updating the property to include the latest changes, as well as end with applying any modifications we might do.

Since we include the possibility to exclude the scene path, the code has to branch if only a little bit. As you remember, the attribute has a showPath property that defaults to false, but we can’t see if the overloaded constructor was used or not, so we’ll start by grabbing a reference to the target attribute, which will allow us to check the value of the bool in the PropertyDrawer. We’ll also check the property.stringValue to check if it is valid or not, which we’ll do in the IsValidSceneName() method (we’ll get to in a moment). If it’s valid (meaning theres a scene with the same name in the build settings) we find the corresponding index in the array of valid strings and assign it to the selectedIndex variable. The reason we want to do this check (rather than just keeping the index consistent) is that if the order of the scenes in the build settings are ever reordered, we would end up with other scene names in our MonoBehaviours (which I think we can agree can only lead to a world of pain).

Finally, we use the EditorGUI.Popup() method to draw the nice dropdown, feeding it the property Rect, the nice display name of the property (eg. “MyProperty” becomes “My Property” in the Inspector), the selected index (which also draws a nice little checkmark next to the selected value in the dropdown), and the array of valid scene names that we get from the GetValidSceneNames() method that we’ll get to next.