浏览代码

[Material Graph] Rename and reorganise the repository.

/main
Tim Cooper 8 年前
当前提交
1b049752
共有 98 个文件被更改,包括 1441 次插入1814 次删除
  1. 5
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/CopySelected.cs
  2. 366
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs
  3. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NullInputProxy.cs
  4. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs.meta
  5. 84
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
  6. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Styles/NodalView.uss
  7. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/ShaderGenerationTest.cs
  8. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs
  9. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function2InputTests.cs
  10. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function3InputTests.cs
  11. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialSlotTests.cs
  12. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialOptions.cs
  13. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/BlendNode.cs
  14. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/CombineNode.cs
  15. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/DivNode.cs
  16. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/FunctionMultiInput.cs
  17. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LengthNode.cs
  18. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LerpNode.cs
  19. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MultiplyNode.cs
  20. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalizeNode.cs
  21. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PixelShaderNode.cs
  22. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PowerNode.cs
  23. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/QuantizeNode.cs
  24. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SinNode.cs
  25. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SmoothStepNode.cs
  26. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubtractNode.cs
  27. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SwizzleNode.cs
  28. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyGenerator.cs
  29. 48
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodePreviewDrawData.cs
  30. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs
  31. 154
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs
  32. 316
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs
  33. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs.meta
  34. 9
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData.meta
  35. 9
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer.meta
  36. 45
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs
  37. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs.meta
  38. 15
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphDataSource.cs
  39. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphDataSource.cs.meta
  40. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer.meta
  41. 91
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs
  42. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs.meta
  43. 25
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/AnchorDrawData.cs
  44. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/AnchorDrawData.cs.meta
  45. 31
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/ControlDrawData.cs
  46. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/ControlDrawData.cs.meta
  47. 19
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/EdgeDrawData.cs
  48. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/EdgeDrawData.cs.meta
  49. 68
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs
  50. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs.meta
  51. 116
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs
  52. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs.meta
  53. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/ColorNodeDrawData.cs
  54. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/ColorNodeDrawData.cs.meta
  55. 18
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs
  56. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs.meta
  57. 36
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialNodeDrawData.cs
  58. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialNodeDrawData.cs.meta
  59. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodeDrawers.7z
  60. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodeDrawers.7z.meta
  61. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodePreviewDrawData.cs.meta
  62. 52
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/TextureNodeDrawData.cs
  63. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/TextureNodeDrawData.cs.meta
  64. 95
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs
  65. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs.meta
  66. 210
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs
  67. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs.meta
  68. 242
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs
  69. 13
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/ICustomNodeUi.cs
  70. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/ICustomNodeUi.cs.meta
  71. 0
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/IGraphElementView.cs
  72. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/IGraphElementView.cs.meta
  73. 149
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs
  74. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs.meta
  75. 34
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphElementView.cs
  76. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphElementView.cs.meta
  77. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphNode.cs.meta
  78. 118
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs
  79. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs.meta
  80. 160
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeData.cs
  81. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeData.cs.meta
  82. 40
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeAnchorData.cs
  83. 12
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeAnchorData.cs.meta
  84. 188
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphNode.cs
  85. 64
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphStyles.cs
  86. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphStyles.cs.meta
  87. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Editors.meta
  88. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs.meta
  89. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData.meta
  90. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodePreviewDrawData.cs
  91. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs.meta
  92. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs

