浏览代码

[Material Graph]Refactoring drawing. Working general drawing.

/main
Tim Cooper 8 年前
当前提交
1b5c5494
共有 91 个文件被更改,包括 3105 次插入707 次删除
  1. 1
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/INode.cs
  2. 25
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Tests/SerializedGraphTests.cs
  3. 9
      UnityProject/Assets/UnityShaderEditor/Editor/Nodes/AbstractMaterialNode.cs
  4. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Nodes/AddNode.cs
  5. 13
      UnityProject/Assets/UnityShaderEditor/Editor/Nodes/Function2Input.cs
  6. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Nodes/MaterialSlot.cs
  7. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Nodes/PixelShaderNode.cs
  8. 3
      UnityProject/Assets/UnityShaderEditor/Editor/Nodes/PropertyNode.cs
  9. 22
      UnityProject/Assets/UnityShaderEditor/Editor/Nodes/Vector4Node.cs
  10. 3
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/Edge.cs
  11. 9
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableNode.cs
  12. 2
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MyNodeAdapters.cs
  13. 18
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeAnchor.cs
  14. 2
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DeleteSelected.cs
  15. 9
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor.meta
  16. 9
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Assets.meta
  17. 9
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing.meta
  18. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/GUIModificationType.cs.meta
  19. 9
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation.meta
  20. 9
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces.meta
  21. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/IEdge.cs.meta
  22. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/IGraph.cs.meta
  23. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/INode.cs.meta
  24. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/ISlot.cs.meta
  25. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/SlotReference.cs.meta
  26. 9
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Tests.meta
  27. 9
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Util.meta
  28. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Util/Logging.cs.meta
  29. 12
      UnityProject/Assets/UnityShaderEditor/Editor/AbstractMaterialGraph.cs.meta
  30. 9
      UnityProject/Assets/UnityShaderEditor/Editor/AssetCallbacks.meta
  31. 9
      UnityProject/Assets/UnityShaderEditor/Editor/Drawing.meta
  32. 9
      UnityProject/Assets/UnityShaderEditor/Editor/Editors.meta
  33. 9
      UnityProject/Assets/UnityShaderEditor/Editor/Interfaces.meta
  34. 9
      UnityProject/Assets/UnityShaderEditor/Editor/Light.meta
  35. 12
      UnityProject/Assets/UnityShaderEditor/Editor/MaterialGraph.cs.meta
  36. 12
      UnityProject/Assets/UnityShaderEditor/Editor/MaterialGraphAsset.cs.meta
  37. 12
      UnityProject/Assets/UnityShaderEditor/Editor/MaterialOptions.cs.meta
  38. 9
      UnityProject/Assets/UnityShaderEditor/Editor/Nodes.meta
  39. 12
      UnityProject/Assets/UnityShaderEditor/Editor/PixelGraph.cs.meta
  40. 12
      UnityProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/AbstractMaterialGraphTests.cs.meta
  41. 12
      UnityProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialGraphTests.cs.meta
  42. 12
      UnityProject/Assets/UnityShaderEditor/Editor/TitleAttribute.cs.meta
  43. 9
      UnityProject/Assets/UnityShaderEditor/Editor/Util.meta
  44. 1001
      UnityProject/Assets/UnityShaderEditor/Graphs/TestGraph.ShaderGraph
  45. 8
      UnityProject/Assets/UnityShaderEditor/Graphs/TestGraph.ShaderGraph.meta
  46. 1001
      UnityProject/Assets/UnityShaderEditor/Graphs/stine.ShaderGraph
  47. 8
      UnityProject/Assets/UnityShaderEditor/Graphs/stine.ShaderGraph.meta
  48. 35
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Assets/SerializableGraphAsset.cs
  49. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Assets/SerializableGraphAsset.cs.meta
  50. 152
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs
  51. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs.meta
  52. 159
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs
  53. 190
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs
  54. 68
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NullInputProxy.cs
  55. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/Edge.cs.meta
  56. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/NodeUtils.cs.meta
  57. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableGraph.cs.meta
  58. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableNode.cs.meta
  59. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableSlot.cs.meta
  60. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SlotType.cs.meta
  61. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/Edge.cs.meta
  62. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/GUIModificationType.cs.meta
  63. 8
      UnityProject/Assets/GraphFramework/SerializableGraph/NodeUtils.cs.meta
  64. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/SerializableGraph.cs.meta
  65. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/SerializableNode.cs.meta
  66. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/SerializableSlot.cs.meta
  67. 12
      UnityProject/Assets/GraphFramework/SerializableGraph/SlotReference.cs.meta
  68. 12
      UnityProject/Assets/UnityShaderEditor/Editor/Drawing/DrawableMaterialNode.cs.meta
  69. 196
      UnityProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialWindow.cs
  70. 66
      UnityProject/Assets/UnityShaderEditor/Editor/Drawing/NullInputProxy.cs
  71. 152
      UnityProject/Assets/UnityShaderEditor/Editor/Drawing/DrawableMaterialNode.cs
  72. 165
      UnityProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphDataSource.cs
  73. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/Edge.cs
  74. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/NodeUtils.cs
  75. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableGraph.cs
  76. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableNode.cs
  77. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableSlot.cs
  78. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/SlotReference.cs
  79. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SlotType.cs
  80. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs.meta
  81. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs.meta
  82. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MyNodeAdapters.cs
  83. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MyNodeAdapters.cs.meta
  84. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeAnchor.cs
  85. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeAnchor.cs.meta
  86. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DeleteSelected.cs
  87. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DeleteSelected.cs.meta
  88. 0
      /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NullInputProxy.cs.meta

1
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/INode.cs


ISlot FindSlot(string name);
ISlot FindInputSlot(string name);
ISlot FindOutputSlot(string name);
IEnumerable<ISlot> GetInputsWithNoConnection();
}
}

25
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Tests/SerializedGraphTests.cs


Assert.AreEqual(2, graph.nodes.Count());
graph.Connect(outputNode.GetSlotReference("output"), inputNode.GetSlotReference("input"));
Assert.AreEqual(1, graph.edges.Count());
}
[Test]
public void TestGetInputsWithNoConnection()
{
var graph = new SerializableGraph();
var outputNode = new SerializableNode(graph);
outputNode.AddSlot(new SerializableSlot("output", "output", SlotType.Output));
graph.AddNode(outputNode);
var inputNode = new SerializableNode(graph);
inputNode.AddSlot(new SerializableSlot("input", "input", SlotType.Input));
inputNode.AddSlot(new SerializableSlot("input2", "input2", SlotType.Input));
inputNode.AddSlot(new SerializableSlot("output", "output", SlotType.Output));
graph.AddNode(inputNode);
Assert.AreEqual(2, graph.nodes.Count());
graph.Connect(outputNode.GetSlotReference("output"), inputNode.GetSlotReference("input"));
Assert.AreEqual(1, graph.edges.Count());
var slots = inputNode.GetInputsWithNoConnection();
Assert.AreEqual(1, slots.Count());
Assert.AreEqual("input2", slots.FirstOrDefault().name);
}
}
}

9
UnityProject/Assets/UnityShaderEditor/Editor/Nodes/AbstractMaterialNode.cs


get { return outputSlots.OfType<MaterialSlot>(); }
}
protected AbstractMaterialNode(AbstractMaterialGraph theOwner) : base(theOwner)
protected AbstractMaterialNode(IGraph theOwner) : base(theOwner)
{ }
public virtual void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)

