From bfb4ec4ef856da9ba87bdc7e7a475fcacb46bf33 Mon Sep 17 00:00:00 2001 From: Robin <1121080+rYuuk@users.noreply.github.com> Date: Fri, 5 Jan 2024 15:34:11 +0100 Subject: [PATCH] feat: shader properties show is based on texture channel --- .../UI/CustomEditors/AvatarConfigEditor.cs | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Editor/Core/Scripts/UI/CustomEditors/AvatarConfigEditor.cs b/Editor/Core/Scripts/UI/CustomEditors/AvatarConfigEditor.cs index b8377816..9333e039 100644 --- a/Editor/Core/Scripts/UI/CustomEditors/AvatarConfigEditor.cs +++ b/Editor/Core/Scripts/UI/CustomEditors/AvatarConfigEditor.cs @@ -36,6 +36,7 @@ public class AvatarConfigEditor : UnityEditor.Editor private bool previousMeshOptCompressionValue; private VisualElement root; + private Action textureChannelChanged; public override VisualElement CreateInspectorGUI() { @@ -215,15 +216,17 @@ void BindItem(VisualElement e, int i) { if (x.newValue) { - var textureChannels = new List(); + var textureChannels = avatarConfigTarget.TextureChannel.ToList(); textureChannels.Add((TextureChannel) i); avatarConfigTarget.TextureChannel = textureChannels.ToArray(); + textureChannelChanged?.Invoke(); } else { var textureChannels = avatarConfigTarget.TextureChannel.ToList(); textureChannels.Remove((TextureChannel) i); avatarConfigTarget.TextureChannel = textureChannels.ToArray(); + textureChannelChanged?.Invoke(); } Save(); }); @@ -247,25 +250,55 @@ private void SetupShader() var shaderPropertiesContainer = root.Q("ShaderProperties"); CreateShaderProperties(shaderPropertiesContainer); + + textureChannelChanged += () => ShowShaderProperties(shaderPropertiesContainer); if (shader.value == null) { shaderPropertiesContainer.style.display = DisplayStyle.None; } + else + { + ShowShaderProperties(shaderPropertiesContainer); + } shader.RegisterValueChangedCallback(x => { avatarConfigTarget.Shader = (Shader) x.newValue; Save(); - shaderPropertiesContainer.style.display = x.previousValue == null && x.newValue != null ? DisplayStyle.Flex : DisplayStyle.None; + if (x.newValue == null) + { + shaderPropertiesContainer.style.display = DisplayStyle.None; + } + else + { + ShowShaderProperties(shaderPropertiesContainer); + } } ); } + private void ShowShaderProperties(VisualElement shaderPropertiesContainer) + { + shaderPropertiesContainer.style.display = DisplayStyle.Flex; + foreach (var child in shaderPropertiesContainer.Children()) + { + if (avatarConfigTarget.TextureChannel.Contains((TextureChannel) Enum.Parse(typeof(TextureChannel), child.name))) + { + child.style.display = DisplayStyle.Flex; + } + else + { + child.style.display = DisplayStyle.None; + } + } + } + private void CreateShaderProperties(VisualElement shaderPropertiesContainer) { foreach (TextureChannel textureChannel in Enum.GetValues(typeof(TextureChannel))) { var field = new TextField(textureChannel.ToString()); + field.name = textureChannel.ToString(); var property = avatarConfigTarget.ShaderProperties.FindIndex(x => x.TextureChannel == textureChannel); field.SetValueWithoutNotify(avatarConfigTarget.ShaderProperties[property].PropertyName); field.RegisterValueChangedCallback(x =>