5
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/CopySelected.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Graphing;
/*
namespace UnityEditor.Graphing.Drawing

366
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
using UnityEngine.MaterialGraph;
using UnityEngine.RMGUI;
namespace UnityEditor.Graphing.Drawing
{

public static void OpenMenu()
{
GetWindow<GraphEditWindow>();
}
}
public abstract class AbstractGraphEditWindow<T> : EditorWindow, ISerializationCallbackReceiver where T : class, IGraphAsset
{
public RenderTexture rt;
[NonSerialized]
private T m_LastSelection;
[SerializeField]
private ScriptableObject m_LastSelectedGraphSerialized;
private bool shouldRepaint
{
get
{
return m_LastSelection != null && m_LastSelection.shouldRepaint;
}
}
private MaterialGraphView m_Contents;
void OnEnable()
{
m_Contents = new MaterialGraphView();
m_Contents.name = "theView";
var source = CreateInstance<MaterialGraphDataSource>();
source.Initialize (m_LastSelection);
m_Contents.dataSource = source;
m_Contents.StretchToParentSize();
windowRoot.AddChild(m_Contents);
}
void OnDisable()
{
windowRoot.ClearChildren();
}
void Update()
{
if (shouldRepaint)
Repaint();
}
void OnSelectionChange()
{
if (Selection.activeObject == null || !EditorUtility.IsPersistent(Selection.activeObject))
return;
if (Selection.activeObject is ScriptableObject)
{
var selection = Selection.activeObject as T;
if (selection != m_LastSelection)
{
var graph = selection.graph;
graph.OnEnable();
graph.ValidateGraph();
m_LastSelection = selection;
var source = CreateInstance<MaterialGraphDataSource>();
source.Initialize (m_LastSelection);
m_Contents.dataSource = source;
m_Contents.StretchToParentSize();
Repaint();
}
}
}
/*
private void ConvertSelectionToSubGraph()
{
if (m_Canvas.dataSource == null)
return;
var dataSource = m_Canvas.dataSource as GraphDataSource;
if (dataSource == null)
return;
var asset = dataSource.graphAsset;
if (asset == null)
return;
var targetGraph = asset.graph;
if (targetGraph == null)
return;
if (!m_Canvas.selection.Any())
return;
var serialzied = CopySelected.SerializeSelectedElements(m_Canvas);
var deserialized = CopySelected.DeserializeSelectedElements(serialzied);
if (deserialized == null)
return;
string path = EditorUtility.SaveFilePanelInProject("Save subgraph", "New SubGraph", "ShaderSubGraph", "");
path = path.Replace(Application.dataPath, "Assets");
if (path.Length == 0)
return;
var graphAsset = CreateInstance<MaterialSubGraphAsset>();
graphAsset.name = Path.GetFileName(path);
graphAsset.PostCreate();
var graph = graphAsset.subGraph;
if (graphAsset.graph == null)
return;
var nodeGuidMap = new Dictionary<Guid, Guid>();
foreach (var node in deserialized.GetNodes<INode>())
{
var oldGuid = node.guid;
var newGuid = node.RewriteGuid();
nodeGuidMap[oldGuid] = newGuid;
graph.AddNode(node);
}
// remap outputs to the subgraph
var inputEdgeNeedsRemap = new List<IEdge>();
var outputEdgeNeedsRemap = new List<IEdge>();
foreach (var edge in deserialized.edges)
{
var outputSlot = edge.outputSlot;
var inputSlot = edge.inputSlot;
Guid remappedOutputNodeGuid;
Guid remappedInputNodeGuid;
var outputRemapExists = nodeGuidMap.TryGetValue(outputSlot.nodeGuid, out remappedOutputNodeGuid);
var inputRemapExists = nodeGuidMap.TryGetValue(inputSlot.nodeGuid, out remappedInputNodeGuid);
// pasting nice internal links!
if (outputRemapExists && inputRemapExists)
{
var outputSlotRef = new SlotReference(remappedOutputNodeGuid, outputSlot.slotId);
var inputSlotRef = new SlotReference(remappedInputNodeGuid, inputSlot.slotId);
graph.Connect(outputSlotRef, inputSlotRef);
}
// one edge needs to go to outside world
else if (outputRemapExists)
{
inputEdgeNeedsRemap.Add(edge);
}
else if (inputRemapExists)
{
outputEdgeNeedsRemap.Add(edge);
}
}
// we do a grouping here as the same output can
// point to multiple inputs
var uniqueOutputs = outputEdgeNeedsRemap.GroupBy(edge => edge.outputSlot);
var inputsNeedingConnection = new List<KeyValuePair<IEdge, IEdge>>();
foreach (var group in uniqueOutputs)
{
var inputNode = graph.inputNode;
var slotId = inputNode.AddSlot();
var outputSlotRef = new SlotReference(inputNode.guid, slotId);
foreach (var edge in group)
{
var newEdge = graph.Connect(outputSlotRef, new SlotReference(nodeGuidMap[edge.inputSlot.nodeGuid], edge.inputSlot.slotId));
inputsNeedingConnection.Add(new KeyValuePair<IEdge, IEdge>(edge, newEdge));
}
}
var uniqueInputs = inputEdgeNeedsRemap.GroupBy(edge => edge.inputSlot);
var outputsNeedingConnection = new List<KeyValuePair<IEdge, IEdge>>();
foreach (var group in uniqueInputs)
{
var outputNode = graph.outputNode;
var slotId = outputNode.AddSlot();
var inputSlotRef = new SlotReference(outputNode.guid, slotId);
foreach (var edge in group)
{
var newEdge = graph.Connect(new SlotReference(nodeGuidMap[edge.outputSlot.nodeGuid], edge.outputSlot.slotId), inputSlotRef);
outputsNeedingConnection.Add(new KeyValuePair<IEdge, IEdge>(edge, newEdge));
}
}
AssetDatabase.CreateAsset(graphAsset, path);
var subGraphNode = new SubGraphNode();
targetGraph.AddNode(subGraphNode);
subGraphNode.subGraphAsset = graphAsset;
foreach (var edgeMap in inputsNeedingConnection)
{
targetGraph.Connect(edgeMap.Key.outputSlot, new SlotReference(subGraphNode.guid, edgeMap.Value.outputSlot.slotId));
}
foreach (var edgeMap in outputsNeedingConnection)
{
targetGraph.Connect(new SlotReference(subGraphNode.guid, edgeMap.Value.inputSlot.slotId), edgeMap.Key.inputSlot);
}
var toDelete = m_Canvas.selection.Where(x => x is DrawableNode).ToList();
dataSource.DeleteElements(toDelete);
targetGraph.ValidateGraph();
m_Canvas.ReloadData();
m_Canvas.Invalidate();
m_Canvas.selection.Clear();
var toSelect = m_Canvas.elements.OfType<DrawableNode>().FirstOrDefault(x => x.m_Node == subGraphNode);
if (toSelect != null)
{
toSelect.selected = true;
m_Canvas.selection.Add(toSelect);
}
m_Canvas.Repaint();
}
private void Rebuild()
{
if (m_Canvas == null || m_LastSelection == null)
return;
m_DataSource.graphAsset = m_LastSelection;
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));
if (GUI.Button(new Rect(position.width - 250, 0, 250, 50), "Convert to Sub-Graph"))
ConvertSelectionToSubGraph();
if (GUI.Button(new Rect(position.width - 250, 70, 250, 50), "Export"))
Export(false);
if (GUI.Button(new Rect(position.width - 250, 140, 250, 50), "Export - quick"))
Export(true);
EditorGUI.ObjectField(new Rect(position.width - 250, 210, 250, 50), rt, typeof(RenderTexture), false);
}*/
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
var ds = m_Contents.dataSource as MaterialGraphDataSource;
if (ds != null && !string.IsNullOrEmpty(path))
{
ExportShader(ds.graphAsset as MaterialGraphAsset, path);
}
else
EditorUtility.DisplayDialog("Export Shader Error", "Cannot export shader", "Ok");
}
public static Shader ExportShader(MaterialGraphAsset graphAsset, string path)
{
if (graphAsset == null)
return null;
var materialGraph = graphAsset.graph as PixelGraph;
if (materialGraph == null)
return null;
List<PropertyGenerator.TextureInfo> configuredTextures;
var shaderString = ShaderGenerator.GenerateSurfaceShader(materialGraph.pixelMasterNode, new MaterialOptions(), materialGraph.name, false, out configuredTextures);
File.WriteAllText(path, shaderString);
AssetDatabase.Refresh(); // Investigate if this is optimal
var shader = AssetDatabase.LoadAssetAtPath(path, typeof(Shader)) as Shader;
if (shader == null)
return null;
var shaderImporter = AssetImporter.GetAtPath(path) as ShaderImporter;
if (shaderImporter == null)
return null;
var textureNames = new List<string>();
var textures = new List<Texture>();
foreach (var textureInfo in configuredTextures.Where(x => x.modifiable == TexturePropertyChunk.ModifiableState.Modifiable))
{
var texture = EditorUtility.InstanceIDToObject(textureInfo.textureId) as Texture;
if (texture == null)
continue;
textureNames.Add(textureInfo.name);
textures.Add(texture);
}
shaderImporter.SetDefaultTextures(textureNames.ToArray(), textures.ToArray());
textureNames.Clear();
textures.Clear();
foreach (var textureInfo in configuredTextures.Where(x => x.modifiable == TexturePropertyChunk.ModifiableState.NonModifiable))
{
var texture = EditorUtility.InstanceIDToObject(textureInfo.textureId) as Texture;
if (texture == null)
continue;
textureNames.Add(textureInfo.name);
textures.Add(texture);
}
shaderImporter.SetNonModifiableTextures(textureNames.ToArray(), textures.ToArray());
shaderImporter.SaveAndReimport();
return shaderImporter.GetShader();
}
/*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 void OnBeforeSerialize()
{
var o = m_LastSelection as ScriptableObject;
if (o != null)
m_LastSelectedGraphSerialized = o;
}
public void OnAfterDeserialize()
{
if (m_LastSelectedGraphSerialized != null)
m_LastSelection = m_LastSelectedGraphSerialized as T;
m_LastSelectedGraphSerialized = null;
}
}
}

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NullInputProxy.cs


using UnityEngine;
using UnityEngine.Graphing;
/*
namespace UnityEditor.Graphing.Drawing
{

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs.meta


fileFormatVersion: 2
guid: 194f855484623804c819a9132a24268f
timeCreated: 1445419780
timeCreated: 1476707366
licenseType: Pro
MonoImporter:
serializedVersion: 2

84
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs


using System.Collections.Generic;
using System.IO;
using System.Linq;
using RMGUI.GraphView;
using UnityEngine;
namespace UnityEditor.MaterialGraph
namespace UnityEditor.MaterialGraph.Drawing
{
public class MaterialGraphEditWindow : AbstractGraphEditWindow<IMaterialGraphAsset>
{

GetWindow<MaterialGraphEditWindow>();
}
public override AbstractGraphDataSource CreateDataSource()
{
return CreateInstance<MaterialGraphDataSource>();
}
public override GraphView CreateGraphView()
{
return new MaterialGraphView();
}
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
var ds = graphView.dataSource as AbstractGraphDataSource;
if (ds != null && !string.IsNullOrEmpty(path))
{
ExportShader(ds.graphAsset as MaterialGraphAsset, path);
}
else
EditorUtility.DisplayDialog("Export Shader Error", "Cannot export shader", "Ok");
}
public static Shader ExportShader(MaterialGraphAsset graphAsset, string path)
{
if (graphAsset == null)
return null;
var materialGraph = graphAsset.graph as PixelGraph;
if (materialGraph == null)
return null;
List<PropertyGenerator.TextureInfo> configuredTextures;
var shaderString = ShaderGenerator.GenerateSurfaceShader(materialGraph.pixelMasterNode, new MaterialOptions(), materialGraph.name, false, out configuredTextures);
File.WriteAllText(path, shaderString);
AssetDatabase.Refresh(); // Investigate if this is optimal
var shader = AssetDatabase.LoadAssetAtPath(path, typeof(Shader)) as Shader;
if (shader == null)
return null;
var shaderImporter = AssetImporter.GetAtPath(path) as ShaderImporter;
if (shaderImporter == null)
return null;
var textureNames = new List<string>();
var textures = new List<Texture>();
foreach (var textureInfo in configuredTextures.Where(x => x.modifiable == TexturePropertyChunk.ModifiableState.Modifiable))
{
var texture = EditorUtility.InstanceIDToObject(textureInfo.textureId) as Texture;
if (texture == null)
continue;
textureNames.Add(textureInfo.name);
textures.Add(texture);
}
shaderImporter.SetDefaultTextures(textureNames.ToArray(), textures.ToArray());
textureNames.Clear();
textures.Clear();
foreach (var textureInfo in configuredTextures.Where(x => x.modifiable == TexturePropertyChunk.ModifiableState.NonModifiable))
{
var texture = EditorUtility.InstanceIDToObject(textureInfo.textureId) as Texture;
if (texture == null)
continue;
textureNames.Add(textureInfo.name);
textures.Add(texture);
}
shaderImporter.SetNonModifiableTextures(textureNames.ToArray(), textures.ToArray());
shaderImporter.SaveAndReimport();
return shaderImporter.GetShader();
}
}
}

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Styles/NodalView.uss


MaterialGraphNode {
MaterialNodeDrawer {
MaterialGraphNode #slots {
MaterialNodeDrawer #slots {
MaterialGraphNode #slots #input {
MaterialNodeDrawer #slots #input {
MaterialGraphNode #slots #output {
MaterialNodeDrawer #slots #output {
MaterialGraphNode #controls {
MaterialNodeDrawer #controls {
MaterialGraphNode #controls #element{
MaterialNodeDrawer #controls #element{
MaterialGraphNode #preview {
MaterialNodeDrawer #preview {
MaterialGraphNode #preview #image {
MaterialNodeDrawer #preview #image {
height: 200;
width: 200;
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/ShaderGenerationTest.cs


using System.IO;
using System.Linq;
using NUnit.Framework;
using UnityEditor.Graphing.Drawing;
using UnityEditor.MaterialGraph.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
using Object = UnityEngine.Object;

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs


using System;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function2InputTests.cs


using System;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function3InputTests.cs


using System;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialSlotTests.cs


using System;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Graphing;

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialOptions.cs


using System;
using UnityEngine;
namespace UnityEngine.MaterialGraph
{

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/BlendNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Art/Blend Node")]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/CombineNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Art/Combine Node")]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/DivNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Div Node")]

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/FunctionMultiInput.cs


using System.Linq;
using UnityEngine;
using System.Collections.Generic;
namespace UnityEditor.MaterialGraph
{
/*public abstract class FunctionMultiInput : BaseMaterialNode, IGeneratesBodyCode

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LengthNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Length Node")]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LerpNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Lerp Node")]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MultiplyNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Multiply Node")]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalizeNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Normalize Node")]

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PixelShaderNode.cs


using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine.Graphing;

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PowerNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Power Node")]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/QuantizeNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Quantize Node")]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SinNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Sin Node")]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SmoothStepNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/SmoothStep Node")]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubtractNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Math/Subtract Node")]

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SwizzleNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Channels/Swizzle Node")]

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyGenerator.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

48
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodePreviewDrawData.cs


using UnityEngine.MaterialGraph;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph
namespace UnityEditor.MaterialGraph.Drawing
/* [CustomDataView(typeof(NodePreviewData))]
public class NodePreview : GraphElement
{
public NodePreview(NodePreviewData preview)
{
dataProvider = preview;
}
public override void DoRepaint(PaintContext args)
{
base.DoRepaint(args);
m_WwwTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
AddChild(new Image { image = m_WwwTexture });
Handles.DrawSolidRectangleWithOutline(parent.position, Color.red, Color.blue);
}
}*/
public abstract class NodeControlData : GraphElementData
{
public INode node { get; private set; }
protected NodeControlData()
{}
public void Initialize(INode inNode)
{
node = inNode;
}
public virtual void OnGUIHandler()
{
if (node == null)
return;
GUIUtility.GetControlID (node.guid.GetHashCode(), FocusType.Passive);
}
public abstract float GetHeight();
}
[Serializable]
public class NodePreviewData : GraphElementData
public class NodePreviewDrawData : GraphElementData
protected NodePreviewData()
protected NodePreviewDrawData()
{}
private MaterialGraphPreviewGenerator m_PreviewGenerator;

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs


using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph
namespace UnityEditor.MaterialGraph.Drawing
{
internal class MaterialGraphPreviewGenerator
{

154
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs


using System;
using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
using UnityEditor.MaterialGraph.Drawing;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
[Serializable]
public abstract class AbstractGraphDataSource : ScriptableObject, IGraphElementDataSource
{
[SerializeField]
private List<GraphElementData> m_Elements = new List<GraphElementData>();
private readonly Dictionary<Type, Type> m_DataMapper = new Dictionary<Type, Type>();
public IGraphAsset graphAsset { get; private set; }
void OnNodeChanged(INode inNode)
{
var dependentNodes = new List<INode>();
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, inNode);
foreach (var node in dependentNodes)
{
var theElements = m_Elements.OfType<MaterialNodeDrawData>().ToList();
var found = theElements.Where(x => x.node.guid == node.guid).ToList();
foreach (var drawableNodeData in found)
drawableNodeData.MarkDirtyHack();
}
}
private void UpdateData()
{
m_Elements.Clear();
var drawableNodes = new List<MaterialNodeDrawData>();
foreach (var node in graphAsset.graph.GetNodes<INode>())
{
var type = node.GetType();
Type found = null;
while (type != null)
{
if (m_DataMapper.TryGetValue(type, out found))
break;
type = type.BaseType;
}
if (found == null)
found = typeof(MaterialNodeDrawData);
var nodeData = (MaterialNodeDrawData) CreateInstance(found);
node.onModified += OnNodeChanged;
nodeData.Initialize(node);
drawableNodes.Add(nodeData);
}
var drawableEdges = new List<EdgeDrawData>();
foreach (var addedNode in drawableNodes)
{
var baseNode = addedNode.node;
foreach (var slot in baseNode.GetOutputSlots<ISlot>())
{
var sourceAnchors = addedNode.elements.OfType<AnchorDrawData>();
var sourceAnchor = sourceAnchors.FirstOrDefault(x => x.slot == slot);
var edges = baseNode.owner.GetEdges(new SlotReference(baseNode.guid, slot.id));
foreach (var edge in edges)
{
var toNode = baseNode.owner.GetNodeFromGuid(edge.inputSlot.nodeGuid);
var toSlot = toNode.FindInputSlot<ISlot>(edge.inputSlot.slotId);
var targetNode = drawableNodes.FirstOrDefault(x => x.node == toNode);
var targetAnchors = targetNode.elements.OfType<AnchorDrawData>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == toSlot);
var edgeData = ScriptableObject.CreateInstance<EdgeDrawData>();
edgeData.Initialize(edge);
edgeData.left = sourceAnchor;
edgeData.right = targetAnchor;
drawableEdges.Add(edgeData);
}
}
}
m_Elements.AddRange(drawableNodes.OfType<GraphElementData>());
m_Elements.AddRange(drawableEdges.OfType<GraphElementData>());
}
protected abstract void AddTypeMappings();
public void AddTypeMapping(Type node, Type drawData)
{
m_DataMapper[node] = drawData;
}
public virtual void Initialize(IGraphAsset graphAsset)
{
m_DataMapper.Clear();
AddTypeMappings();
this.graphAsset = graphAsset;
if (graphAsset == null)
return;
UpdateData();
}
protected AbstractGraphDataSource()
{}
public void AddNode(INode node)
{
graphAsset.graph.AddNode(node);
UpdateData();
}
public void RemoveElements(IEnumerable<MaterialNodeDrawData> nodes, IEnumerable<EdgeDrawData> edges)
{
graphAsset.graph.RemoveElements(nodes.Select(x => x.node), edges.Select(x => x.edge));
graphAsset.graph.ValidateGraph();
UpdateData();
}
public IEnumerable<GraphElementData> elements
{
get { return m_Elements; }
}
public void AddElement(GraphElementData element)
{
var edge = element as EdgeData;
if (edge.candidate == false)
{
var left = edge.left as AnchorDrawData;
var right = edge.right as AnchorDrawData;
if (left && right)
graphAsset.graph.Connect(left.slot.slotReference, right.slot.slotReference);
UpdateData();
return;
}
m_Elements.Add(element);
}
public void RemoveElement(GraphElementData element)
{
m_Elements.RemoveAll(x => x == element);
}
}
}

316
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs


using System;
using RMGUI.GraphView;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.RMGUI;
namespace UnityEditor.Graphing.Drawing
{
public abstract class AbstractGraphEditWindow<T> : EditorWindow, ISerializationCallbackReceiver where T : class, IGraphAsset
{
public RenderTexture rt;
[NonSerialized]
private T m_LastSelection;
[SerializeField]
private ScriptableObject m_LastSelectedGraphSerialized;
private bool shouldRepaint
{
get
{
return m_LastSelection != null && m_LastSelection.shouldRepaint;
}
}
protected GraphView graphView
{
get { return m_GraphView; }
}
private GraphView m_GraphView;
public virtual AbstractGraphDataSource CreateDataSource()
{
return CreateInstance<SerializedGraphDataSource>();
}
public virtual GraphView CreateGraphView()
{
return new SerializableGraphView();
}
void OnEnable()
{
m_GraphView = CreateGraphView();
m_GraphView.name = "Graph View";
var source = CreateDataSource();
source.Initialize(m_LastSelection);
m_GraphView.dataSource = source;
m_GraphView.StretchToParentSize();
windowRoot.AddChild(m_GraphView);
}
void OnDisable()
{
windowRoot.ClearChildren();
}
void Update()
{
if (shouldRepaint)
Repaint();
}
void OnSelectionChange()
{
if (Selection.activeObject == null || !EditorUtility.IsPersistent(Selection.activeObject))
return;
if (Selection.activeObject is ScriptableObject)
{
var selection = Selection.activeObject as T;
if (selection != m_LastSelection)
{
var graph = selection.graph;
graph.OnEnable();
graph.ValidateGraph();
m_LastSelection = selection;
var source = CreateDataSource();
source.Initialize(m_LastSelection);
m_GraphView.dataSource = source;
m_GraphView.StretchToParentSize();
Repaint();
}
}
}
/*
private void ConvertSelectionToSubGraph()
{
if (m_Canvas.dataSource == null)
return;
var dataSource = m_Canvas.dataSource as GraphDataSource;
if (dataSource == null)
return;
var asset = dataSource.graphAsset;
if (asset == null)
return;
var targetGraph = asset.graph;
if (targetGraph == null)
return;
if (!m_Canvas.selection.Any())
return;
var serialzied = CopySelected.SerializeSelectedElements(m_Canvas);
var deserialized = CopySelected.DeserializeSelectedElements(serialzied);
if (deserialized == null)
return;
string path = EditorUtility.SaveFilePanelInProject("Save subgraph", "New SubGraph", "ShaderSubGraph", "");
path = path.Replace(Application.dataPath, "Assets");
if (path.Length == 0)
return;
var graphAsset = CreateInstance<MaterialSubGraphAsset>();
graphAsset.name = Path.GetFileName(path);
graphAsset.PostCreate();
var graph = graphAsset.subGraph;
if (graphAsset.graph == null)
return;
var nodeGuidMap = new Dictionary<Guid, Guid>();
foreach (var node in deserialized.GetNodes<INode>())
{
var oldGuid = node.guid;
var newGuid = node.RewriteGuid();
nodeGuidMap[oldGuid] = newGuid;
graph.AddNode(node);
}
// remap outputs to the subgraph
var inputEdgeNeedsRemap = new List<IEdge>();
var outputEdgeNeedsRemap = new List<IEdge>();
foreach (var edge in deserialized.edges)
{
var outputSlot = edge.outputSlot;
var inputSlot = edge.inputSlot;
Guid remappedOutputNodeGuid;
Guid remappedInputNodeGuid;
var outputRemapExists = nodeGuidMap.TryGetValue(outputSlot.nodeGuid, out remappedOutputNodeGuid);
var inputRemapExists = nodeGuidMap.TryGetValue(inputSlot.nodeGuid, out remappedInputNodeGuid);
// pasting nice internal links!
if (outputRemapExists && inputRemapExists)
{
var outputSlotRef = new SlotReference(remappedOutputNodeGuid, outputSlot.slotId);
var inputSlotRef = new SlotReference(remappedInputNodeGuid, inputSlot.slotId);
graph.Connect(outputSlotRef, inputSlotRef);
}
// one edge needs to go to outside world
else if (outputRemapExists)
{
inputEdgeNeedsRemap.Add(edge);
}
else if (inputRemapExists)
{
outputEdgeNeedsRemap.Add(edge);
}
}
// we do a grouping here as the same output can
// point to multiple inputs
var uniqueOutputs = outputEdgeNeedsRemap.GroupBy(edge => edge.outputSlot);
var inputsNeedingConnection = new List<KeyValuePair<IEdge, IEdge>>();
foreach (var group in uniqueOutputs)
{
var inputNode = graph.inputNode;
var slotId = inputNode.AddSlot();
var outputSlotRef = new SlotReference(inputNode.guid, slotId);
foreach (var edge in group)
{
var newEdge = graph.Connect(outputSlotRef, new SlotReference(nodeGuidMap[edge.inputSlot.nodeGuid], edge.inputSlot.slotId));
inputsNeedingConnection.Add(new KeyValuePair<IEdge, IEdge>(edge, newEdge));
}
}
var uniqueInputs = inputEdgeNeedsRemap.GroupBy(edge => edge.inputSlot);
var outputsNeedingConnection = new List<KeyValuePair<IEdge, IEdge>>();
foreach (var group in uniqueInputs)
{
var outputNode = graph.outputNode;
var slotId = outputNode.AddSlot();
var inputSlotRef = new SlotReference(outputNode.guid, slotId);
foreach (var edge in group)
{
var newEdge = graph.Connect(new SlotReference(nodeGuidMap[edge.outputSlot.nodeGuid], edge.outputSlot.slotId), inputSlotRef);
outputsNeedingConnection.Add(new KeyValuePair<IEdge, IEdge>(edge, newEdge));
}
}
AssetDatabase.CreateAsset(graphAsset, path);
var subGraphNode = new SubGraphNode();
targetGraph.AddNode(subGraphNode);
subGraphNode.subGraphAsset = graphAsset;
foreach (var edgeMap in inputsNeedingConnection)
{
targetGraph.Connect(edgeMap.Key.outputSlot, new SlotReference(subGraphNode.guid, edgeMap.Value.outputSlot.slotId));
}
foreach (var edgeMap in outputsNeedingConnection)
{
targetGraph.Connect(new SlotReference(subGraphNode.guid, edgeMap.Value.inputSlot.slotId), edgeMap.Key.inputSlot);
}
var toDelete = m_Canvas.selection.Where(x => x is DrawableNode).ToList();
dataSource.DeleteElements(toDelete);
targetGraph.ValidateGraph();
m_Canvas.ReloadData();
m_Canvas.Invalidate();
m_Canvas.selection.Clear();
var toSelect = m_Canvas.elements.OfType<DrawableNode>().FirstOrDefault(x => x.m_Node == subGraphNode);
if (toSelect != null)
{
toSelect.selected = true;
m_Canvas.selection.Add(toSelect);
}
m_Canvas.Repaint();
}
private void Rebuild()
{
if (m_Canvas == null || m_LastSelection == null)
return;
m_DataSource.graphAsset = m_LastSelection;
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));
if (GUI.Button(new Rect(position.width - 250, 0, 250, 50), "Convert to Sub-Graph"))
ConvertSelectionToSubGraph();
if (GUI.Button(new Rect(position.width - 250, 70, 250, 50), "Export"))
Export(false);
if (GUI.Button(new Rect(position.width - 250, 140, 250, 50), "Export - quick"))
Export(true);
EditorGUI.ObjectField(new Rect(position.width - 250, 210, 250, 50), rt, typeof(RenderTexture), false);
}*/
/*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 void OnBeforeSerialize()
{
var o = m_LastSelection as ScriptableObject;
if (o != null)
m_LastSelectedGraphSerialized = o;
}
public void OnAfterDeserialize()
{
if (m_LastSelectedGraphSerialized != null)
m_LastSelection = m_LastSelectedGraphSerialized as T;
m_LastSelectedGraphSerialized = null;
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs.meta


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

9
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData.meta


fileFormatVersion: 2
guid: 4e974459130fa5f4f9899e83b1e752d5
folderAsset: yes
timeCreated: 1476708485
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer.meta


fileFormatVersion: 2
guid: 8aa4176733f149446bd0c55036656e30
folderAsset: yes
timeCreated: 1476708981
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

45
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs


using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
using RMGUI.GraphView.Demo;
using UnityEditor.MaterialGraph.Drawing;
using UnityEngine;
using UnityEngine.RMGUI;
namespace UnityEditor.Graphing.Drawing
{
[StyleSheet("Assets/UnityShaderEditor/Editor/Styles/NodalView.uss")]
public class SerializableGraphView : GraphView
{
public SerializableGraphView()
{
// Shortcut handler to delete elements
var dictionary = new Dictionary<Event, ShortcutDelegate>();
dictionary[Event.KeyboardEvent("delete")] = DeleteSelection;
contentViewContainer.AddManipulator(new ShortcutHandler(dictionary));
AddManipulator(new ContentZoomer());
AddManipulator(new ContentDragger());
AddManipulator(new RectangleSelector());
AddManipulator(new SelectionDragger());
AddManipulator(new ClickSelector());
AddDecorator(new GridBackground());
dataMapper[typeof(NodeDrawData)] = typeof(NodeDrawer);
}
private EventPropagation DeleteSelection()
{
var nodalViewData = dataSource as AbstractGraphDataSource;
if (nodalViewData == null)
return EventPropagation.Stop;
nodalViewData.RemoveElements(
selection.OfType<MaterialNodeDrawer>().Select(x => x.dataProvider as MaterialNodeDrawData),
selection.OfType<RMGUI.GraphView.Edge>().Select(x => x.dataProvider as EdgeDrawData)
);
return EventPropagation.Stop;
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs.meta


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

15
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphDataSource.cs


using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
public class SerializedGraphDataSource : AbstractGraphDataSource
{
protected SerializedGraphDataSource()
{ }
protected override void AddTypeMappings()
{
AddTypeMapping(typeof(SerializableNode), typeof(NodeDrawData));
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphDataSource.cs.meta


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

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer.meta


fileFormatVersion: 2
guid: 7887abd697bcde24596ec729cd7e3c3e
folderAsset: yes
timeCreated: 1476708485
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

91
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs


using System;
using System.Reflection;
using RMGUI.GraphView;
using RMGUI.GraphView.Demo;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
using UnityEngine.RMGUI;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph.Drawing
{
[StyleSheet("Assets/UnityShaderEditor/Editor/Styles/NodalView.uss")]
public class MaterialGraphView : SerializableGraphView
{
public MaterialGraphView()
{
AddManipulator(new ContextualMenu(DoContextMenu));
dataMapper[typeof(MaterialNodeDrawData)] = typeof(MaterialNodeDrawer);
dataMapper[typeof(NodeAnchorData)] = typeof(NodeAnchor);
dataMapper[typeof(EdgeData)] = typeof(RMGUI.GraphView.Edge);
}
public virtual bool CanAddToNodeMenu(Type type)
{
return true;
}
protected EventPropagation DoContextMenu(Event evt, 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, evt.mousePosition));
}
}
}
//gm.AddSeparator("");
// gm.AddItem(new GUIContent("Convert To/SubGraph"), true, ConvertSelectionToSubGraph);
gm.ShowAsContext();
return EventPropagation.Stop;
}
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) as INode;
}
catch (Exception e)
{
Debug.LogWarningFormat("Could not construct instance of: {0} - {1}", posObj.m_Type, e);
return;
}
if (node == null)
return;
var drawstate = node.drawState;
drawstate.position = new Rect(posObj.m_Pos.x, posObj.m_Pos.y, 0, 0);
node.drawState = drawstate;
var graphDataSource = dataSource as AbstractGraphDataSource;
graphDataSource.AddNode(node);
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs.meta


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

25
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/AnchorDrawData.cs


using System;
using RMGUI.GraphView;
using RMGUI.GraphView.Demo;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
[Serializable]
public class AnchorDrawData : NodeAnchorData
{
protected AnchorDrawData()
{}
public ISlot slot { get; private set; }
public void Initialize(ISlot slot)
{
this.slot = slot;
name = slot.displayName;
type = typeof(Vector4);
direction = slot.isInputSlot ? Direction.Input : Direction.Output;
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/AnchorDrawData.cs.meta


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

31
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/ControlDrawData.cs


using System;
using RMGUI.GraphView;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
[Serializable]
public abstract class ControlDrawData : GraphElementData
{
public INode node { get; private set; }
protected ControlDrawData()
{}
public void Initialize(INode inNode)
{
node = inNode;
}
public virtual void OnGUIHandler()
{
if (node == null)
return;
GUIUtility.GetControlID(node.guid.GetHashCode(), FocusType.Passive);
}
public abstract float GetHeight();
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/ControlDrawData.cs.meta


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

19
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/EdgeDrawData.cs


using System;
using RMGUI.GraphView;
namespace UnityEditor.Graphing.Drawing
{
[Serializable]
public class EdgeDrawData : EdgeData
{
protected EdgeDrawData()
{}
public UnityEngine.Graphing.IEdge edge { get; private set; }
public void Initialize(UnityEngine.Graphing.IEdge inEdge)
{
edge = inEdge;
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/EdgeDrawData.cs.meta


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

68
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs


using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
public class NodeDrawData : GraphElementData
{
protected NodeDrawData()
{}
public INode node { get; private set; }
protected List<GraphElementData> m_Children = new List<GraphElementData>();
public override IEnumerable<GraphElementData> elements
{
get { return m_Children; }
}
//TODO: Kill this and the function below after talking with shanti
[SerializeField]
private int m_SerializationRandom;
public void MarkDirtyHack()
{
m_SerializationRandom++;
}
public override void CommitChanges()
{
base.CommitChanges();
var drawData = node.drawState;
drawData.position = position;
node.drawState = drawData;
}
protected virtual IEnumerable<GraphElementData> GetControlData()
{
return new ControlDrawData[0];
}
public virtual void Initialize(INode inNode)
{
node = inNode;
capabilities |= Capabilities.Movable;
if (node == null)
return;
name = inNode.name;
foreach (var input in node.GetSlots<ISlot>())
{
var data = CreateInstance<AnchorDrawData>();
data.Initialize(input);
m_Children.Add(data);
}
var controlData = GetControlData();
m_Children.AddRange(controlData);
position = new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0);
//position
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs.meta


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

116
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs


using System.Linq;
using RMGUI.GraphView;
using RMGUI.GraphView.Demo;
using UnityEditor.MaterialGraph.Drawing;
using UnityEngine;
using UnityEngine.RMGUI;
namespace UnityEditor.Graphing.Drawing
{
[GUISkinStyle("window")]
public class NodeDrawer : GraphElement
{
VisualContainer m_SlotContainer;
VisualContainer m_ControlsContainer;
public NodeDrawer()
{
content = new GUIContent("");
m_SlotContainer = new VisualContainer
{
name = "slots", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_ControlsContainer = new VisualContainer
{
name = "controls", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
}
public override void DoRepaint(PaintContext painter)
{
base.DoRepaint(painter);
if (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected)
{
painter.DrawRectangleOutline(transform, position, Color.yellow);
}
}
private void AddSlots(MaterialNodeDrawData nodeData)
{
m_SlotContainer.ClearChildren();
if (!nodeData.elements.OfType<NodeAnchorData>().Any())
return;
var inputs = new VisualContainer
{
name = "input", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_SlotContainer.AddChild(inputs);
// put a spacer here?
//m_SlotContainer.AddChild(new f);
var outputs = new VisualContainer
{
name = "output", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_SlotContainer.AddChild(outputs);
content = new GUIContent(nodeData.name);
foreach (var anchor in nodeData.elements.OfType<NodeAnchorData>())
{
if (anchor.direction == Direction.Input)
inputs.AddChild(new NodeAnchor(anchor));
else
outputs.AddChild(new NodeAnchor(anchor));
}
AddChild(m_SlotContainer);
}
private void AddControls(MaterialNodeDrawData nodeData)
{
m_ControlsContainer.ClearChildren();
if (!nodeData.elements.OfType<ControlDrawData>().Any())
return;
foreach (var controlData in nodeData.elements.OfType<ControlDrawData>())
{
var imContainer = new IMGUIContainer
{
name = "element",
OnGUIHandler = controlData.OnGUIHandler,
pickingMode = PickingMode.Position,
height = controlData.GetHeight(),
};
m_ControlsContainer.AddChild(imContainer);
}
AddChild(m_ControlsContainer);
}
public override void OnDataChanged()
{
base.OnDataChanged();
ClearChildren();
m_ControlsContainer.ClearChildren();
var nodeData = dataProvider as MaterialNodeDrawData;
if (nodeData == null)
return;
AddSlots(nodeData);
AddControls(nodeData);
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs.meta


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

38
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/ColorNodeDrawData.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class ContolDrawDrawData : ControlDrawData
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as UnityEngine.MaterialGraph.ColorNode;
if (cNode == null)
return;
cNode.color = EditorGUILayout.ColorField("Color", cNode.color);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class ColorNodeDrawData : MaterialNodeDrawData
{
protected override IEnumerable<GraphElementData> GetControlData()
{
var instance = CreateInstance<ContolDrawDrawData>();
instance.Initialize(node);
return new List<GraphElementData> { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/ColorNodeDrawData.cs.meta


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

18
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs


using UnityEditor.Graphing.Drawing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
public class MaterialGraphDataSource : AbstractGraphDataSource
{
protected MaterialGraphDataSource()
{}
protected override void AddTypeMappings()
{
AddTypeMapping(typeof(AbstractMaterialNode), typeof(MaterialNodeDrawData));
AddTypeMapping(typeof(ColorNode), typeof(ColorNodeDrawData));
AddTypeMapping(typeof(TextureNode), typeof(TextureNodeDrawData));
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs.meta


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

36
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialNodeDrawData.cs


using System;
using UnityEditor.Graphing.Drawing;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
public class MaterialNodeDrawData : NodeDrawData
{
public bool requiresTime
{
get { return node is IRequiresTime; }
}
protected MaterialNodeDrawData()
{}
public override void Initialize(INode inNode)
{
base.Initialize(inNode);
AddPreview(inNode);
}
private void AddPreview(INode inNode)
{
var materialNode = inNode as AbstractMaterialNode;
if (materialNode == null || !materialNode.hasPreview)
return;
var previewData = CreateInstance<NodePreviewDrawData>();
previewData.Initialize(materialNode);
m_Children.Add(previewData);
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialNodeDrawData.cs.meta


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

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodeDrawers.7z


7z��'�$�"
#$�~":��V�N�q$P�ߩ7G�*�~�oO��� ��N�1`�w�+���k=�0wJ���{X<P��i�,�������N*�d�=u�J6X� �MK��YW���N�Z�s<��22q@dJ�»Ps� !���u�Y��}��^A�8?���Ȩ�B�Cd��g�0-~�|8��e6̣i�T�s�M!�囖.R��?�<;p'�OM����ò""W)C���G�������98~[�m]x��wY �c2I�������F�/�jy8p�����m�=�?xE�%O�t��칂f�%oS8�W�᪗=Iכ���K��R7U�����UlS�-;�,�C3N�r��1g�.uf��Ng.��l,1 �o�b����s���2s��t����$�o��~�Lp,pT'UWWz!�|e�jO��� �vϦ�Z,��?�)���ٳ-��#�HЦ��⁃�Lql����������:��!_o!j槨�_VJ���'�6I���p^'aI:���EL���SV����@N��~������S�i�S;�O,;.��*�*�w�i�~*'�������p蕿�9�b&���Gۿ��I2m�gi�u���|�͏iB1��WAǧ�����6T�����Fk��� �c��"�9MM�*��" Ci��t�� H����{��A�P���&�qó�� ~m�{��v�����w2���Hc%%����H��{����gC�a ����zT�~��g��;Ŷ^ �Ec���Ǧ����)s�$K����( ׳��!�x���\��i:��ѡ&A�F$����Y�K�_���W�|���|��D��ՃT;�Aє���o�%Q��}�����LAQJ5�7�sTQ$*����!�b��4E�F�Kׯ-McR�3{����/��RV{���<J�ʀL����V����%L���fT���q�P��>�#���tswX=�AW���Lr�^�~|%I ��|�\O���_2O�_JD궟@�U>���$e����Up�Z���.���Ho����7�������tc�ASn׺��a�A��S a�����D�U[K�:"�ͩSZrliӥ�AN�p�m0& :xZ���q����@LK\�k%Q�<T� 8��o�4�ʣf�L&��ׂʾ03 ����}ӝd"��L%0���B5]���v67]��A^xx8���t�cG��2^6pDQ�N�w�]��K�H'�w �C�:0\��ʍ�sk�n"�N1�^9��K� ]θ��b~��7z���׺��]ٜ��عos�Y����$��8�����`JLY�˽�kOG���]=|�٭OC�0`*
���4���vv>*��5��%�7!��]JщȻUӽ�SH`C��J�}��n����ࡕZ�r�b�T SQ�ՒA��ވ�`�;XD�W5�_�x�X�~M�I)��U�2�rb�E���:%�c}m������xsk�ⵖ�+
]�3{ђ����=h?J�t�,v~{��"٦�xZܝӖ0 ܖ�]�\�c�vD�=}�ZlN��Z������Wi��|s�{�ۿt�A�HW*Qv@����}=�&��V$���W������g��p�Hk.���S�3i��8U suM�� 79��<�|� �dLn9���Qr9��Un�L��`|=�1s����^N �I�3b��y�� ^�ŝ0�ZY��ܧ/X��' k��u��=-nLz�����d�G��X.0�b����bą2Nov y[Q��B2��[<i�GP5/뻻ꀄk7�kK�T��E �U�ǡ~@a�ԣD!�������hg/�7��Yj�Y6/,:��]�D!9#�9��2��K������W6��A���Y�v�E�j�+p"��U?���1#���$ :5�s�LNr�Ap!�~?�r�bl�k[����L��r-_� U���#� ���b�� ;<ȣ����}0dg�yMd�Jy���$J�B�o|T ��%@�_ �jC�'X!���o��l����B���a���0.
l+ �M�ݪC_�AtzU�z�+��Iv� �����0��X�� 3�(57�z�_y��F�!�5�{���=�
��L�!�!���g�bC~7,�V���<����ZP4��A�8y�����h�dݴXc����D�;4SNָ�������U�#v�!p�4��3�Շ���l)H+A2h��M�z�@�";Km�,������
>=�̨���%�4.�n�7hm,S��+^��ۊb�L�,�]*s���k�n�&Y�~��cΆr��mOk�r� �ff���Q�ԓ � x�Ć[t��q�&�0�@G�`� Ӥ�iLie�X�AE0�O�9�Z�5�Ż��E��<fCIJ��1la]qCcu�6�_ھ�8A�niy �r3�y,�+����~��ZQ:�)��=��7�f
0���.w�U��c]BnM% �6���Ն���Y�8mDH�e%�5zX�$�:~Dž��p"�Ŝ6ɴ���AB(���J�0��J.n �\x
[q]�S���T�$hN��W���^ �x�#݋*�\�u���������"�%U���. 6�$M˴�;�� �� #] ��
��$

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodeDrawers.7z.meta


fileFormatVersion: 2
guid: bde27ac8743925a4dbb92de71afc2e31
timeCreated: 1475825200
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodePreviewDrawData.cs.meta


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

52
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/TextureNodeDrawData.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class ContolDrawData : ControlDrawData
{
private string[] m_TextureTypeNames;
private string[] textureTypeNames
{
get
{
if (m_TextureTypeNames == null)
m_TextureTypeNames = Enum.GetNames(typeof(TextureType));
return m_TextureTypeNames;
}
}
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.TextureNode;
if (tNode == null)
return;
tNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), tNode.exposedState);
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture2D), null) as Texture2D;
tNode.textureType = (TextureType)EditorGUILayout.Popup((int)tNode.textureType, textureTypeNames, EditorStyles.popup);
}
public override float GetHeight()
{
return 3 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class TextureNodeDrawData : MaterialNodeDrawData
{
protected override IEnumerable<GraphElementData> GetControlData()
{
var instance = CreateInstance<ContolDrawData>();
instance.Initialize(node);
return new List<GraphElementData> { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/TextureNodeDrawData.cs.meta


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

95
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.RMGUI;
namespace UnityEditor.MaterialGraph.Drawing
{
[GUISkinStyle("window")]
public class MaterialNodeDrawer : NodeDrawer
{
VisualContainer m_PreviewContainer;
private List<NodePreviewDrawData> m_currentPreviewData;
public MaterialNodeDrawer()
{
m_PreviewContainer = new VisualContainer
{
name = "preview", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_currentPreviewData = new List<NodePreviewDrawData>();
}
private void AddPreview(MaterialNodeDrawData nodeData)
{
if (!nodeData.elements.OfType<NodePreviewDrawData>().Any())
return;
var previews = nodeData.elements.OfType<NodePreviewDrawData>().ToList();
var isSamePreviews = m_currentPreviewData.Count == previews.Count;
if (isSamePreviews)
{
for (int i = 0; i < previews.Count; i++)
{
if (!ReferenceEquals(previews[i], m_currentPreviewData[i]))
{
isSamePreviews = false;
break;
}
}
}
if (isSamePreviews)
{
for (int i = 0; i < previews.Count; i++)
{
var preview = previews[i];
var thePreview = m_PreviewContainer.GetChildAtIndex(i) as Image;
// TODO: Consider null exception
// TODO: Need to share the texture
// right now it's allocating all the time.
thePreview.image = preview.Render(new Vector2(200, 200));
}
}
else
{
m_PreviewContainer.ClearChildren();
m_currentPreviewData.Clear();
foreach (var preview in previews)
{
var image = preview.Render(new Vector2(200, 200));
var thePreview = new Image
{
image = image,
name = "image"
};
m_PreviewContainer.AddChild(thePreview);
m_currentPreviewData.Add(preview);
}
}
AddChild(m_PreviewContainer);
}
public override void OnDataChanged()
{
base.OnDataChanged();
var nodeData = dataProvider as MaterialNodeDrawData;
if (nodeData == null)
return;
AddPreview(nodeData);
/*positionType = PositionType.Absolute;
positionLeft = nodeData.node.drawState.position.x;
positionTop = nodeData.node.drawState.position.y;*/
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs.meta


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

210
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs


using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
/*
namespace UnityEditor.Graphing.Drawing
{
public class DrawableNode : CanvasElement
{
private readonly GraphDataSource m_Data;
private readonly Rect m_CustomUiRect;
public readonly INode m_Node;
private readonly ICustomNodeUi m_Ui;
private const int kDefaultWidth = 200;
public DrawableNode(INode node, ICustomNodeUi ui, GraphDataSource data)
{
var drawData = node.drawState;
translation = drawData.position.min;
var width = ui != null ? ui.GetNodeWidth() : kDefaultWidth;
scale = new Vector2(width, width);
m_Node = node;
m_Ui = ui;
m_Data = data;
const float yStart = 10.0f;
var vector3 = new Vector3(5.0f, yStart, 0.0f);
Vector3 pos = vector3;
// input slots
foreach (var slot in node.GetInputSlots<ISlot>().OrderBy(x => x.priority))
{
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;
bool first = true;
foreach (var slot in node.GetOutputSlots<ISlot>().OrderBy(x => x.priority).ThenBy(x => x.id))
{
var edges = node.owner.GetEdges(node.GetSlotReference(slot.id));
// don't show empty output slots in collapsed mode
if (!node.drawState.expanded && !edges.Any() && !first)
continue;
pos.y += 22;
AddChild(new NodeAnchor(pos, typeof(Vector4), node, slot, data, Direction.Output));
first = false;
}
pos.y += 22;
pos.y = Mathf.Max(pos.y, inputYMax);
if (ui != null)
{
var customUiHeight = ui.GetNodeUiHeight(width);
m_CustomUiRect = new Rect(10, pos.y, width - 20, customUiHeight);
pos.y += customUiHeight;
}
scale = new Vector3(pos.x, pos.y + 10.0f, 0.0f);
OnWidget += InvalidateUIIfNeedsTime;
AddManipulator(new ImguiContainer());
AddManipulator(new Draggable());
}
private bool InvalidateUIIfNeedsTime(CanvasElement element, Event e, Canvas2D parent)
{
var childrenNodes = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(childrenNodes, m_Node);
if (childrenNodes.OfType<IRequiresTime>().Any())
Invalidate();
ListPool<INode>.Release(childrenNodes);
return true;
}
public override void UpdateModel(UpdateType t)
{
base.UpdateModel(t);
var drawState = m_Node.drawState;
var pos = drawState.position;
pos.min = translation;
drawState.position = pos;
m_Node.drawState = drawState;
}
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);
var drawState = m_Node.drawState;
if (GUI.Button(new Rect(scale.x - 20f, 3f, 14f, 14f), drawState.expanded ? "-" : "+"))
{
drawState.expanded = !drawState.expanded;
m_Node.drawState = drawState;
ParentCanvas().ReloadData();
ParentCanvas().Repaint();
return;
}
if (m_Ui != null)
{
var modificationType = m_Ui.Render(m_CustomUiRect);
if (modificationType != GUIModificationType.None)
m_Data.MarkDirty();
if (modificationType == GUIModificationType.ModelChanged)
{
m_Node.owner.ValidateGraph();
ParentCanvas().Invalidate();
ParentCanvas().ReloadData();
ParentCanvas().Repaint();
return;
}
if (modificationType == GUIModificationType.DataChanged)
{
ValidateDependentNodes(m_Node);
RepaintDependentNodes(m_Node);
}
else if (modificationType == GUIModificationType.Repaint)
{
// if we were changed, we need to redraw all the
// dependent nodes.
RepaintDependentNodes(m_Node);
}
}
base.Render(parentRect, canvas);
}
private void RepaintDependentNodes(INode theNode)
{
var dependentNodes = new List<INode>();
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, theNode);
foreach (var node in dependentNodes)
{
foreach (var drawableNode in m_Data.lastGeneratedNodes.Where(x => x.m_Node == node))
drawableNode.Invalidate();
}
}
private void ValidateDependentNodes(INode theNode)
{
var dependentNodes = new List<INode>();
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, theNode);
foreach (var node in dependentNodes)
node.ValidateNode();
}
/*
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);
}
}*/
/* public virtual GUIModificationType NodeUI(Rect drawArea)
{
return GUIModificationType.None;
}
public virtual bool OnGUI()
{
GUILayout.Label("MaterialSlot Defaults", EditorStyles.boldLabel);
var modified = false;
foreach (var slot in inputSlots)
{
if (!owner.GetEdges(GetSlotReference(slot.name)).Any())
modified |= DoSlotUI(this, slot);
}
return modified;
}
public static bool DoSlotUI(SerializableNode node, ISlot slot)
{
GUILayout.BeginHorizontal( /*EditorStyles.inspectorBig*);
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.Label("MaterialSlot " + slot.name, EditorStyles.largeLabel);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.EndHorizontal();
//TODO: fix this
return false;
//return slot.OnGUI();
}*
}
}*/

12
MaterialGraphProject/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:

242
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
[AttributeUsage(AttributeTargets.Class)]
sealed class CustomNodeUI : Attribute
{
private Type m_ModeToDrawFor;
public CustomNodeUI(Type nodeToDrawFor)
{
m_ModeToDrawFor = nodeToDrawFor;
}
public Type nodeToDrawFor
{
get { return m_ModeToDrawFor; } }
}
/*
public class GraphDataSource : ICanvasDataSource
{
readonly List<DrawableNode> m_DrawableNodes = new List<DrawableNode>();
public IGraphAsset graphAsset { get; set; }
public ICollection<DrawableNode> lastGeneratedNodes
{
get { return m_DrawableNodes; }
}
private static Type[] GetTypesFromAssembly(Assembly assembly)
{
if (assembly == null)
return new Type[] {};
try
{
return assembly.GetTypes();
}
catch (ReflectionTypeLoadException)
{
return new Type[] {};
}
}
private static Dictionary<Type, Type> s_DrawerUI;
private static Dictionary<Type, Type> drawerUI
{
get
{
if (s_DrawerUI == null)
{
s_DrawerUI = new Dictionary<Type, Type>();
var loadedTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => GetTypesFromAssembly(x));
foreach (var type in loadedTypes)
{
var attribute = type.GetCustomAttributes(true).OfType<CustomNodeUI>().FirstOrDefault();
if (attribute != null && typeof(ICustomNodeUi).IsAssignableFrom(type))
s_DrawerUI.Add(attribute.nodeToDrawFor, type);
}
}
return s_DrawerUI;
}
}
public CanvasElement[] FetchElements()
{
m_DrawableNodes.Clear();
var graph = graphAsset.graph;
Debug.LogFormat("Trying to convert: {0}", graphAsset.graph);
foreach (var node in graph.GetNodes<INode>())
{
var nodeType = node.GetType();
Type draweruiType = null;
while (draweruiType == null && nodeType != null)
{
draweruiType = drawerUI.FirstOrDefault(x => x.Key == nodeType).Value;
nodeType = nodeType.BaseType;
}
ICustomNodeUi customUI = null;
if (draweruiType != null)
{
try
{
customUI = Activator.CreateInstance(draweruiType) as ICustomNodeUi;
customUI.node = node;
}
catch (Exception e)
{
Debug.LogWarningFormat("Could not construct instance of: {0} - {1}", draweruiType, e);
}
}
// add the nodes
m_DrawableNodes.Add(new DrawableNode(node, customUI, this));
}
// Add the edges now
var drawableEdges = new List<DrawableEdge<NodeAnchor>>();
foreach (var drawableMaterialNode in m_DrawableNodes)
{
var baseNode = drawableMaterialNode.m_Node;
foreach (var slot in baseNode.GetOutputSlots<ISlot>())
{
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.id));
foreach (var edge in edges)
{
var toNode = baseNode.owner.GetNodeFromGuid(edge.inputSlot.nodeGuid);
var toSlot = toNode.FindInputSlot<ISlot>(edge.inputSlot.slotId);
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 DrawableEdge<NodeAnchor>(edge, 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 graph = graphAsset.graph;
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<ISlot>(x.outputSlot.slotId) == e.Left.m_Slot
&& graph.GetNodeFromGuid(x.inputSlot.nodeGuid).FindInputSlot<ISlot>(x.inputSlot.slotId) == 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);
MarkDirty();
}
public void Connect(NodeAnchor a, NodeAnchor b)
{
var graph = graphAsset.graph;
graph.Connect(a.m_Node.GetSlotReference(a.m_Slot.id), b.m_Node.GetSlotReference(b.m_Slot.id));
MarkDirty();
}
public void Addnode(INode node)
{
var graph = graphAsset.graph;
graph.AddNode(node);
MarkDirty();
}
public void MarkDirty()
{
EditorUtility.SetDirty(graphAsset.GetScriptableObject());
}
/*
}
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();
}*
}*/
}

13
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/ICustomNodeUi.cs


using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
public interface ICustomNodeUi
{
float GetNodeUiHeight(float width);
GUIModificationType Render(Rect area);
INode node { get; set; }
float GetNodeWidth();
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/ICustomNodeUi.cs.meta


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

0
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/IGraphElementView.cs

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/IGraphElementView.cs.meta


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

149
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs


using System;
using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.Graphing.Drawing
{
[Serializable]
public class MaterialGraphDataSource : ScriptableObject, IGraphElementDataSource
{
[SerializeField]
private List<GraphElementData> m_Elements = new List<GraphElementData>();
private readonly Dictionary<Type, Type> m_DataMapper = new Dictionary<Type, Type>();
public IGraphAsset graphAsset { get; private set; }
void OnNodeChanged(INode inNode)
{
var dependentNodes = new List<INode>();
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, inNode);
foreach (var node in dependentNodes)
{
var theElements = m_Elements.OfType<MaterialNodeData>().ToList();
var found = theElements.Where(x => x.node.guid == node.guid).ToList();
foreach (var drawableNodeData in found)
drawableNodeData.MarkDirtyHack();
}
}
private void UpdateData()
{
m_Elements.Clear();
var drawableNodes = new List<MaterialNodeData>();
foreach (var node in graphAsset.graph.GetNodes<INode>())
{
var type = node.GetType ();
Type found = null;
while (type != null)
{
if (m_DataMapper.TryGetValue (type, out found))
break;
type = type.BaseType;
}
if (found == null)
found = typeof(MaterialNodeData);
var nodeData = (MaterialNodeData)CreateInstance(found);
node.onModified += OnNodeChanged;
nodeData.Initialize(node);
drawableNodes.Add(nodeData);
}
var drawableEdges = new List<MaterialEdgeData>();
foreach (var addedNode in drawableNodes)
{
var baseNode = addedNode.node;
foreach (var slot in baseNode.GetOutputSlots<ISlot>())
{
var sourceAnchors = addedNode.elements.OfType<MaterialNodeAnchorData>();
var sourceAnchor = sourceAnchors.FirstOrDefault(x => x.slot == slot);
var edges = baseNode.owner.GetEdges(new SlotReference(baseNode.guid, slot.id));
foreach (var edge in edges)
{
var toNode = baseNode.owner.GetNodeFromGuid(edge.inputSlot.nodeGuid);
var toSlot = toNode.FindInputSlot<ISlot>(edge.inputSlot.slotId);
var targetNode = drawableNodes.FirstOrDefault(x => x.node == toNode);
var targetAnchors = targetNode.elements.OfType<MaterialNodeAnchorData>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == toSlot);
var edgeData = ScriptableObject.CreateInstance<MaterialEdgeData>();
edgeData.Initialize (edge);
edgeData.left = sourceAnchor;
edgeData.right = targetAnchor;
drawableEdges.Add(edgeData);
}
}
}
m_Elements.AddRange(drawableNodes.OfType<GraphElementData>());
m_Elements.AddRange(drawableEdges.OfType<GraphElementData>());
}
public void Initialize(IGraphAsset graphAsset)
{
m_DataMapper.Clear ();
m_DataMapper [typeof(AbstractMaterialNode)] = typeof(MaterialNodeData);
m_DataMapper [typeof(ColorNode)] = typeof(ColorNodeData);
m_DataMapper [typeof(TextureNode)] = typeof(TextureNodeData);
this.graphAsset = graphAsset;
if (graphAsset == null)
return;
UpdateData();
}
protected MaterialGraphDataSource()
{ }
public void AddNode(INode node)
{
graphAsset.graph.AddNode(node);
UpdateData();
}
public void RemoveElements(IEnumerable<MaterialNodeData> nodes, IEnumerable<MaterialEdgeData> edges)
{
graphAsset.graph.RemoveElements(nodes.Select(x => x.node), edges.Select(x => x.edge));
graphAsset.graph.ValidateGraph();
UpdateData ();
}
public IEnumerable<GraphElementData> elements
{
get { return m_Elements; }
}
public void AddElement(GraphElementData element)
{
var edge = element as EdgeData;
if (edge.candidate == false)
{
var left = edge.left as MaterialNodeAnchorData;
var right = edge.right as MaterialNodeAnchorData;
if (left && right)
graphAsset.graph.Connect (left.slot.slotReference, right.slot.slotReference);
UpdateData ();
return;
}
m_Elements.Add(element);
}
public void RemoveElement(GraphElementData element)
{
m_Elements.RemoveAll(x => x == element);
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs.meta


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

34
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphElementView.cs


using RMGUI.GraphView;
using UnityEngine;
namespace UnityEditor.Graphing.Drawing
{
/*public class MaterialGraphElementView : IGraphElementView
{
private bool m_Selected;
public string name { get; set; }
public Capabilities capabilities { get; set; }
public Rect position { get; set; }
public bool selected
{
get { return m_Selected; }
set
{
// Set new value (toggle old value)
if ((capabilities & Capabilities.Selectable) == Capabilities.Selectable)
{
m_Selected = value;
}
}
}
protected void OnEnable()
{
capabilities = Capabilities.Normal | Capabilities.Movable | Capabilities.Selectable;
}
}*/
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphElementView.cs.meta


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

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphNode.cs.meta


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

118
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs


using System;
using System.Linq;
using System.Reflection;
using RMGUI.GraphView;
using RMGUI.GraphView.Demo;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
using UnityEngine.RMGUI;
using System.Collections.Generic;
using Object = UnityEngine.Object;
namespace UnityEditor.Graphing.Drawing
{
[StyleSheet("Assets/UnityShaderEditor/Editor/Styles/NodalView.uss")]
//[StyleSheet("Assets/UnityShaderEditor/Editor/Styles/MatGraph.uss")]
public class MaterialGraphView : GraphView
{
public MaterialGraphView()
{
// Shortcut handler to delete elements
var dictionary = new Dictionary<Event, ShortcutDelegate>();
dictionary[Event.KeyboardEvent("delete")] = DeleteSelection;
contentViewContainer.AddManipulator(new ShortcutHandler(dictionary));
AddManipulator(new ContentZoomer());
AddManipulator(new ContentDragger());
AddManipulator(new RectangleSelector());
AddManipulator(new SelectionDragger());
AddManipulator(new ClickSelector());
AddManipulator(new ContextualMenu(DoContextMenu));
AddDecorator(new GridBackground());
dataMapper[typeof(MaterialNodeData)] = typeof(MaterialGraphNode);
dataMapper[typeof(NodeAnchorData)] = typeof(NodeAnchor);
dataMapper[typeof(EdgeData)] = typeof(RMGUI.GraphView.Edge);
}
private EventPropagation DeleteSelection()
{
var nodalViewData = dataSource as MaterialGraphDataSource;
if (nodalViewData == null)
return EventPropagation.Stop;
nodalViewData.RemoveElements(
selection.OfType<MaterialGraphNode>().Select(x => x.dataProvider as MaterialNodeData),
selection.OfType<RMGUI.GraphView.Edge>().Select(x => x.dataProvider as MaterialEdgeData)
);
return EventPropagation.Stop;
}
public virtual bool CanAddToNodeMenu(Type type)
{
return true;
}
protected EventPropagation DoContextMenu(Event evt, 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, evt.mousePosition));
}
}
}
//gm.AddSeparator("");
// gm.AddItem(new GUIContent("Convert To/SubGraph"), true, ConvertSelectionToSubGraph);
gm.ShowAsContext();
return EventPropagation.Stop;
}
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) as INode;
}
catch (Exception e)
{
Debug.LogWarningFormat("Could not construct instance of: {0} - {1}", posObj.m_Type, e);
return;
}
if (node == null)
return;
var drawstate = node.drawState;
drawstate.position = new Rect(posObj.m_Pos.x, posObj.m_Pos.y, 0 , 0);
node.drawState = drawstate;
var graphDataSource = dataSource as MaterialGraphDataSource;
graphDataSource.AddNode(node);
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs.meta


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