return inputSlot.OnGUI(rect, inputSlotType);
}
public virtual IEnumerable<MaterialSlot> GetInputsWithNoConnection()
{
return materialInputSlots.Where(x => !owner.GetEdges(GetSlotReference(x.name)).Any());
}
public void ExecuteRepaint()
{
if (onNeedsRepaint != null)

protected bool InternalUpdatePreviewShader(string resultShader)
{
MaterialWindow.DebugMaterialGraph("RecreateShaderAndMaterial : " + name + "_" + guid.ToString().Replace("-","_") + "\n" + resultShader);
Debug.Log("RecreateShaderAndMaterial : " + name + "_" + guid.ToString().Replace("-","_") + "\n" + resultShader);
// workaround for some internal shader compiler weirdness
// if we are in error we sometimes to not properly clean

4
UnityProject/Assets/UnityShaderEditor/Editor/Nodes/AddNode.cs


using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.MaterialGraph
{

public AddNode(AbstractMaterialGraph owner)
public AddNode(IGraph owner)
: base(owner)
{
name = "AddNode";

13
UnityProject/Assets/UnityShaderEditor/Editor/Nodes/Function2Input.cs


get { return true; }
}
protected Function2Input(AbstractMaterialGraph owner)
protected Function2Input(IGraph owner)
{
UpdateSlots();
}
private void UpdateSlots()
{
AddSlot(GetInputSlot1());
AddSlot(GetInputSlot2());

public string input2Dimension
{
get { return ConvertConcreteSlotValueTypeToString(FindMaterialInputSlot(GetInputSlot2Name()).concreteValueType); }
}
public override void OnAfterDeserialize()
{
base.OnAfterDeserialize();
UpdateSlots();
}
}
}

2
UnityProject/Assets/UnityShaderEditor/Editor/Nodes/MaterialSlot.cs


[SerializeField]
private ConcreteSlotValueType m_ConcreteValueType;
public MaterialSlot() { }
public MaterialSlot(string name, string displayName, SlotType slotType, SlotValueType valueType, Vector4 defaultValue)
: base(name, displayName, slotType)
{

4
UnityProject/Assets/UnityShaderEditor/Editor/Nodes/PixelShaderNode.cs


return GUIModificationType.None;
}
public override IEnumerable<MaterialSlot> GetInputsWithNoConnection()
public override IEnumerable<ISlot> GetInputsWithNoConnection()
return new List<MaterialSlot>();
return new List<ISlot>();
}
public override bool hasPreview

3
UnityProject/Assets/UnityShaderEditor/Editor/Nodes/PropertyNode.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.MaterialGraph

[SerializeField]
public bool m_Exposed;
public PropertyNode(AbstractMaterialGraph owner) : base(owner)
public PropertyNode(IGraph owner) : base(owner)
{}
public bool exposed

22
UnityProject/Assets/UnityShaderEditor/Editor/Nodes/Vector4Node.cs


[SerializeField]
public Vector4 m_Value;
private void InternalValidate()
{
AddSlot(new MaterialSlot(kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
}
public Vector4Node(AbstractMaterialGraph owner) : base(owner)
public Vector4Node(IGraph owner) : base(owner)
InternalValidate();
UpdateSlots();
private void UpdateSlots()
{
AddSlot(new MaterialSlot(kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
}
public override PropertyType propertyType
{
get { return PropertyType.Vector4; }

m_PropType = PropertyType.Vector4,
m_Vector4 = m_Value
};
}
public override void OnAfterDeserialize()
{
base.OnAfterDeserialize();
UpdateSlots();
}
}
}

3
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/Edge.cs


[SerializeField]
private SlotReference m_InputSlot;
public Edge()
{}
public Edge(SlotReference outputSlot, SlotReference inputSlot)
{
m_OutputSlot = outputSlot;

9
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableNode.cs


get { return m_Slots; }
}
public SerializableNode(SerializableGraph theOwner)
public SerializableNode(IGraph theOwner)
{
owner = theOwner;
m_Guid = Guid.NewGuid();

else
m_Guid = Guid.NewGuid();
m_Slots = SerializationHelper.Deserialize<ISlot>(m_SerializableSlots, new object[] { this });
m_Slots = SerializationHelper.Deserialize<ISlot>(m_SerializableSlots, new object[] {});
}
public virtual IEnumerable<ISlot> GetInputsWithNoConnection()
{
return inputSlots.Where(x => !owner.GetEdges(GetSlotReference(x.name)).Any());
}
}
}

2
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MyNodeAdapters.cs


