@@ -38,13 +38,14 @@ public class AvatarConfigEditor : UnityEditor.Editor
38
38
private VisualElement root ;
39
39
private Action textureChannelChanged ;
40
40
41
+ private SerializedProperty shaderPropertyMappingList ;
42
+
41
43
public override VisualElement CreateInspectorGUI ( )
42
44
{
43
45
root = new VisualElement ( ) ;
44
46
visualTreeAsset . CloneTree ( root ) ;
45
-
46
47
avatarConfigTarget = ( AvatarConfig ) target ;
47
-
48
+ shaderPropertyMappingList = serializedObject . FindProperty ( "ShaderPropertyMapping" ) ;
48
49
SetupLod ( ) ;
49
50
SetupPose ( ) ;
50
51
SetupTextureAtlas ( ) ;
@@ -255,65 +256,106 @@ private void SetupShader()
255
256
var shader = root . Q < ObjectField > ( "ShaderOverride" ) ;
256
257
shader . SetValueWithoutNotify ( avatarConfigTarget . Shader ) ;
257
258
259
+ shader . RegisterValueChangedCallback ( x =>
260
+ {
261
+ avatarConfigTarget . Shader = ( Shader ) x . newValue ;
262
+ Save ( ) ;
263
+ SetupShader ( ) ;
264
+ }
265
+ ) ;
258
266
var shaderPropertiesContainer = root . Q < VisualElement > ( "ShaderProperties" ) ;
259
- CreateShaderProperties ( shaderPropertiesContainer ) ;
260
-
261
- textureChannelChanged += ( ) => ShowShaderProperties ( shaderPropertiesContainer ) ;
262
- if ( shader . value == null )
267
+ shaderPropertiesContainer . Clear ( ) ;
268
+ shaderPropertiesContainer . style . display = DisplayStyle . Flex ;
269
+ shaderPropertiesContainer . style . flexDirection = FlexDirection . Column ;
270
+ if ( avatarConfigTarget . Shader == null )
263
271
{
264
272
shaderPropertiesContainer . style . display = DisplayStyle . None ;
265
273
}
266
274
else
267
275
{
268
- ShowShaderProperties ( shaderPropertiesContainer ) ;
269
- }
270
-
271
- shader . RegisterValueChangedCallback ( x =>
276
+ shaderPropertiesContainer . style . display = DisplayStyle . Flex ;
277
+ shaderPropertiesContainer . style . marginTop = 10 ;
278
+ shaderPropertiesContainer . style . left = 10 ;
279
+ shaderPropertiesContainer . style . right = 10 ;
280
+ var titleRowContainer = new VisualElement ( ) ;
281
+ titleRowContainer . style . flexDirection = FlexDirection . Row ;
282
+ titleRowContainer . style . marginBottom = 7 ;
283
+ titleRowContainer . style . marginTop = 7 ;
284
+ titleRowContainer . style . left = 10 ;
285
+ titleRowContainer . style . right = 10 ;
286
+ var sourceTitleField = new Label ( "Source Property" )
272
287
{
273
- avatarConfigTarget . Shader = ( Shader ) x . newValue ;
274
- Save ( ) ;
275
- if ( x . newValue == null )
288
+ style =
276
289
{
277
- shaderPropertiesContainer . style . display = DisplayStyle . None ;
290
+ width = 200 , unityFontStyleAndWeight = FontStyle . Bold , // Make the text bold
291
+ unityTextAlign = TextAnchor . MiddleLeft
278
292
}
279
- else
280
- {
281
- ShowShaderProperties ( shaderPropertiesContainer ) ;
282
- }
283
- }
284
- ) ;
285
- }
286
-
287
- private void ShowShaderProperties ( VisualElement shaderPropertiesContainer )
288
- {
289
- shaderPropertiesContainer . style . display = DisplayStyle . Flex ;
290
- foreach ( var child in shaderPropertiesContainer . Children ( ) )
291
- {
292
- if ( avatarConfigTarget . TextureChannel . Contains ( ( TextureChannel ) Enum . Parse ( typeof ( TextureChannel ) , child . name ) ) )
293
+ } ;
294
+ titleRowContainer . Add ( sourceTitleField ) ;
295
+ var targetTitleField = new Label ( "Target Property" )
293
296
{
294
- child . style . display = DisplayStyle . Flex ;
295
- }
296
- else
297
+ style = { width = 200 , marginRight = 10 , flexGrow = 0.8f , unityFontStyleAndWeight = FontStyle . Bold , }
298
+ } ;
299
+ titleRowContainer . Add ( targetTitleField ) ;
300
+ var typeTitleField = new Label ( "Type" )
297
301
{
298
- child . style . display = DisplayStyle . None ;
299
- }
300
- }
301
- }
302
-
303
- private void CreateShaderProperties ( VisualElement shaderPropertiesContainer )
304
- {
305
- foreach ( TextureChannel textureChannel in Enum . GetValues ( typeof ( TextureChannel ) ) )
306
- {
307
- var field = new TextField ( textureChannel . ToString ( ) ) ;
308
- field . name = textureChannel . ToString ( ) ;
309
- var property = avatarConfigTarget . ShaderProperties . FindIndex ( x => x . TextureChannel == textureChannel ) ;
310
- field . SetValueWithoutNotify ( avatarConfigTarget . ShaderProperties [ property ] . PropertyName ) ;
311
- field . RegisterValueChangedCallback ( x =>
302
+ style = { width = 70 , alignSelf = Align . FlexEnd , unityFontStyleAndWeight = FontStyle . Bold , }
303
+ } ;
304
+ titleRowContainer . Add ( typeTitleField ) ;
305
+ shaderPropertiesContainer . Add ( titleRowContainer ) ;
306
+ for ( int i = 0 ; i < shaderPropertyMappingList . arraySize ; i ++ )
312
307
{
313
- avatarConfigTarget . ShaderProperties [ property ] . PropertyName = x . newValue ;
314
- Save ( ) ;
315
- } ) ;
316
- shaderPropertiesContainer . Add ( field ) ;
308
+ SerializedProperty mapping = shaderPropertyMappingList . GetArrayElementAtIndex ( i ) ;
309
+
310
+ var propertyContainer = new VisualElement ( ) ;
311
+ propertyContainer . style . flexDirection = FlexDirection . Column ;
312
+ //propertyContainer.style.marginBottom = 10;
313
+
314
+ var horizontalContainer = new VisualElement ( ) ;
315
+ horizontalContainer . style . flexDirection = FlexDirection . Row ;
316
+ horizontalContainer . style . marginBottom = 7 ;
317
+ horizontalContainer . style . marginTop = 7 ;
318
+ horizontalContainer . style . left = 10 ;
319
+ horizontalContainer . style . right = 10 ;
320
+ // Alternating background colors
321
+ propertyContainer . style . backgroundColor = i % 2 == 0 ? new StyleColor ( new Color ( 0.25f , 0.25f , 0.25f ) ) : new StyleColor ( new Color ( 0.3f , 0.3f , 0.3f ) ) ;
322
+
323
+ var sourcePropertyField = new Label ( mapping . FindPropertyRelative ( "SourceProperty" ) . stringValue )
324
+ {
325
+ style =
326
+ {
327
+ width = 200 , unityFontStyleAndWeight = FontStyle . Bold , // Make the text bold
328
+ unityTextAlign = TextAnchor . MiddleLeft
329
+ }
330
+ } ;
331
+ horizontalContainer . Add ( sourcePropertyField ) ;
332
+
333
+ var targetPropertyField = new TextField
334
+ {
335
+ value = mapping . FindPropertyRelative ( "TargetProperty" ) . stringValue ,
336
+ //style = { flexGrow = 1, marginTop = 5 }
337
+ style = { width = 200 , marginRight = 10 , flexGrow = 0.8f }
338
+ } ;
339
+ targetPropertyField . RegisterValueChangedCallback ( evt =>
340
+ {
341
+ mapping . FindPropertyRelative ( "TargetProperty" ) . stringValue = evt . newValue ;
342
+ Save ( ) ;
343
+ } ) ;
344
+ horizontalContainer . Add ( targetPropertyField ) ;
345
+
346
+ var propertyTypeField = new EnumField ( ( ShaderPropertyType ) mapping . FindPropertyRelative ( "Type" ) . enumValueIndex )
347
+ {
348
+ style = { width = 70 , alignSelf = Align . FlexEnd }
349
+ } ;
350
+ propertyTypeField . RegisterValueChangedCallback ( evt =>
351
+ {
352
+ mapping . FindPropertyRelative ( "Type" ) . enumValueIndex = ( int ) ( ShaderPropertyType ) evt . newValue ;
353
+ Save ( ) ;
354
+ } ) ;
355
+ horizontalContainer . Add ( propertyTypeField ) ;
356
+ propertyContainer . Add ( horizontalContainer ) ;
357
+ shaderPropertiesContainer . Add ( propertyContainer ) ;
358
+ }
317
359
}
318
360
}
319
361
0 commit comments