160
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeData.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.MaterialGraph;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.Graphing.Drawing
{
class TextureNodeContolData : NodeControlData
{
private string[] m_TextureTypeNames;
private string[] textureTypeNames
{
get
{
if (m_TextureTypeNames == null)
m_TextureTypeNames = Enum.GetNames(typeof(TextureType));
return m_TextureTypeNames;
}
}
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.TextureNode;
if (tNode == null)
return;
tNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), tNode.exposedState);
tNode.defaultTexture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), tNode.defaultTexture, typeof(Texture2D), null) as Texture2D;
tNode.textureType = (TextureType)EditorGUILayout.Popup((int)tNode.textureType, textureTypeNames, EditorStyles.popup);
}
public override float GetHeight()
{
return 3 * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
class ColorNodeContolData : NodeControlData
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as UnityEngine.MaterialGraph.ColorNode;
if (cNode == null)
return;
cNode.color = EditorGUILayout.ColorField("Color", cNode.color);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class ColorNodeData : MaterialNodeData
{
protected override IEnumerable<GraphElementData> GetControlData()
{
var instance = CreateInstance<ColorNodeContolData>();
instance.Initialize(node);
return new List<GraphElementData> { instance };
}
}
[Serializable]
public class TextureNodeData : MaterialNodeData
{
protected override IEnumerable<GraphElementData> GetControlData()
{
var instance = CreateInstance<TextureNodeContolData>();
instance.Initialize(node);
return new List<GraphElementData> { instance };
}
}
[Serializable]
public class MaterialNodeData : GraphElementData
{
public INode node { get; private set; }
protected List<GraphElementData> m_Children = new List<GraphElementData>();
public override IEnumerable<GraphElementData> elements
{
get { return m_Children; }
}
protected MaterialNodeData()
{}
public override void CommitChanges()
{
base.CommitChanges();
var drawData = node.drawState;
drawData.position = position;
node.drawState = drawData;
}
//TODO: Kill this and the function below after talking with shanti
[SerializeField]
private int m_SerializationRandom;
public void MarkDirtyHack()
{
m_SerializationRandom++;
}
public void Initialize(INode inNode)
{
node = inNode;
capabilities |= Capabilities.Movable;
if (node == null)
return;
name = inNode.name;
foreach (var input in node.GetSlots<ISlot>())
{
var data = CreateInstance<MaterialNodeAnchorData>();
data.Initialize(input);
m_Children.Add(data);
}
AddPreview(inNode);
var controlData = GetControlData();
m_Children.AddRange(controlData);
position = new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0);
//position
}
private void AddPreview(INode inNode)
{
var materialNode = inNode as AbstractMaterialNode;
if (materialNode == null || !materialNode.hasPreview)
return;
var previewData = CreateInstance<NodePreviewData>();
previewData.Initialize(materialNode);
m_Children.Add(previewData);
}
protected virtual IEnumerable<GraphElementData> GetControlData()
{
return new NodeControlData[0];
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeData.cs.meta


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

40
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeAnchorData.cs


using System;
using RMGUI.GraphView;
using RMGUI.GraphView.Demo;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
[Serializable]
public class MaterialEdgeData : EdgeData
{
protected MaterialEdgeData()
{}
public UnityEngine.Graphing.IEdge edge { get; private set; }
public void Initialize(UnityEngine.Graphing.IEdge inEdge)
{
edge = inEdge;
}
}
[Serializable]
public class MaterialNodeAnchorData : NodeAnchorData
{
protected MaterialNodeAnchorData()
{}
public ISlot slot { get; private set; }
public void Initialize(ISlot slot)
{
this.slot = slot;
name = slot.displayName;
type = typeof(Vector4);
direction = slot.isInputSlot ? Direction.Input : Direction.Output;
}
}
}

12
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeAnchorData.cs.meta


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

188
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphNode.cs


using System.Collections.Generic;
using System.Linq;
using RMGUI.GraphView;
using RMGUI.GraphView.Demo;
using UnityEditor.MaterialGraph;
using UnityEngine;
using UnityEngine.RMGUI;
namespace UnityEditor.Graphing.Drawing
{
[GUISkinStyle("window")]
public class MaterialGraphNode : GraphElement
{
VisualContainer m_SlotContainer;
VisualContainer m_ControlsContainer;
VisualContainer m_PreviewContainer;
private List<NodePreviewData> m_currentPreviewData;
public MaterialGraphNode()
{
content = new GUIContent("");
m_SlotContainer = new VisualContainer
{
name = "slots", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_ControlsContainer = new VisualContainer
{
name = "controls", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_PreviewContainer = new VisualContainer
{
name = "preview", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_currentPreviewData = new List<NodePreviewData>();
}
public override void DoRepaint(PaintContext painter)
{
base.DoRepaint(painter);
if (GetData<GraphElementData>() != null && GetData<GraphElementData>().selected)
{
painter.DrawRectangleOutline(transform, position, Color.yellow);
}
}
private void AddSlots(MaterialNodeData nodeData)
{
m_SlotContainer.ClearChildren();
if (!nodeData.elements.OfType<NodeAnchorData>().Any())
return;
var inputs = new VisualContainer
{
name = "input", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_SlotContainer.AddChild(inputs);
// put a spacer here?
//m_SlotContainer.AddChild(new f);
var outputs = new VisualContainer
{
name = "output", // for USS&Flexbox
pickingMode = PickingMode.Ignore,
};
m_SlotContainer.AddChild(outputs);
content = new GUIContent(nodeData.name);
foreach (var anchor in nodeData.elements.OfType<NodeAnchorData>())
{
if (anchor.direction == Direction.Input)
inputs.AddChild(new NodeAnchor(anchor));
else
outputs.AddChild(new NodeAnchor(anchor));
}
AddChild(m_SlotContainer);
}
private void AddControls(MaterialNodeData nodeData)
{
m_ControlsContainer.ClearChildren();
if (!nodeData.elements.OfType<NodeControlData>().Any())
return;
foreach (var controlData in nodeData.elements.OfType<NodeControlData>())
{
var imContainer = new IMGUIContainer
{
name = "element",
OnGUIHandler = controlData.OnGUIHandler,
pickingMode = PickingMode.Position,
height = controlData.GetHeight(),
};
m_ControlsContainer.AddChild(imContainer);
}
AddChild(m_ControlsContainer);
}
private void AddPreview(MaterialNodeData nodeData)
{
if (!nodeData.elements.OfType<NodePreviewData>().Any())
return;
var previews = nodeData.elements.OfType<NodePreviewData>().ToList();
var isSamePreviews = m_currentPreviewData.Count == previews.Count;
if (isSamePreviews)
{
for (int i = 0; i < previews.Count; i++)
{
if (!ReferenceEquals(previews[i], m_currentPreviewData[i]))
{
isSamePreviews = false;
break;
}
}
}
if (isSamePreviews)
{
for (int i = 0; i < previews.Count; i++)
{
var preview = previews[i];
var thePreview = m_PreviewContainer.GetChildAtIndex(i) as Image;
// TODO: Consider null exception
// TODO: Need to share the texture
// right now it's allocating all the time.
thePreview.image = preview.Render(new Vector2(200, 200));
}
}
else
{
m_PreviewContainer.ClearChildren();
m_currentPreviewData.Clear();
foreach (var preview in previews)
{
var image = preview.Render(new Vector2(200, 200));
var thePreview = new Image
{
image = image,
name = "image"
};
m_PreviewContainer.AddChild(thePreview);
m_currentPreviewData.Add(preview);
}
}
AddChild(m_PreviewContainer);
}
public override void OnDataChanged()
{
base.OnDataChanged();
ClearChildren();
m_ControlsContainer.ClearChildren();
// m_PreviewContainer.ClearChildren();
var nodeData = dataProvider as MaterialNodeData;
if (nodeData == null)
return;
AddSlots(nodeData);
AddControls(nodeData);
AddPreview(nodeData);
/*positionType = PositionType.Absolute;
positionLeft = nodeData.node.drawState.position.x;
positionTop = nodeData.node.drawState.position.y;*/
}
}
}

64
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphStyles.cs


using UnityEngine;
namespace UnityEditor.MaterialGraph
{
public class MaterialGraphStyles
{
private static MaterialGraphStyles s_Styles;
private const float kHeadingSpace = 22.0f;
private readonly GUIStyle m_Header = "ShurikenModuleTitle";
private MaterialGraphStyles()
{
m_Header.font = (new GUIStyle("Label")).font;
m_Header.border = new RectOffset(15, 7, 4, 4);
m_Header.fixedHeight = kHeadingSpace;
m_Header.contentOffset = new Vector2(20f, -2f);
}
private static MaterialGraphStyles styles
{
get { return s_Styles ?? (s_Styles = new MaterialGraphStyles()); }
}
public static bool DoDrawDefaultInspector(SerializedObject obj)
{
EditorGUI.BeginChangeCheck();
obj.Update();
// Loop through properties and create one field (including children) for each top level property.
SerializedProperty property = obj.GetIterator();
bool expanded = true;
while (property.NextVisible(expanded))
{
EditorGUI.BeginDisabledGroup("m_Script" == property.propertyPath);
EditorGUILayout.PropertyField(property, true);
EditorGUI.EndDisabledGroup();
expanded = false;
}
obj.ApplyModifiedProperties();
return EditorGUI.EndChangeCheck();
}
public static bool Header(string title, bool display)
{
GUILayout.Box(title, styles.m_Header);
var rect = GUILayoutUtility.GetLastRect();
Rect toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f);
if (Event.current.type == EventType.Repaint)
EditorStyles.foldout.Draw(toggleRect, false, false, display, false);
Event e = Event.current;
if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition))
{
display = !display;
e.Use();
}
return display;
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphStyles.cs.meta


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

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


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

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs.meta → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/AbstractMaterialNodeUI.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodePreviewDrawData.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Editors/MaterialGraphEditor.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Editors/MaterialGraphEditor.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs

正在加载...
取消
保存