using UnityEditor.Experimental.Graph;
using UnityEngine;
namespace UnityEditor.MaterialGraph
namespace UnityEditor.Graphing.Drawing
{
internal class PortSource<T>
{

18
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeAnchor.cs


using UnityEditor.Experimental.Graph;
using UnityEngine;
namespace UnityEditor.MaterialGraph
namespace UnityEditor.Graphing.Drawing
{
public class NodeAnchor : CanvasElement, IConnect
{

private MaterialGraphDataSource m_Data;
public MaterialSlot m_Slot;
public AbstractMaterialNode m_Node;
private GraphDataSource m_Data;
public ISlot m_Slot;
public INode m_Node;
public NodeAnchor(Vector3 position, Type type, AbstractMaterialNode node, MaterialSlot slot, MaterialGraphDataSource data, Direction direction)
public NodeAnchor(Vector3 position, Type type, INode node, ISlot slot, GraphDataSource data, Direction direction)
{
m_Type = type;
scale = new Vector3(15.0f, 15.0f, 1.0f);

return Orientation.Horizontal;
}
private static string ConcreteSlotValueTypeAsString(ConcreteSlotValueType type)
/* private static string ConcreteSlotValueTypeAsString(ConcreteSlotValueType type)
{
switch (type)
{

return "(E)";
}
}
}*/
public override void Render(Rect parentRect, Canvas2D canvas)
{

EditorGUI.DrawRect(new Rect(translation.x, translation.y, scale.x, scale.y), anchorColor);
string text = m_Slot.name;
string text = m_Slot.displayName;
text += " " + ConcreteSlotValueTypeAsString(m_Slot.concreteValueType);
text += " " + ConcreteSlotValueTypeAsString(m_Slot.concreteValueType);
Vector2 sizeOfText = GUIStyle.none.CalcSize(new GUIContent(text));
labelRect = new Rect(translation.x - sizeOfText.x - 4.0f, translation.y, sizeOfText.x + 4.0f, sizeOfText.y + 4.0f);
}

2
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DeleteSelected.cs


using UnityEditor.Experimental;
using UnityEngine;
namespace UnityEditor.MaterialGraph
namespace UnityEditor.Graphing.Drawing
{
internal class DeleteSelected : IManipulate
{

9
UnityProject/Assets/GraphFramework/SerializableGraph/Editor.meta


fileFormatVersion: 2
guid: 93c541dd957a2ac40870d0b23d2dc115
folderAsset: yes
timeCreated: 1464264920
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Assets.meta


fileFormatVersion: 2
guid: fbce0c0b81b61ca4cb27684a4abb3fd1
folderAsset: yes
timeCreated: 1464265232
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing.meta


fileFormatVersion: 2
guid: 1dc52c222e72d364ba1f1ce5d428d645
folderAsset: yes
timeCreated: 1464264920
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/GUIModificationType.cs.meta


fileFormatVersion: 2
guid: eda3c0504bf73e244befc23f40505007
timeCreated: 1464264926
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation.meta


fileFormatVersion: 2
guid: 931ad3a4d181270419aa65ff77b3ec16
folderAsset: yes
timeCreated: 1464264924
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces.meta


fileFormatVersion: 2
guid: 5b6c961691e6a7a46b9366ca4fa781ac
folderAsset: yes
timeCreated: 1464264924
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/IEdge.cs.meta


fileFormatVersion: 2
guid: 2f67813c9628ef14a839d0c546f6ab25
timeCreated: 1464264924
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/IGraph.cs.meta


fileFormatVersion: 2
guid: ad5e6e2ab1165fb46bfc2296913d25a2
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/INode.cs.meta


fileFormatVersion: 2
guid: b16d3bd20d4d2c644969258425ff071a
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/ISlot.cs.meta


fileFormatVersion: 2
guid: c273d08d1dec8434583305f6cff41a08
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/SlotReference.cs.meta


fileFormatVersion: 2
guid: a7b6f306850f6cc449bc71d8d2384146
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Tests.meta


fileFormatVersion: 2
guid: ad1c022ae8278c34ba435f1ef3928952
folderAsset: yes
timeCreated: 1464264921
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Util.meta


fileFormatVersion: 2
guid: e45006b8ac3b76f4aa0df05ea8514cbe
folderAsset: yes
timeCreated: 1464264920
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Util/Logging.cs.meta


fileFormatVersion: 2
guid: ffca76f71e6326344ad2ff5e823d02f9
timeCreated: 1464264926
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/UnityShaderEditor/Editor/AbstractMaterialGraph.cs.meta


fileFormatVersion: 2
guid: 92dd684b5c787db4f9b11cec99be5d92
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/UnityShaderEditor/Editor/AssetCallbacks.meta


fileFormatVersion: 2
guid: 4d0b60652dca71b49a137663137e38ea
folderAsset: yes
timeCreated: 1464264920
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/UnityShaderEditor/Editor/Drawing.meta


fileFormatVersion: 2
guid: 628a36608983fbe49bd5b01cc799f525
folderAsset: yes
timeCreated: 1464264920
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/UnityShaderEditor/Editor/Editors.meta


fileFormatVersion: 2
guid: 9847d86c4f5011c4284af07e94be19d0
folderAsset: yes
timeCreated: 1464264921
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/UnityShaderEditor/Editor/Interfaces.meta


fileFormatVersion: 2
guid: fa6cfee2afcf9584b9e67fe405662d0e
folderAsset: yes
timeCreated: 1464264921
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/UnityShaderEditor/Editor/Light.meta


fileFormatVersion: 2
guid: 9558d2a8413064e40b02dc7e71a6925f
folderAsset: yes
timeCreated: 1464264921
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/UnityShaderEditor/Editor/MaterialGraph.cs.meta


fileFormatVersion: 2
guid: 2400e28d912db104797e8def686c6cdc
timeCreated: 1464264924
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/UnityShaderEditor/Editor/MaterialGraphAsset.cs.meta


fileFormatVersion: 2
guid: 61bd7d04bf730474f9d9a0a32ef12cf4
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/UnityShaderEditor/Editor/MaterialOptions.cs.meta


fileFormatVersion: 2
guid: 8f38eea901fa63d418361da2427f7699
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/UnityShaderEditor/Editor/Nodes.meta


fileFormatVersion: 2
guid: 0082d52fe349b94449238a3d0db01df0
folderAsset: yes
timeCreated: 1464264919
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/UnityShaderEditor/Editor/PixelGraph.cs.meta


fileFormatVersion: 2
guid: ef84063adc43c204cb779ca0d9e31d4e
timeCreated: 1464264926
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/AbstractMaterialGraphTests.cs.meta


fileFormatVersion: 2
guid: 351a6b3ff7ef41c45938a78e94dd2a20
timeCreated: 1464264924
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialGraphTests.cs.meta


fileFormatVersion: 2
guid: 0675182a7c3e7464e977d09524877e2c
timeCreated: 1464264924
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/UnityShaderEditor/Editor/TitleAttribute.cs.meta


fileFormatVersion: 2
guid: 5db8bb6be10ebf244acdc1faa2585ef2
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
UnityProject/Assets/UnityShaderEditor/Editor/Util.meta


fileFormatVersion: 2
guid: 32e29ba6d98ba0140a774b7804b02a28
folderAsset: yes
timeCreated: 1464264921
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

1001
UnityProject/Assets/UnityShaderEditor/Graphs/TestGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件

8
UnityProject/Assets/UnityShaderEditor/Graphs/TestGraph.ShaderGraph.meta


fileFormatVersion: 2
guid: 0c9dcadb1b558ae42a80c642bbd7add7
timeCreated: 1454679931
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

1001
UnityProject/Assets/UnityShaderEditor/Graphs/stine.ShaderGraph
文件差异内容过多而无法显示
查看文件

8
UnityProject/Assets/UnityShaderEditor/Graphs/stine.ShaderGraph.meta


fileFormatVersion: 2
guid: 754ba2dfba8dd3e40a130b6ecd09ec6b
timeCreated: 1455192604
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

35
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Assets/SerializableGraphAsset.cs


using System.IO;
using UnityEditor.Graphing;
using UnityEditor.ProjectWindowCallback;
using UnityEngine;
namespace UnityEditor.MaterialGraph
{
public class CreateSerializableGraph : EndNameEditAction
{
[MenuItem("Assets/Create/Serializable Graph", false, 207)]
public static void CreateMaterialGraph()
{
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateSerializableGraph>(),
"New Shader Graph.ShaderGraph", null, null);
}
public override void Action(int instanceId, string pathName, string resourceFile)
{
var graph = CreateInstance<SerializableGraphAsset>();
graph.name = Path.GetFileName(pathName);
AssetDatabase.CreateAsset(graph, pathName);
}
}
public class SerializableGraphAsset : ScriptableObject
{
[SerializeField]
private SerializableGraph m_Graph;
public SerializableGraph graph
{
get { return m_Graph; }
}
}
}

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Assets/SerializableGraphAsset.cs.meta


fileFormatVersion: 2
guid: d730ce8d1849fef439b593190f45eaec
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

152
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs


using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
using UnityEngine;
namespace UnityEditor.Graphing.Drawing
{
public sealed class DrawableNode : CanvasElement
{
private readonly GraphDataSource m_Data;
public INode m_Node;
private Rect m_PreviewArea;
private Rect m_NodeUIRect;
public DrawableNode(INode node, float width, GraphDataSource data)
{
translation = node.position.min;
scale = new Vector2(width, width);
m_Node = node;
m_Data = data;
//m_Node.onNeedsRepaint += Invalidate;
const float yStart = 10.0f;
var vector3 = new Vector3(5.0f, yStart, 0.0f);
Vector3 pos = vector3;
// input slots
foreach (var slot in node.inputSlots)
{
pos.y += 22;
AddChild(new NodeAnchor(pos, typeof(Vector4), node, slot, data, Direction.Input));
}
var inputYMax = pos.y + 22;
// output port
pos.x = width;
pos.y = yStart;
foreach (var slot in node.outputSlots)
{
var edges = node.owner.GetEdges(node.GetSlotReference(slot.name));
// don't show empty output slots in collapsed mode
//if (node.drawMode == DrawMode.Collapsed && !edges.Any())
// continue;
pos.y += 22;
AddChild(new NodeAnchor(pos, typeof(Vector4), node, slot, data, Direction.Output));
}
pos.y += 22;
pos.y = Mathf.Max(pos.y, inputYMax);
/*
var nodeUIHeight = m_Node.GetNodeUIHeight(width);
m_NodeUIRect = new Rect(10, pos.y, width - 20, nodeUIHeight);
pos.y += nodeUIHeight;
if (node.hasPreview && node.drawMode != DrawMode.Collapsed)
{
m_PreviewArea = new Rect(10, pos.y, width - 20, width - 20);
pos.y += m_PreviewArea.height;
}*/
scale = new Vector3(pos.x, pos.y + 10.0f, 0.0f);
//OnWidget += MarkDirtyIfNeedsTime;
AddManipulator(new ImguiContainer());
AddManipulator(new Draggable());
}
/*
private bool MarkDirtyIfNeedsTime(CanvasElement element, Event e, Canvas2D parent)
{
var childrenNodes = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(childrenNodes, m_Node);
if (childrenNodes.Any(x => x is IRequiresTime))
Invalidate();
ListPool<INode>.Release(childrenNodes);
return true;
}*/
public override void UpdateModel(UpdateType t)
{
base.UpdateModel(t);
var pos = m_Node.position;
pos.min = translation;
m_Node.position = pos;
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
Color selectedColor = new Color(1.0f, 0.7f, 0.0f, 0.7f);
EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), selected ? selectedColor : backgroundColor);
GUI.Label(new Rect(0, 0, scale.x, 26f), GUIContent.none, new GUIStyle("preToolbar"));
GUI.Label(new Rect(10, 2, scale.x - 20.0f, 16.0f), m_Node.name, EditorStyles.toolbarTextField);
/*if (GUI.Button(new Rect(scale.x - 20f, 3f, 14f, 14f), m_Node.drawMode == DrawMode.Full ? "-" : "+"))
{
m_Node.drawMode = m_Node.drawMode == DrawMode.Full ? DrawMode.Collapsed : DrawMode.Full;
ParentCanvas().ReloadData();
ParentCanvas().Repaint();
return;
}*/
/*var modificationType = m_Node.NodeUI(m_NodeUIRect);
if (modificationType == GUIModificationType.Repaint)
{
// if we were changed, we need to redraw all the
// dependent nodes.
RepaintDependentNodes(m_Node);
}
else if (modificationType == GUIModificationType.ModelChanged)
{
ParentCanvas().ReloadData();
ParentCanvas().Repaint();
return;
}
if (m_Node.hasPreview
&& m_Node.drawMode != DrawMode.Collapsed
&& m_PreviewArea.width > 0
&& m_PreviewArea.height > 0)
{
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
GUI.DrawTexture(m_PreviewArea, m_Node.RenderPreview(new Rect(0, 0, m_PreviewArea.width, m_PreviewArea.height)), ScaleMode.StretchToFill, false);
GL.sRGBWrite = false;
}*/
base.Render(parentRect, canvas);
}
/*
public static void RepaintDependentNodes(AbstractMaterialNode bmn)
{
var dependentNodes = new List<INode>();
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, bmn);
foreach (var node in dependentNodes.OfType<SerializableNode>())
node.onNeedsRepaint();
}
public static void OnGUI(List<CanvasElement> selection)
{
var drawableMaterialNode = selection.OfType<DrawableMaterialNode>().FirstOrDefault();
if (drawableMaterialNode != null && drawableMaterialNode.m_Node.OnGUI())
{
// if we were changed, we need to redraw all the
// dependent nodes.
RepaintDependentNodes(drawableMaterialNode.m_Node);
}
}*/
}
}

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs.meta


fileFormatVersion: 2
guid: 52beeedec4c17cc4cad82cfe972c9b02
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

159
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
using UnityEngine;
namespace UnityEditor.Graphing.Drawing
{
public class GraphDataSource : ICanvasDataSource
{
readonly List<DrawableNode> m_DrawableNodes = new List<DrawableNode>();
public IGraph graph { get; set; }
public ICollection<DrawableNode> lastGeneratedNodes
{
get { return m_DrawableNodes; }
}
public CanvasElement[] FetchElements()
{
m_DrawableNodes.Clear();
Debug.LogFormat("Trying to convert: {0}", graph);
foreach (var node in graph.nodes)
{
// add the nodes
m_DrawableNodes.Add(new DrawableNode(node, 200.0f, this));
}
// Add the edges now
var drawableEdges = new List<Edge<NodeAnchor>>();
foreach (var drawableMaterialNode in m_DrawableNodes)
{
var baseNode = drawableMaterialNode.m_Node;
foreach (var slot in baseNode.outputSlots)
{
var sourceAnchor = (NodeAnchor)drawableMaterialNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == slot);
var edges = baseNode.owner.GetEdges(new SlotReference(baseNode.guid, slot.name));
foreach (var edge in edges)
{
var toNode = baseNode.owner.GetNodeFromGuid(edge.inputSlot.nodeGuid);
var toSlot = toNode.FindInputSlot(edge.inputSlot.slotName);
var targetNode = m_DrawableNodes.FirstOrDefault(x => x.m_Node == toNode);
var targetAnchor = (NodeAnchor)targetNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == toSlot);
drawableEdges.Add(new Edge<NodeAnchor>(this, sourceAnchor, targetAnchor));
}
}
}
// Add proxy inputs for when edges are not connect
var nullInputSlots = new List<NullInputProxy>();
foreach (var drawableMaterialNode in m_DrawableNodes)
{
var baseNode = drawableMaterialNode.m_Node;
// grab the input slots where there are no edges
foreach (var slot in baseNode.GetInputsWithNoConnection())
{
// if there is no anchor, continue
// this can happen if we are in collapsed mode
var sourceAnchor = (NodeAnchor)drawableMaterialNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor)x).m_Slot == slot);
if (sourceAnchor == null)
continue;
nullInputSlots.Add(new NullInputProxy(baseNode, slot, sourceAnchor));
}
}
var toReturn = new List<CanvasElement>();
toReturn.AddRange(m_DrawableNodes.Select(x => (CanvasElement)x));
toReturn.AddRange(drawableEdges.Select(x => (CanvasElement)x));
toReturn.AddRange(nullInputSlots.Select(x => (CanvasElement)x));
//toReturn.Add(new FloatingPreview(new Rect(Screen.width - 300, Screen.height - 300, 300, 300), pixelGraph.nodes.FirstOrDefault(x => x is PixelShaderNode)));
Debug.LogFormat("Returning {0} nodes", m_DrawableNodes.Count);
Debug.LogFormat("Returning {0} drawableEdges", drawableEdges.Count);
Debug.LogFormat("Returning {0} nullInputSlots", nullInputSlots.Count);
return toReturn.ToArray();
}
public void DeleteElement(CanvasElement e)
{
// do nothing here, we want to use delete elements.
// delete elements ensures that edges are deleted before nodes.
}
public void DeleteElements(List<CanvasElement> elements)
{
var toRemoveEdge = new List<IEdge>();
// delete selected edges first
foreach (var e in elements.OfType<Edge<NodeAnchor>>())
{
//find the edge
var edge = graph.edges.FirstOrDefault(x => graph.GetNodeFromGuid(x.outputSlot.nodeGuid).FindOutputSlot(x.outputSlot.slotName) == e.Left.m_Slot
&& graph.GetNodeFromGuid(x.inputSlot.nodeGuid).FindInputSlot(x.inputSlot.slotName) == e.Right.m_Slot);
toRemoveEdge.Add(edge);
}
var toRemoveNode = new List<INode>();
// now delete the nodes
foreach (var e in elements.OfType<DrawableNode>())
{
if (!e.m_Node.canDeleteNode)
continue;
toRemoveNode.Add(e.m_Node);
}
graph.RemoveElements(toRemoveNode, toRemoveEdge);
}
public void Connect(NodeAnchor a, NodeAnchor b)
{
graph.Connect(a.m_Node.GetSlotReference(a.m_Slot.name), b.m_Node.GetSlotReference(b.m_Slot.name));
}
/* private string m_LastPath;
public void Export(bool quickExport)
{
var path = quickExport ? m_LastPath : EditorUtility.SaveFilePanelInProject("Export shader to file...", "shader.shader", "shader", "Enter file name");
m_LastPath = path; // For quick exporting
if (!string.IsNullOrEmpty(path))
graph.ExportShader(path);
else
EditorUtility.DisplayDialog("Export Shader Error", "Cannot export shader", "Ok");
}
}
public class FloatingPreview : CanvasElement
{
private AbstractMaterialNode m_Node;
public FloatingPreview(Rect position, AbstractMaterialNode node)
{
m_Node = node as AbstractMaterialNode;
m_Translation = new Vector2(position.x, position.y);
m_Scale = new Vector3(position.width, position.height, 1);
m_Caps |= Capabilities.Floating | Capabilities.Unselectable;
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
var drawArea = new Rect(0, 0, scale.x, scale.y);
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
EditorGUI.DrawRect(drawArea, backgroundColor);
drawArea.width -= 10;
drawArea.height -= 10;
drawArea.x += 5;
drawArea.y += 5;
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
GUI.DrawTexture(drawArea, m_Node.RenderPreview(new Rect(0, 0, drawArea.width, drawArea.height)), ScaleMode.StretchToFill, false);
GL.sRGBWrite = false;
Invalidate();
canvas.Repaint();
}*/
}
}

