1
+ using System . Globalization ;
2
+ using System . Text . RegularExpressions ;
3
+ using UnityEditor . UIElements ;
4
+ using UnityEngine . UIElements ;
5
+
6
+ namespace UnityEditor
7
+ {
8
+ [ CustomPropertyDrawer ( typeof ( SceneManifest . SceneItem ) ) ]
9
+ internal sealed class SceneItemsPropertyDrawer : PropertyDrawer
10
+ {
11
+ public override VisualElement CreatePropertyGUI ( SerializedProperty property )
12
+ {
13
+ var root = new VisualElement ( ) ;
14
+
15
+ var foldout = new Foldout { text = property . displayName , value = false } ;
16
+ root . Add ( foldout ) ;
17
+
18
+ const string nameTypeName = nameof ( SceneManifest . SceneItem . Name ) ;
19
+ const string categoryTypeName = nameof ( SceneManifest . SceneItem . Category ) ;
20
+ const string descriptionTypeName = nameof ( SceneManifest . SceneItem . Description ) ;
21
+ const string scenePathTypeName = nameof ( SceneManifest . SceneItem . ScenePath ) ;
22
+
23
+ var nameProperty = property . FindPropertyRelative ( nameTypeName ) ;
24
+ var categoryProperty = property . FindPropertyRelative ( categoryTypeName ) ;
25
+ var descriptionProperty = property . FindPropertyRelative ( descriptionTypeName ) ;
26
+ var scenePathProperty = property . FindPropertyRelative ( scenePathTypeName ) ;
27
+
28
+ // Name.
29
+ var namePropertyField = new TextField { label = nameTypeName , bindingPath = nameProperty . propertyPath , enabledSelf = false } ;
30
+ foldout . Add ( namePropertyField ) ;
31
+
32
+ // Category.
33
+ foldout . Add ( new PropertyField ( categoryProperty , categoryTypeName ) ) ;
34
+
35
+ // Description.
36
+ foldout . Add ( new PropertyField ( descriptionProperty , descriptionTypeName ) ) ;
37
+
38
+ // Scene Path.
39
+ var scenePathPropertyField = new TextField { label = scenePathTypeName , bindingPath = scenePathProperty . propertyPath , enabledSelf = false } ;
40
+ foldout . Add ( scenePathPropertyField ) ;
41
+
42
+ // Provide the ability to drag a Unity Scene here.
43
+ var unitySceneField = new ObjectField ( "Unity Scene" ) { value = AssetDatabase . LoadAssetAtPath < SceneAsset > ( scenePathProperty . stringValue ) } ;
44
+ unitySceneField . RegisterValueChangedCallback ( evt =>
45
+ {
46
+ namePropertyField . value = CultureInfo . CurrentCulture . TextInfo . ToTitleCase ( Regex . Replace ( evt . newValue . name , "(\\ B[A-Z])" , " $1" ) ) ;
47
+ scenePathPropertyField . value = AssetDatabase . GetAssetPath ( evt . newValue ) ;
48
+ } ) ;
49
+ foldout . Add ( unitySceneField ) ;
50
+
51
+ return root ;
52
+ }
53
+ }
54
+ }
0 commit comments