Tim Cooper
8 年前
当前提交
1b049752
共有 98 个文件被更改,包括 1441 次插入 和 1814 次删除
-
5MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/CopySelected.cs
-
366MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs
-
2MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NullInputProxy.cs
-
2MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs.meta
-
84MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
-
16MaterialGraphProject/Assets/UnityShaderEditor/Editor/Styles/NodalView.uss
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/ShaderGenerationTest.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function2InputTests.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function3InputTests.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialSlotTests.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialOptions.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/BlendNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/CombineNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/DivNode.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/FunctionMultiInput.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LengthNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/LerpNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MultiplyNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/NormalizeNode.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PixelShaderNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PowerNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/QuantizeNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SinNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SmoothStepNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubtractNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SwizzleNode.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyGenerator.cs
-
48MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodePreviewDrawData.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs
-
154MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs
-
316MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs.meta
-
9MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData.meta
-
9MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer.meta
-
45MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs.meta
-
15MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphDataSource.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphDataSource.cs.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer.meta
-
91MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs.meta
-
25MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/AnchorDrawData.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/AnchorDrawData.cs.meta
-
31MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/ControlDrawData.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/ControlDrawData.cs.meta
-
19MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/EdgeDrawData.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/EdgeDrawData.cs.meta
-
68MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs.meta
-
116MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs.meta
-
38MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/ColorNodeDrawData.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/ColorNodeDrawData.cs.meta
-
18MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs.meta
-
36MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialNodeDrawData.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialNodeDrawData.cs.meta
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodeDrawers.7z
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodeDrawers.7z.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodePreviewDrawData.cs.meta
-
52MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/TextureNodeDrawData.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/TextureNodeDrawData.cs.meta
-
95MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs.meta
-
210MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs.meta
-
242MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs
-
13MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/ICustomNodeUi.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/ICustomNodeUi.cs.meta
-
0MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/IGraphElementView.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/IGraphElementView.cs.meta
-
149MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs.meta
-
34MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphElementView.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphElementView.cs.meta
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphNode.cs.meta
-
118MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs.meta
-
160MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeData.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeData.cs.meta
-
40MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeAnchorData.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeAnchorData.cs.meta
-
188MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphNode.cs
-
64MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphStyles.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphStyles.cs.meta
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Editors.meta
-
0/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphDataSource.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/NodePreviewDrawData.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.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); |
|||
} |
|||
} |
|||
} |
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 322c21863b8e2024e85c4f0e0dee0b94 |
|||
timeCreated: 1476711073 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 4e974459130fa5f4f9899e83b1e752d5 |
|||
folderAsset: yes |
|||
timeCreated: 1476708485 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 8aa4176733f149446bd0c55036656e30 |
|||
folderAsset: yes |
|||
timeCreated: 1476708981 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0f06001291d4e32479f71557abf52944 |
|||
timeCreated: 1476710182 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEditor.Graphing.Drawing |
|||
{ |
|||
public class SerializedGraphDataSource : AbstractGraphDataSource |
|||
{ |
|||
protected SerializedGraphDataSource() |
|||
{ } |
|||
|
|||
protected override void AddTypeMappings() |
|||
{ |
|||
AddTypeMapping(typeof(SerializableNode), typeof(NodeDrawData)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d7466f2e9546aaa409ea2125e36a0342 |
|||
timeCreated: 1476711073 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7887abd697bcde24596ec729cd7e3c3e |
|||
folderAsset: yes |
|||
timeCreated: 1476708485 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e0bbd4215e018eb4bbdb28bfaa7eabdd |
|||
timeCreated: 1476707367 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f04b4288b3bfba3408bdc318de3a50b1 |
|||
timeCreated: 1476707367 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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(); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 070b72651e4f90b478ca6f031541065e |
|||
timeCreated: 1476707366 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4b9ded26d428ffa49b4c9569437e5b49 |
|||
timeCreated: 1476708486 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f01062de38f2dd0408db6e9bdfb4f8cf |
|||
timeCreated: 1476708486 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 540ef3297c22e2945a07528a40ff101b |
|||
timeCreated: 1476708982 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9ea4884532b198441a14c69dae0a63f6 |
|||
timeCreated: 1476707367 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 90219f5b90369c545855e7aa23e4ae89 |
|||
timeCreated: 1476709521 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6d66b7c0ed7187d4f9ebae2c7f8d3167 |
|||
timeCreated: 1476707367 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
7z��' �$�" |
|||
|