190
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs


using System;
using System.Reflection;
using UnityEditor.Experimental;
using UnityEditor.MaterialGraph;
using UnityEngine;
using Object = UnityEngine.Object;
namespace UnityEditor.Graphing.Drawing
{
class GraphEditWindow : EditorWindow
{
[MenuItem("Window/Graph Editor")]
public static void OpenMenu()
{
GetWindow<GraphEditWindow>();
}
[SerializeField]
private SerializableGraphAsset m_LastSelection;
[NonSerialized]
private Canvas2D m_Canvas;
[NonSerialized]
private EditorWindow m_HostWindow;
[NonSerialized]
private GraphDataSource m_DataSource;
private bool shouldRepaint
{
get
{
return m_LastSelection != null && m_LastSelection.graph != null;
}
}
void Update()
{
if (shouldRepaint)
Repaint();
}
void OnSelectionChange()
{
if (Selection.activeObject == null || !EditorUtility.IsPersistent(Selection.activeObject))
return;
if (Selection.activeObject is SerializableGraphAsset)
{
var selection = (SerializableGraphAsset) Selection.activeObject;
if (selection != m_LastSelection)
{
m_LastSelection = selection;
Rebuild();
Repaint();
}
}
}
private void InitializeCanvas()
{
if (m_Canvas == null)
{
m_DataSource = new GraphDataSource();
m_Canvas = new Canvas2D(this, m_HostWindow, m_DataSource);
// draggable manipulator allows to move the canvas around. Note that individual elements can have the draggable manipulator on themselves
m_Canvas.AddManipulator(new Draggable(2, EventModifiers.None));
m_Canvas.AddManipulator(new Draggable(0, EventModifiers.Alt));
// make the canvas zoomable
m_Canvas.AddManipulator(new Zoomable());
// allow framing the selection when hitting "F" (frame) or "A" (all). Basically shows how to trap a key and work with the canvas selection
m_Canvas.AddManipulator(new Frame(Frame.FrameType.All));
m_Canvas.AddManipulator(new Frame(Frame.FrameType.Selection));
// The following manipulator show how to work with canvas2d overlay and background rendering
m_Canvas.AddManipulator(new RectangleSelect());
m_Canvas.AddManipulator(new ScreenSpaceGrid());
m_Canvas.AddManipulator(new ContextualMenu(DoAddNodeMenu));
m_Canvas.AddManipulator(new DeleteSelected(m_DataSource.DeleteElements, m_Canvas));
}
Rebuild();
}
private class AddNodeCreationObject : object
{
public Vector2 m_Pos;
public readonly Type m_Type;
public AddNodeCreationObject(Type t, Vector2 p) { m_Type = t; m_Pos = p; }
};
private void AddNode(object obj)
{
var posObj = obj as AddNodeCreationObject;
if (posObj == null)
return;
INode node;
try
{
node = Activator.CreateInstance(posObj.m_Type, m_LastSelection.graph) as INode;
}
catch
{
Debug.LogWarningFormat("Could not construct instance of: {0}", posObj.m_Type);
return;
}
if (node == null)
return;
node.position = new Rect(posObj.m_Pos.x, posObj.m_Pos.y, node.position.width, node.position.height);
m_LastSelection.graph.AddNode(node);
Rebuild();
Repaint();
}
public virtual bool CanAddToNodeMenu(Type type) { return true; }
protected bool DoAddNodeMenu(Event @event, Canvas2D parent, Object customData)
{
var gm = new GenericMenu();
foreach (Type type in Assembly.GetAssembly(typeof(AbstractMaterialNode)).GetTypes())
{
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(AbstractMaterialNode))))
{
var attrs = type.GetCustomAttributes(typeof(TitleAttribute), false) as TitleAttribute[];
if (attrs != null && attrs.Length > 0 && CanAddToNodeMenu(type))
{
gm.AddItem(new GUIContent(attrs[0].m_Title), false, AddNode, new AddNodeCreationObject(type, parent.MouseToCanvas(@event.mousePosition)));
}
}
}
gm.ShowAsContext();
return true;
}
private void Rebuild()
{
if (m_Canvas == null || m_LastSelection == null || m_LastSelection.graph == null)
return;
m_DataSource.graph = m_LastSelection.graph;
m_Canvas.ReloadData();
}
void OnGUI()
{
m_HostWindow = this;
if (m_Canvas == null)
{
InitializeCanvas();
}
if (m_LastSelection == null || m_LastSelection.graph == null)
{
GUILayout.Label("No Graph selected");
return;
}
m_Canvas.OnGUI(this, new Rect(0, 0, position.width - 250, position.height));
}
/*public void RenderOptions(MaterialGraph graph)
{
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
EditorGUILayout.BeginVertical();
m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos, EditorStyles.textArea, GUILayout.Width(250), GUILayout.ExpandHeight(true));
graph.materialOptions.DoGUI();
EditorGUILayout.Separator();
m_NodeExpanded = MaterialGraphStyles.Header("Selected", m_NodeExpanded);
if (m_NodeExpanded)
DrawableMaterialNode.OnGUI(m_Canvas.selection);
GUILayout.EndScrollView();
if (GUILayout.Button("Export"))
m_DataSource.Export(false);
GUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
}*/
}
}

