浏览代码

Update ToggleControl to UIElements

Cosmetic fixes to
- InvertColors node
- ChannelMixer node
- Blend node
/main
Matt Dean 7 年前
当前提交
7e22f269
共有 5 个文件被更改,包括 62 次插入29 次删除
  1. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/InvertColorsNode.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Blend/BlendNode.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelMixerControl.cs
  4. 49
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ToggleControl.cs
  5. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/InvertColorsNode.cs


[SerializeField]
private bool m_RedChannel;
[ToggleControl("Red")]
[ToggleControl("R")]
public Toggle redChannel
{
get { return new Toggle(m_RedChannel, channelCount > 0); }

[SerializeField]
private bool m_GreenChannel;
[ToggleControl("Green")]
[ToggleControl("G")]
public Toggle greenChannel
{
get { return new Toggle(m_GreenChannel, channelCount > 1); }

[SerializeField]
private bool m_BlueChannel;
[ToggleControl("Blue")]
[ToggleControl("B")]
public Toggle blueChannel
{
get { return new Toggle(m_BlueChannel, channelCount > 2); }

private bool m_AlphaChannel;
[ToggleControl("Alpha")]
[ToggleControl("A")]
public Toggle alphaChannel
{
get { return new Toggle(m_AlphaChannel, channelCount > 3); }

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Blend/BlendNode.cs


[SerializeField]
BlendMode m_BlendMode = BlendMode.Overlay;
[EnumControl("")]
[EnumControl("Mode")]
public BlendMode blendMode
{
get { return m_BlendMode; }

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelMixerControl.cs


float m_Maximum;
bool m_Initialized;
int m_UndoGroup = -1;
public ChannelMixerControlView(string label, float minimum, float maximum, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
m_Node = node;

49
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ToggleControl.cs


using System;
using System.Reflection;
using UnityEditor.Graphing;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEngine.Experimental.UIElements.StyleSheets;
using UnityEditor.ShaderGraph;
namespace UnityEditor.ShaderGraph.Drawing.Controls
{

GUIContent m_Label;
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
IMGUIContainer m_Container;
UnityEngine.Experimental.UIElements.Toggle m_Toggle;
public ToggleControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{

throw new ArgumentException("Property must be a Toggle.", "propertyInfo");
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
m_Container = new IMGUIContainer(OnGUIHandler);
Add(m_Container);
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
var value = (Toggle)m_PropertyInfo.GetValue(m_Node, null);
var panel = new VisualElement { name = "togglePanel" };
if (!string.IsNullOrEmpty(label))
panel.Add(new Label(label));
Action changedToggle = () => { OnChangeToggle(); };
m_Toggle = new UnityEngine.Experimental.UIElements.Toggle(changedToggle);
m_Toggle.SetEnabled(value.isEnabled);
panel.Add(m_Toggle);
Add(panel);
var value = (Toggle)m_PropertyInfo.GetValue(m_Node, null);
m_Toggle.SetEnabled(value.isEnabled);
m_Container.Dirty(ChangeType.Repaint);
{
Dirty(ChangeType.Repaint);
}
void OnGUIHandler()
void OnChangeToggle()
m_Node.owner.owner.RegisterCompleteObjectUndo("Toggle Change");
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
m_Container.SetEnabled(value.isEnabled);
bool isOn = EditorGUILayout.Toggle(m_Label, value.isOn);
value = new Toggle(isOn, value.isEnabled);
if (changeCheckScope.changed)
{
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
m_PropertyInfo.SetValue(m_Node, value, null);
}
}
value.isOn = !value.isOn;
m_PropertyInfo.SetValue(m_Node, value, null);
Dirty(ChangeType.Repaint);
}
}
}

30
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


ChannelMixerControlView > #buttonPanel {
flex-direction: row;
flex-grow: 1;
margin-bottom: 6;
margin-left: 2;
margin-right: 2;
margin-left: 0;
margin-right: 0;
align-items: center;
}

margin-right: 2;
min-width: 30;
max-width: 30;
}
ToggleControlView > #togglePanel {
flex-direction: row;
flex-grow: 1;
}
ToggleControlView > #togglePanel > Label {
flex-grow: 1;
padding-left: 0;
padding-right: 0;
padding-top: 0;
padding-bottom: 0;
margin-left: 8;
margin-right: 8;
margin-top: 4;
margin-bottom: 4;
}
ToggleControlView > #togglePanel > Toggle {
margin-left: 8;
margin-right: 8;
margin-top: 4;
margin-bottom: 4;
align-self: center;
}
ObjectControlView {

正在加载...
取消
保存