浏览代码

Refactor Channel Mixer UI

/main
Matt Dean 7 年前
当前提交
fb18c249
共有 2 个文件被更改,包括 179 次插入9 次删除
  1. 127
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ChannelMixerControl.cs
  2. 61
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss

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


Slider m_GreenSlider;
Slider m_BlueSlider;
FloatField m_RedInputField;
FloatField m_GreenInputField;
FloatField m_BlueInputField;
int m_UndoGroup = -1;
public ChannelMixerControlView(string label, float minimum, float maximum, AbstractMaterialNode node, PropertyInfo propertyInfo)
{

if (!string.IsNullOrEmpty(label))
Add(new Label(label));
var buttonPanel = new VisualElement { name = "buttonPanel" };
Add(outputButtonRed);
outputButtonRed.Add(new Label("R"));
buttonPanel.Add(outputButtonRed);
Add(outputButtonGreen);
outputButtonGreen.Add(new Label("G"));
buttonPanel.Add(outputButtonGreen);
Add(outputButtonBlue);
outputButtonBlue.Add(new Label("B"));
buttonPanel.Add(outputButtonBlue);
Add(new Label("Red"));
Add(buttonPanel);
var redSliderPanel = new VisualElement { name = "sliderPanel" };
redSliderPanel.Add(new Label("R"));
Add(m_RedSlider);
redSliderPanel.Add(m_RedSlider);
m_RedInputField = new FloatField { value = m_ChannelMixer.outRed.x };
m_RedInputField.OnValueChanged(OnChangeRedInputField);
redSliderPanel.Add(m_RedInputField);
Add(redSliderPanel);
Add(new Label("Green"));
var greenSliderPanel = new VisualElement { name = "sliderPanel" };
greenSliderPanel.Add(new Label("G"));
Add(m_GreenSlider);
greenSliderPanel.Add(m_GreenSlider);
m_GreenInputField = new FloatField { value = m_ChannelMixer.outRed.y };
m_GreenInputField.OnValueChanged(OnChangeGreenInputField);
greenSliderPanel.Add(m_GreenInputField);
Add(greenSliderPanel);
Add(new Label("Blue"));
var blueSliderPanel = new VisualElement { name = "sliderPanel" };
blueSliderPanel.Add(new Label("B"));
Add(m_BlueSlider);
blueSliderPanel.Add(m_BlueSlider);
m_BlueInputField = new FloatField { value = m_ChannelMixer.outRed.z };
m_BlueInputField.OnValueChanged(OnChangeBlueInputField);
blueSliderPanel.Add(m_BlueInputField);
Add(blueSliderPanel);
m_Initialized = true;
ResetSliders();

m_ChannelMixer.outRed[inChannel] = value;
break;
}
switch(inChannel)
{
case 1:
m_GreenInputField.value = value;
break;
case 2:
m_BlueInputField.value = value;
break;
default:
m_RedInputField.value = value;
break;
}
}
void OnChangeRedInputField(ChangeEvent<double> evt)
{
if (!m_Initialized)
return;
var value = Mathf.Max(Mathf.Min((float)evt.newValue, m_Maximum), m_Minimum);
m_Node.owner.owner.RegisterCompleteObjectUndo("Input Field Change");
switch (m_OutChannel)
{
case 1:
m_ChannelMixer.outGreen[0] = value;
break;
case 2:
m_ChannelMixer.outBlue[0] = value;
break;
default:
m_ChannelMixer.outRed[0] = value;
break;
}
m_RedSlider.value = value;
m_PropertyInfo.SetValue(m_Node, m_ChannelMixer, null);
Dirty(ChangeType.Repaint);
}
void OnChangeGreenInputField(ChangeEvent<double> evt)
{
if (!m_Initialized)
return;
var value = Mathf.Max(Mathf.Min((float)evt.newValue, m_Maximum), m_Minimum);
m_Node.owner.owner.RegisterCompleteObjectUndo("Input Field Change");
switch (m_OutChannel)
{
case 1:
m_ChannelMixer.outGreen[1] = value;
break;
case 2:
m_ChannelMixer.outBlue[1] = value;
break;
default:
m_ChannelMixer.outRed[1] = value;
break;
}
m_GreenSlider.value = value;
m_PropertyInfo.SetValue(m_Node, m_ChannelMixer, null);
Dirty(ChangeType.Repaint);
}
void OnChangeBlueInputField(ChangeEvent<double> evt)
{
if (!m_Initialized)
return;
var value = Mathf.Max(Mathf.Min((float)evt.newValue, m_Maximum), m_Minimum);
m_Node.owner.owner.RegisterCompleteObjectUndo("Input Field Change");
switch (m_OutChannel)
{
case 1:
m_ChannelMixer.outGreen[2] = value;
break;
case 2:
m_ChannelMixer.outBlue[2] = value;
break;
default:
m_ChannelMixer.outRed[2] = value;
break;
}
m_BlueSlider.value = value;
m_PropertyInfo.SetValue(m_Node, m_ChannelMixer, null);
Dirty(ChangeType.Repaint);
}
void OnClickButton(int outChannel)

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


flex-grow: 1;
}
ChannelMixerControlView {
padding-left: 8;
padding-right: 8;
padding-top: 4;
padding-bottom: 4;
}
ChannelMixerControlView > Label {
margin-left: 0;
margin-right: 0;
cursor: slide-arrow;
}
ChannelMixerControlView > #buttonPanel {
flex-direction: row;
flex-grow: 1;
}
ChannelMixerControlView > #buttonPanel > Button {
flex-grow: 1;
margin-left: 2;
margin-right: 2;
align-items: center;
}
ChannelMixerControlView > #buttonPanel > Button > Label {
flex-grow: 1;
margin-left: 0;
margin-right: 0;
margin-top: 0;
margin-bottom: 0;
padding-left: 0;
padding-right: 0;
padding-top: 0;
padding-bottom: 0;
}
ChannelMixerControlView > #sliderPanel {
flex-direction: row;
flex-grow: 1;
}
ChannelMixerControlView > #sliderPanel > Label {
margin-left: 0;
margin-right: 0;
min-width: 20;
}
ChannelMixerControlView > #sliderPanel > Slider {
flex-grow: 1;
margin-left: 0;
margin-right: 0;
}
ChannelMixerControlView > #sliderPanel > FloatField {
margin-left: 4;
margin-right: 2;
min-width: 30;
max-width: 30;
}
ObjectControlView {
flex-direction: row;
}

正在加载...
取消
保存