68
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NullInputProxy.cs


using UnityEditor.Experimental;
using UnityEngine;
namespace UnityEditor.Graphing.Drawing
{
public class NullInputProxy : CanvasElement
{
private ISlot m_InputSlot;
private INode m_Node;
private NodeAnchor m_NodeAnchor;
private const int kWidth = 180;
public NullInputProxy(INode node, ISlot inputSlot, NodeAnchor nodeAnchor)
{
m_InputSlot = inputSlot;
m_Node = node;
m_NodeAnchor = nodeAnchor;
var size = m_NodeAnchor.scale;
size.x = kWidth;
scale = size;
nodeAnchor.AddDependency(this);
UpdateModel(UpdateType.Update);
var position = m_NodeAnchor.canvasBoundingRect.min;
position.x -= kWidth;
translation = position;
AddManipulator(new ImguiContainer());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
var size = m_NodeAnchor.scale;
size.x = kWidth;
scale = size;
var position = m_NodeAnchor.canvasBoundingRect.min;
position.x -= kWidth;
translation = position;
var rect = new Rect(0, 0, scale.x, scale.y);
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f));
//TODO: FIX
/*var changed = m_Node.DrawSlotDefaultInput(rect, m_InputSlot);
if (changed)
DrawableMaterialNode.RepaintDependentNodes(m_Node);*/
}
public override void UpdateModel(UpdateType t)
{
var size = m_NodeAnchor.scale;
size.x = kWidth;
scale = size;
var position = m_NodeAnchor.canvasBoundingRect.min;
position.x -= kWidth;
translation = position;
base.UpdateModel(t);
}
}
}

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/Edge.cs.meta


