浏览代码

Workarounds for float formatting (e.g. 0.6 becoming a mess of decimal points) and label draggers (dragging not working on anything but first label on slot control)

/main
Peter Bay Bastian 7 年前
当前提交
508ec3ef
共有 5 个文件被更改,包括 64 次插入20 次删除
  1. 20
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/VectorControl.cs
  2. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/MultiFloatSlotControlView.cs
  3. 33
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  4. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/FloatField.cs
  5. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/FloatField.cs.meta

20
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/VectorControl.cs


void AddField(int index, string subLabel)
{
var dummy = new VisualElement { name = "dummy" };
Add(label);
var doubleField = new DoubleField { userData = index, value = m_Value[index] };
var dragger = new FieldMouseDragger<double>(doubleField);
dummy.Add(label);
Add(dummy);
var field = new FloatField { userData = index, value = m_Value[index] };
var dragger = new FieldMouseDragger<double>(field);
doubleField.RegisterCallback<MouseDownEvent>(Repaint);
doubleField.RegisterCallback<MouseMoveEvent>(Repaint);
doubleField.OnValueChanged(evt =>
field.RegisterCallback<MouseDownEvent>(Repaint);
field.RegisterCallback<MouseMoveEvent>(Repaint);
field.OnValueChanged(evt =>
{
var value = GetValue();
value[index] = (float)evt.newValue;

});
doubleField.RegisterCallback<InputEvent>(evt =>
field.RegisterCallback<InputEvent>(evt =>
{
if (m_UndoGroup == -1)
{

SetValue(value);
Dirty(ChangeType.Repaint);
});
doubleField.RegisterCallback<KeyDownEvent>(evt =>
field.RegisterCallback<KeyDownEvent>(evt =>
{
if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1)
{

}
Dirty(ChangeType.Repaint);
});
Add(doubleField);
Add(field);
}
object ValueToPropertyType(Vector4 value)

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/MultiFloatSlotControlView.cs


void AddField(Vector4 initialValue, int index, string subLabel)
{
var dummy = new VisualElement { name = "dummy" };
Add(label);
var doubleField = new DoubleField { userData = index, value = initialValue[index] };
var dragger = new FieldMouseDragger<double>(doubleField);
dummy.Add(label);
Add(dummy);
var field = new FloatField { userData = index, value = initialValue[index] };
var dragger = new FieldMouseDragger<double>(field);
doubleField.OnValueChanged(evt =>
field.OnValueChanged(evt =>
{
var value = m_Get();
value[index] = (float)evt.newValue;

m_UndoGroup = -1;
});
doubleField.RegisterCallback<InputEvent>(evt =>
field.RegisterCallback<InputEvent>(evt =>
{
if (m_UndoGroup == -1)
{

m_Node.onModified(m_Node, ModificationScope.Node);
}
});
doubleField.RegisterCallback<KeyDownEvent>(evt =>
field.RegisterCallback<KeyDownEvent>(evt =>
{
if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1)
{

}
Dirty(ChangeType.Repaint);
});
Add(doubleField);
Add(field);
}
}
}

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


align-items: center;
}
MultiFloatSlotControlView > Label {
MultiFloatSlotControlView > #dummy > Label {
MultiFloatSlotControlView > DoubleField {
MultiFloatSlotControlView > FloatField {
width: 30;
margin-left: 0;
margin-right: 0;

padding-bottom: 8;
}
MultiFloatControlView > Label {
MultiFloatControlView > #dummy > Label {
MultiFloatControlView > DoubleField {
MultiFloatControlView > FloatField {
margin-left: 0;
margin-right: 0;
min-width: 30;

padding-top: 8;
padding-bottom: 8;
}
FloatField {
min-height: 15;
margin-left: 4;
margin-top: 2;
margin-right: 4;
margin-bottom: 2;
padding-left: 3;
padding-top: 1;
padding-right: 3;
padding-bottom: 2;
slice-left: 3;
slice-top: 3;
slice-right: 3;
slice-bottom: 3;
selection-color: rgba(61,128,223,166);
cursor: text;
text-color: #B4B4B4;
background-image: resource("Builtin Skins/DarkSkin/Images/TextField.png");
cursor-color:#B4B4B4;
}
FloatField:focus {
background-image: resource("Builtin Skins/DarkSkin/Images/TextField focused.png");
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/FloatField.cs


using UnityEditor.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing
{
public class FloatField : DoubleField
{
protected override string ValueToString(double v)
{
return ((float)v).ToString();
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/FloatField.cs.meta


fileFormatVersion: 2
guid: f1ab7cad0fa94639990c801ecf80bff2
timeCreated: 1512568655
正在加载...
取消
保存