浏览代码

Outside node controls for vector types

/main
Peter Bay Bastian 7 年前
当前提交
ac179c90
共有 8 个文件被更改,包括 135 次插入0 次删除
  1. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs
  2. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector1MaterialSlot.cs
  3. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2MaterialSlot.cs
  4. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3MaterialSlot.cs
  5. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector4MaterialSlot.cs
  6. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  7. 76
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/MultiFloatSlotControlView.cs
  8. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/MultiFloatSlotControlView.cs.meta

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs


using System;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{

{
get { return m_Value; }
set { m_Value = value; }
}
public override VisualElement InstantiateControl()
{
int components =
concreteValueType == ConcreteSlotValueType.Vector4 ? 4 :
concreteValueType == ConcreteSlotValueType.Vector3 ? 3 :
concreteValueType == ConcreteSlotValueType.Vector2 ? 2 :
concreteValueType == ConcreteSlotValueType.Vector1 ? 1 : 0;
return new MultiFloatSlotControlView(owner, components, () => value, (newValue) => value = newValue);
}

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector1MaterialSlot.cs


using System;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{

{
get { return m_Value; }
set { m_Value = value; }
}
public override VisualElement InstantiateControl()
{
return new MultiFloatSlotControlView(owner, 1, () => new Vector4(value, 0f, 0f, 0f), (newValue) => value = newValue.x);
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2MaterialSlot.cs


using System;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{

{
get { return m_Value; }
set { m_Value = value; }
}
public override VisualElement InstantiateControl()
{
return new MultiFloatSlotControlView(owner, 2, () => value, (newValue) => value = newValue);
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3MaterialSlot.cs


using System;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{

{
get { return m_Value; }
set { m_Value = value; }
}
public override VisualElement InstantiateControl()
{
return new MultiFloatSlotControlView(owner, 3, () => value, (newValue) => value = newValue);
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector4MaterialSlot.cs


using System;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{

{
get { return m_Value; }
set { m_Value = value; }
}
public override VisualElement InstantiateControl()
{
return new MultiFloatSlotControlView(owner, 4, () => value, (newValue) => value = newValue);
}
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)

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


width: 100;
}
MultiFloatSlotControlView {
flex-direction: row;
align-items: center;
}
MultiFloatSlotControlView > Label {
margin-left: 0;
margin-right: 0;
}
MultiFloatSlotControlView > DoubleField {
width: 30;
margin-left: 0;
margin-right: 0;
}
.edge.fromMatrix4, .edge.fromMatrix3, .edge.fromMatrix2 {
edge-output-color: #8FC1DF;
}

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


using System;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Slots
{
public class MultiFloatSlotControlView : VisualElement
{
readonly INode m_Node;
readonly Func<Vector4> m_Get;
readonly Action<Vector4> m_Set;
int m_UndoGroup = -1;
public MultiFloatSlotControlView(INode node, int components, Func<Vector4> get, Action<Vector4> set)
{
m_Node = node;
m_Get = get;
m_Set = set;
var initialValue = get();
AddField(initialValue, 0, "X");
if (components > 1)
AddField(initialValue, 1, "Y");
if (components > 2)
AddField(initialValue, 2, "Z");
if (components > 3)
AddField(initialValue, 3, "W");
}
void AddField(Vector4 initialValue, int index, string subLabel)
{
Add(new Label(subLabel));
var doubleField = new DoubleField { userData = index, value = initialValue[index] };
doubleField.OnValueChanged(evt =>
{
var value = m_Get();
value[index] = (float)evt.newValue;
m_Set(value);
if (m_Node.onModified != null)
m_Node.onModified(m_Node, ModificationScope.Node);
m_UndoGroup = -1;
});
doubleField.RegisterCallback<InputEvent>(evt =>
{
if (m_UndoGroup == -1)
{
m_UndoGroup = Undo.GetCurrentGroup();
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
}
float newValue;
if (!float.TryParse(evt.newData, out newValue))
newValue = 0f;
var value = m_Get();
if (Math.Abs(value[index] - newValue) > 1e-9)
{
value[index] = newValue;
m_Set(value);
if (m_Node.onModified != null)
m_Node.onModified(m_Node, ModificationScope.Node);
}
});
doubleField.RegisterCallback<KeyDownEvent>(evt =>
{
if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1)
{
Undo.RevertAllDownToGroup(m_UndoGroup);
m_UndoGroup = -1;
evt.StopPropagation();
}
Dirty(ChangeType.Repaint);
});
Add(doubleField);
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/Slots/MultiFloatSlotControlView.cs.meta


fileFormatVersion: 2
guid: 6511e850402b445298bdb3256d9a131b
timeCreated: 1509721796
正在加载...
取消
保存