fileFormatVersion: 2
guid: d35a1ba1f2dabea42ab1fc3d040eec81
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/NodeUtils.cs.meta


fileFormatVersion: 2
guid: b5721d495a5354c4a96da57b12f43adb
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableGraph.cs.meta


fileFormatVersion: 2
guid: 94b39bb81d63f9c4d99f87da537af3ef
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableNode.cs.meta


fileFormatVersion: 2
guid: bd99903e0e5626448a8518284feeb047
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableSlot.cs.meta


fileFormatVersion: 2
guid: 236912145b2fff1409d2b69157f5de23
timeCreated: 1464264924
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SlotType.cs.meta


fileFormatVersion: 2
guid: c465ac18d51260d41999717f8c47770f
timeCreated: 1464264925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/Edge.cs.meta


fileFormatVersion: 2
guid: 6b610a05c25f54d4c90f7ebf82696481
timeCreated: 1463576280
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/GUIModificationType.cs.meta


fileFormatVersion: 2
guid: c1bef593b05291f46b4bfd7a7192b881
timeCreated: 1464079584
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
UnityProject/Assets/GraphFramework/SerializableGraph/NodeUtils.cs.meta


fileFormatVersion: 2
guid: 992a8f404953a8248b943cb6fb0b2c79
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

12
UnityProject/Assets/GraphFramework/SerializableGraph/SerializableGraph.cs.meta


fileFormatVersion: 2
guid: 212c20183bfb8be42a77c212a54af19e
timeCreated: 1464079584
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/SerializableNode.cs.meta


fileFormatVersion: 2
guid: a9ce774f3d69dc241aff311e95b8ad19
timeCreated: 1464081042
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/SerializableSlot.cs.meta


fileFormatVersion: 2
guid: 751467780a86a1044a8037840649efd0
timeCreated: 1464081042
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/GraphFramework/SerializableGraph/SlotReference.cs.meta


fileFormatVersion: 2
guid: a178e14960be0e944b4652535f2d12e4
timeCreated: 1463576280
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
UnityProject/Assets/UnityShaderEditor/Editor/Drawing/DrawableMaterialNode.cs.meta


fileFormatVersion: 2
guid: 476f6813876d1d04387dfa9640d44324
timeCreated: 1445419780
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

196
UnityProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialWindow.cs


#define DEBUG_MAT_GEN
using System;
using System.Reflection;
using UnityEditor.Experimental;
using UnityEngine;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph
{
class MaterialWindow : EditorWindow
{
[MenuItem("Window/Material")]
public static void OpenMenu()
{
GetWindow<MaterialWindow>();
}
private MaterialGraph m_MaterialGraph;
private Canvas2D m_Canvas = null;
private EditorWindow m_HostWindow = null;
private MaterialGraphDataSource m_DataSource;
private Vector2 m_ScrollPos;
private bool m_NodeExpanded;
private bool shouldRepaint
{
get
{
return m_MaterialGraph != null && m_MaterialGraph.currentGraph != null && m_MaterialGraph.currentGraph.requiresRepaint;
}
}
void Update()
{
if (shouldRepaint)
Repaint();
}
void OnSelectionChange()
{
if (Selection.activeObject == null || !EditorUtility.IsPersistent(Selection.activeObject))
return;
if (Selection.activeObject is MaterialGraphAsset)
{
var selection = Selection.activeObject as MaterialGraphAsset;
if (selection.graph != m_MaterialGraph)
{
m_MaterialGraph = selection.graph;
}
}
Rebuild();
Repaint();
}
private void InitializeCanvas()
{
if (m_Canvas == null)
{
m_DataSource = new MaterialGraphDataSource();
m_Canvas = new Canvas2D(this, m_HostWindow, m_DataSource);
// draggable manipulator allows to move the canvas around. Note that individual elements can have the draggable manipulator on themselves
m_Canvas.AddManipulator(new Draggable(2, EventModifiers.None));
m_Canvas.AddManipulator(new Draggable(0, EventModifiers.Alt));
// make the canvas zoomable
m_Canvas.AddManipulator(new Zoomable());
// allow framing the selection when hitting "F" (frame) or "A" (all). Basically shows how to trap a key and work with the canvas selection
m_Canvas.AddManipulator(new Frame(Frame.FrameType.All));
m_Canvas.AddManipulator(new Frame(Frame.FrameType.Selection));
// The following manipulator show how to work with canvas2d overlay and background rendering
m_Canvas.AddManipulator(new RectangleSelect());
m_Canvas.AddManipulator(new ScreenSpaceGrid());
m_Canvas.AddManipulator(new ContextualMenu(DoAddNodeMenu));
m_Canvas.AddManipulator(new DeleteSelected(m_DataSource.DeleteElements, m_Canvas));
}
Rebuild();
}
private class AddNodeCreationObject : object
{
public Vector2 m_Pos;
public readonly Type m_Type;
public AddNodeCreationObject(Type t, Vector2 p) { m_Type = t; m_Pos = p; }
};
private void AddNode(object obj)
{
var posObj = obj as AddNodeCreationObject;
if (posObj == null)
return;
AbstractMaterialNode node = null;
try
{
var constructorInfo = posObj.m_Type.GetConstructor(new[] {typeof(AbstractMaterialGraph)});
node = (AbstractMaterialNode)constructorInfo.Invoke(new object[] { m_MaterialGraph.currentGraph });
}
catch
{
Debug.LogWarningFormat("Could not construct instance of: {0} as there is no single argument constuctor that takes a AbstractMaterialGraph", posObj.m_Type);
return;
}
node.position = new Rect(posObj.m_Pos.x, posObj.m_Pos.y, node.position.width, node.position.height);
m_MaterialGraph.currentGraph.AddNode(node);
Rebuild();
Repaint();
}
public virtual bool CanAddToNodeMenu(Type type) { return true; }
protected bool DoAddNodeMenu(Event @event, Canvas2D parent, Object customData)
{
var gm = new GenericMenu();
foreach (Type type in Assembly.GetAssembly(typeof(AbstractMaterialNode)).GetTypes())
{
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(AbstractMaterialNode))))
{
var attrs = type.GetCustomAttributes(typeof(TitleAttribute), false) as TitleAttribute[];
if (attrs != null && attrs.Length > 0 && CanAddToNodeMenu(type))
{
gm.AddItem(new GUIContent(attrs[0].m_Title), false, AddNode, new AddNodeCreationObject(type, parent.MouseToCanvas(@event.mousePosition)));
}
}
}
gm.ShowAsContext();
return true;
}
private void Rebuild()
{
if (m_Canvas == null || m_MaterialGraph == null)
return;
m_DataSource.graph = m_MaterialGraph;
m_Canvas.ReloadData();
}
void OnGUI()
{
m_HostWindow = this;
if (m_Canvas == null)
{
InitializeCanvas();
}
if (m_MaterialGraph == null)
{
GUILayout.Label("No Graph selected");
return;
}
//m_Canvas.dataSource = m_ActiveGraph;
m_Canvas.OnGUI(this, new Rect(0, 0, position.width - 250, position.height));
RenderOptions(m_MaterialGraph);
}
public void RenderOptions(MaterialGraph graph)
{
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
EditorGUILayout.BeginVertical();
m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos, EditorStyles.textArea, GUILayout.Width(250), GUILayout.ExpandHeight(true));
graph.materialOptions.DoGUI();
EditorGUILayout.Separator();
m_NodeExpanded = MaterialGraphStyles.Header("Selected", m_NodeExpanded);
if (m_NodeExpanded)
DrawableMaterialNode.OnGUI(m_Canvas.selection);
GUILayout.EndScrollView();
if (GUILayout.Button("Export"))
m_DataSource.Export(false);
GUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
}
public static void DebugMaterialGraph(string s)
{
#if DEBUG_MAT_GEN
Debug.Log(s);
#endif
}
}
}

