浏览代码

First pass inlining property nodes.

/main
Tim Cooper 7 年前
当前提交
8e5b0d9b
共有 9 个文件被更改,包括 85 次插入9 次删除
  1. 1
      MaterialGraphProject/Assets/NewNodes/Editor/Keep/TransformNode.cs
  2. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  3. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/AbstractLightweightMasterNode.cs
  4. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/ColorNode.cs
  5. 61
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs
  6. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs
  7. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs
  8. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs
  9. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs

1
MaterialGraphProject/Assets/NewNodes/Editor/Keep/TransformNode.cs


using UnityEditor.Graphing;
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


public void RemoveShaderProperty(Guid guid)
{
var propertyNodes = GetNodes<PropertyNode>().Where(x => x.propertyGuid == guid).ToArray();
foreach (var pNode in propertyNodes)
pNode.ReplaceWithConcreteNode();
if (m_Properties.RemoveAll(x => x.guid == guid) > 0)
m_RemovedProperties.Add(guid);
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/AbstractLightweightMasterNode.cs


foreach (var activeNode in nodes.OfType<AbstractMaterialNode>())
{
if (activeNode is IGeneratesBodyCode)
(activeNode as IGeneratesBodyCode).GenerateNodeCode(surfaceOutputRemap,
GenerationMode.ForReals);
(activeNode as IGeneratesBodyCode).GenerateNodeCode(surfaceOutputRemap, GenerationMode.ForReals);
}
foreach (var input in GetInputSlots<MaterialSlot>())

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/ColorNode.cs


[SerializeField]
private Color m_Color;
private const int kOutputSlotId = 0;
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Color";
public ColorNode()

public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[ColorControl("")]

61
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs


{
UpdateNode();
}
public void ReplaceWithConcreteNode()
{
var matGraph = owner as MaterialGraph;
if (matGraph == null)
return;
var property = matGraph.properties.FirstOrDefault(x => x.guid == propertyGuid);
if (property != null)
{
AbstractMaterialNode node = null;
int slotId = -1;
if (property is FloatShaderProperty)
{
var createdNode = new Vector1Node();
createdNode.value = ((FloatShaderProperty) property).value;
slotId = Vector1Node.OutputSlotId;
node = createdNode;
}
else if (property is Vector2ShaderProperty)
{
var createdNode = new Vector2Node();
createdNode.value = ((Vector2ShaderProperty) property).value;
slotId = Vector2Node.OutputSlotId;
node = createdNode;
}
else if (property is Vector3ShaderProperty)
{
var createdNode = new Vector3Node();
createdNode.value = ((Vector3ShaderProperty) property).value;
slotId = Vector3Node.OutputSlotId;
node = createdNode;
}
else if (property is Vector4ShaderProperty)
{
var createdNode = new Vector4Node();
createdNode.value = ((Vector4ShaderProperty) property).value;
slotId = Vector4Node.OutputSlotId;
node = createdNode;
}
else if (property is ColorShaderProperty)
{
var createdNode = new ColorNode();
createdNode.color = ((ColorShaderProperty) property).value;
slotId = ColorNode.OutputSlotId;
node = createdNode;
}
if (node == null)
return;
var slot = FindOutputSlot<MaterialSlot>(OutputSlotId);
node.drawState = drawState;
owner.AddNode(node);
foreach (var edge in owner.GetEdges(slot.slotReference).ToArray())
owner.Connect(node.GetSlotReference(slotId), edge.inputSlot);
owner.RemoveNode(this);
}
}
}
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs


using System.Reflection;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEditor.ShaderGraph;
using Object = UnityEngine.Object;
namespace UnityEditor.ShaderGraph.Drawing.Controls

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/EnumControl.cs


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

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs


using UnityEngine.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
using UnityEngine;
namespace UnityEditor.ShaderGraph.Drawing.Inspector

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs


ToolbarButtonView m_TimeButton;
ToolbarButtonView m_CopyToClipboardButton;
ToolbarButtonView m_InlineSelectedProperties;
PreviewManager m_PreviewManager;
public Action onUpdateAssetClick { get; set; }

}
));
m_InlineSelectedProperties = new ToolbarButtonView() { text = "Inline Property Node" };
m_InlineSelectedProperties.AddManipulator(new Clickable(() =>
{
var slected = graphView.selection.OfType<MaterialNodeView>()
.Select(x => x.node)
.OfType<PropertyNode>();
foreach (var propNode in slected)
propNode.ReplaceWithConcreteNode();
}
));
m_ToolbarView.Add(m_InlineSelectedProperties);
m_ToolbarView.Add(new ToolbarSeparatorView());
}

正在加载...
取消
保存