66
UnityProject/Assets/UnityShaderEditor/Editor/Drawing/NullInputProxy.cs


using UnityEditor.Experimental;
using UnityEditor.Graphs;
using UnityEngine;
namespace UnityEditor.MaterialGraph
{
public class NullInputProxy : CanvasElement
{
private MaterialSlot m_InputSlot;
private AbstractMaterialNode m_Node;
private NodeAnchor m_NodeAnchor;
private const int kWidth = 180;
public NullInputProxy(AbstractMaterialNode node, MaterialSlot inputSlot, NodeAnchor nodeAnchor)
{
m_InputSlot = inputSlot;
m_Node = node;
m_NodeAnchor = nodeAnchor;
var size = m_NodeAnchor.scale;
size.x = kWidth;
scale = size;
nodeAnchor.AddDependency(this);
UpdateModel(UpdateType.Update);
var position = m_NodeAnchor.canvasBoundingRect.min;
position.x -= kWidth;
translation = position;
AddManipulator(new ImguiContainer());
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
var size = m_NodeAnchor.scale;
size.x = kWidth;
scale = size;
var position = m_NodeAnchor.canvasBoundingRect.min;
position.x -= kWidth;
translation = position;
var rect = new Rect(0, 0, scale.x, scale.y);
var changed = m_Node.DrawSlotDefaultInput(rect, m_InputSlot);
if (changed)
DrawableMaterialNode.RepaintDependentNodes(m_Node);
}
public override void UpdateModel(UpdateType t)
{
var size = m_NodeAnchor.scale;
size.x = kWidth;
scale = size;
var position = m_NodeAnchor.canvasBoundingRect.min;
position.x -= kWidth;
translation = position;
base.UpdateModel(t);
}
}
}

152
UnityProject/Assets/UnityShaderEditor/Editor/Drawing/DrawableMaterialNode.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.MaterialGraph
{
public sealed class DrawableMaterialNode : CanvasElement
{
private readonly MaterialGraphDataSource m_Data;
public AbstractMaterialNode m_Node;
private Rect m_PreviewArea;
private Rect m_NodeUIRect;
public DrawableMaterialNode(AbstractMaterialNode node, float width, MaterialGraphDataSource data)
{
translation = node.position.min;
scale = new Vector2(width, width);
m_Node = node;
m_Data = data;
m_Node.onNeedsRepaint += Invalidate;
const float yStart = 10.0f;
var vector3 = new Vector3(5.0f, yStart, 0.0f);
Vector3 pos = vector3;
// input slots
foreach (var slot in node.materialInputSlots)
{
pos.y += 22;
AddChild(new NodeAnchor(pos, typeof (Vector4), node, slot, data, Direction.Input));
}
var inputYMax = pos.y + 22;
// output port
pos.x = width;
pos.y = yStart;
foreach (var slot in node.materialOuputSlots)
{
var edges = node.owner.GetEdges(new SlotReference(node.guid, slot.name));
// don't show empty output slots in collapsed mode
if (node.drawMode == DrawMode.Collapsed && !edges.Any())
continue;
pos.y += 22;
AddChild(new NodeAnchor(pos, typeof (Vector4), node, slot, data, Direction.Output));
}
pos.y += 22;
pos.y = Mathf.Max(pos.y, inputYMax);
var nodeUIHeight = m_Node.GetNodeUIHeight(width);
m_NodeUIRect = new Rect(10, pos.y, width - 20, nodeUIHeight);
pos.y += nodeUIHeight;
if (node.hasPreview && node.drawMode != DrawMode.Collapsed)
{
m_PreviewArea = new Rect(10, pos.y, width - 20, width - 20);
pos.y += m_PreviewArea.height;
}
scale = new Vector3(pos.x, pos.y + 10.0f, 0.0f);
OnWidget += MarkDirtyIfNeedsTime;
AddManipulator(new ImguiContainer());
AddManipulator(new Draggable());
}
private bool MarkDirtyIfNeedsTime(CanvasElement element, Event e, Canvas2D parent)
{
var childrenNodes = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(childrenNodes, m_Node);
if (childrenNodes.Any(x => x is IRequiresTime))
Invalidate();
ListPool<INode>.Release(childrenNodes);
return true;
}
public override void UpdateModel(UpdateType t)
{
base.UpdateModel(t);
var pos = m_Node.position;
pos.min = translation;
m_Node.position = pos;
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
Color selectedColor = new Color(1.0f, 0.7f, 0.0f, 0.7f);
EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), m_Node.hasError ? Color.red : selected ? selectedColor : backgroundColor);
GUI.Label(new Rect(0, 0, scale.x, 26f), GUIContent.none, new GUIStyle("preToolbar"));
GUI.Label(new Rect(10, 2, scale.x - 20.0f, 16.0f), m_Node.name, EditorStyles.toolbarTextField);
if (GUI.Button(new Rect(scale.x - 20f, 3f, 14f, 14f), m_Node.drawMode == DrawMode.Full ? "-" : "+"))
{
m_Node.drawMode = m_Node.drawMode == DrawMode.Full ? DrawMode.Collapsed : DrawMode.Full;
ParentCanvas().ReloadData();
ParentCanvas().Repaint();
return;
}
var modificationType = m_Node.NodeUI(m_NodeUIRect);
if (modificationType== GUIModificationType.Repaint)
{
// if we were changed, we need to redraw all the
// dependent nodes.
RepaintDependentNodes(m_Node);
}
else if (modificationType == GUIModificationType.ModelChanged)
{
ParentCanvas().ReloadData();
ParentCanvas().Repaint();
return;
}
if (m_Node.hasPreview
&& m_Node.drawMode != DrawMode.Collapsed
&& m_PreviewArea.width > 0
&& m_PreviewArea.height > 0)
{
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
GUI.DrawTexture(m_PreviewArea, m_Node.RenderPreview(new Rect(0, 0, m_PreviewArea.width, m_PreviewArea.height)), ScaleMode.StretchToFill, false);
GL.sRGBWrite = false;
}
base.Render(parentRect, canvas);
}
public static void RepaintDependentNodes(AbstractMaterialNode bmn)
{
var dependentNodes = new List<INode>();
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, bmn);
foreach (var node in dependentNodes.OfType<SerializableNode>())
node.onNeedsRepaint();
}
public static void OnGUI(List<CanvasElement> selection)
{
var drawableMaterialNode = selection.OfType<DrawableMaterialNode>().FirstOrDefault();
if (drawableMaterialNode != null && drawableMaterialNode.m_Node.OnGUI())
{
// if we were changed, we need to redraw all the
// dependent nodes.
RepaintDependentNodes(drawableMaterialNode.m_Node);
}
}
}
}

165
UnityProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphDataSource.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.MaterialGraph
{
public class MaterialGraphDataSource : ICanvasDataSource
{
readonly List<DrawableMaterialNode> m_DrawableNodes = new List<DrawableMaterialNode>();
public MaterialGraph graph { get; set; }
public ICollection<DrawableMaterialNode> lastGeneratedNodes
{
get { return m_DrawableNodes; }
}
public CanvasElement[] FetchElements()
{
m_DrawableNodes.Clear();
Debug.Log("trying to convert");
var pixelGraph = graph.currentGraph;
foreach (var node in pixelGraph.nodes)
{
// add the nodes
var bmn = node as AbstractMaterialNode;
m_DrawableNodes.Add(new DrawableMaterialNode(bmn, (bmn is PixelShaderNode) ? 600.0f : 200.0f, this));
}
// Add the edges now
var drawableEdges = new List<Edge<NodeAnchor>>();
foreach (var drawableMaterialNode in m_DrawableNodes)
{
var baseNode = drawableMaterialNode.m_Node;
foreach (var slot in baseNode.outputSlots)
{
var sourceAnchor = (NodeAnchor)drawableMaterialNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == slot);
var edges = baseNode.owner.GetEdges(new SlotReference(baseNode.guid, slot.name));
foreach (var edge in edges)
{
var toNode = baseNode.owner.GetNodeFromGuid(edge.inputSlot.nodeGuid);
var toSlot = toNode.FindInputSlot(edge.inputSlot.slotName);
var targetNode = m_DrawableNodes.FirstOrDefault(x => x.m_Node == toNode);
var targetAnchor = (NodeAnchor)targetNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == toSlot);
drawableEdges.Add(new Edge<NodeAnchor>(this, sourceAnchor, targetAnchor));
}
}
}
// Add proxy inputs for when edges are not connect
var nullInputSlots = new List<NullInputProxy>();
foreach (var drawableMaterialNode in m_DrawableNodes)
{
var baseNode = drawableMaterialNode.m_Node;
// grab the input slots where there are no edges
foreach (var slot in baseNode.GetInputsWithNoConnection())
{
// if there is no anchor, continue
// this can happen if we are in collapsed mode
var sourceAnchor = (NodeAnchor)drawableMaterialNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor)x).m_Slot == slot);
if (sourceAnchor == null)
continue;
nullInputSlots.Add(new NullInputProxy(baseNode, slot, sourceAnchor));
}
}
var toReturn = new List<CanvasElement>();
toReturn.AddRange(m_DrawableNodes.Select(x => (CanvasElement)x));
toReturn.AddRange(drawableEdges.Select(x => (CanvasElement)x));
toReturn.AddRange(nullInputSlots.Select(x => (CanvasElement)x));
//toReturn.Add(new FloatingPreview(new Rect(Screen.width - 300, Screen.height - 300, 300, 300), pixelGraph.nodes.FirstOrDefault(x => x is PixelShaderNode)));
Debug.LogFormat("Returning {0} nodes", m_DrawableNodes.Count);
Debug.LogFormat("Returning {0} drawableEdges", drawableEdges.Count);
Debug.LogFormat("Returning {0} nullInputSlots", nullInputSlots.Count);
return toReturn.ToArray();
}
public void DeleteElement(CanvasElement e)
{
// do nothing here, we want to use delete elements.
// delete elements ensures that edges are deleted before nodes.
}
public void DeleteElements(List<CanvasElement> elements)
{
var toRemoveEdge = new List<IEdge>();
// delete selected edges first
foreach (var e in elements.Where(x => x is Edge<NodeAnchor>))
{
//find the edge
var localEdge = (Edge<NodeAnchor>) e;
var edge = graph.currentGraph.edges.FirstOrDefault(x => graph.currentGraph.GetNodeFromGuid(x.outputSlot.nodeGuid).FindOutputSlot(x.outputSlot.slotName) == localEdge.Left.m_Slot
&& graph.currentGraph.GetNodeFromGuid(x.inputSlot.nodeGuid).FindInputSlot(x.inputSlot.slotName) == localEdge.Right.m_Slot);
toRemoveEdge.Add(edge);
}
var toRemoveNode = new List<INode>();
// now delete the nodes
foreach (var e in elements.Where(x => x is DrawableMaterialNode))
{
var node = ((DrawableMaterialNode) e).m_Node;
if (!node.canDeleteNode)
continue;
toRemoveNode.Add(node);
}
graph.currentGraph.RemoveElements(toRemoveNode, toRemoveEdge);
}
public void Connect(NodeAnchor a, NodeAnchor b)
{
var pixelGraph = graph.currentGraph;
pixelGraph.Connect(a.m_Node.GetSlotReference(a.m_Slot.name), b.m_Node.GetSlotReference(b.m_Slot.name));
}
private string m_LastPath;
public void Export(bool quickExport)
{
var path = quickExport ? m_LastPath : EditorUtility.SaveFilePanelInProject("Export shader to file...", "shader.shader", "shader", "Enter file name");
m_LastPath = path; // For quick exporting
if (!string.IsNullOrEmpty(path))
graph.ExportShader(path);
else
EditorUtility.DisplayDialog("Export Shader Error", "Cannot export shader", "Ok");
}
}
public class FloatingPreview : CanvasElement
{
private AbstractMaterialNode m_Node;
public FloatingPreview(Rect position, AbstractMaterialNode node)
{
m_Node = node as AbstractMaterialNode;
m_Translation = new Vector2(position.x, position.y);
m_Scale = new Vector3(position.width, position.height, 1);
m_Caps |= Capabilities.Floating | Capabilities.Unselectable;
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
var drawArea = new Rect(0, 0, scale.x, scale.y);
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
EditorGUI.DrawRect(drawArea, backgroundColor);
drawArea.width -= 10;
drawArea.height -= 10;
drawArea.x += 5;
drawArea.y += 5;
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
GUI.DrawTexture(drawArea, m_Node.RenderPreview(new Rect(0, 0, drawArea.width, drawArea.height)), ScaleMode.StretchToFill, false);
GL.sRGBWrite = false;
Invalidate();
canvas.Repaint();
}
}
}

/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Edge.cs → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/Edge.cs

/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/NodeUtils.cs → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/NodeUtils.cs

/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/SerializableGraph.cs → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableGraph.cs

/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/SerializableNode.cs → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableNode.cs

/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/SerializableSlot.cs → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableSlot.cs

/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/SlotReference.cs → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/SlotReference.cs

/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/SlotType.cs → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SlotType.cs

/UnityProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphDataSource.cs.meta → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs.meta

/UnityProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialWindow.cs.meta → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs.meta

/UnityProject/Assets/UnityShaderEditor/Editor/Drawing/MyNodeAdapters.cs → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MyNodeAdapters.cs

/UnityProject/Assets/UnityShaderEditor/Editor/Drawing/MyNodeAdapters.cs.meta → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MyNodeAdapters.cs.meta

/UnityProject/Assets/UnityShaderEditor/Editor/Drawing/NodeAnchor.cs → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeAnchor.cs

/UnityProject/Assets/UnityShaderEditor/Editor/Drawing/NodeAnchor.cs.meta → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeAnchor.cs.meta

/UnityProject/Assets/UnityShaderEditor/Editor/Drawing/DeleteSelected.cs → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DeleteSelected.cs

/UnityProject/Assets/UnityShaderEditor/Editor/Drawing/DeleteSelected.cs.meta → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DeleteSelected.cs.meta

/UnityProject/Assets/UnityShaderEditor/Editor/Drawing/NullInputProxy.cs.meta → /UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NullInputProxy.cs.meta

正在加载...
取消
保存