|
|
|
|
|
|
namespace UnityEditor.Graphing.Drawing |
|
|
|
{ |
|
|
|
[Serializable] |
|
|
|
public class MaterialGraphDataSource : IGraphElementDataSource |
|
|
|
public class MaterialGraphDataSource : ScriptableObject, IGraphElementDataSource |
|
|
|
[SerializeField] |
|
|
|
private List<GraphElementData> m_Elements = new List<GraphElementData>(); |
|
|
|
|
|
|
|
public IGraphAsset graphAsset { get; private set; } |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public MaterialGraphDataSource(IGraphAsset graphAsset) |
|
|
|
private void UpdateData() |
|
|
|
this.graphAsset = graphAsset; |
|
|
|
|
|
|
|
if (graphAsset == null) |
|
|
|
return; |
|
|
|
m_Elements.Clear(); |
|
|
|
|
|
|
|
var drawableNodes = new List<MaterialNodeData>(); |
|
|
|
foreach (var node in graphAsset.graph.GetNodes<INode>()) |
|
|
|
|
|
|
|
|
|
|
var targetAnchors = targetNode.elements.OfType<MaterialNodeAnchorData>(); |
|
|
|
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == toSlot); |
|
|
|
var edgeData = ScriptableObject.CreateInstance<EdgeData>(); |
|
|
|
edgeData.left = sourceAnchor; |
|
|
|
edgeData.right = targetAnchor; |
|
|
|
var edgeData = ScriptableObject.CreateInstance<EdgeData>(); |
|
|
|
edgeData.left = sourceAnchor; |
|
|
|
edgeData.right = targetAnchor; |
|
|
|
drawableEdges.Add(edgeData); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
m_Elements.AddRange(drawableEdges.OfType<GraphElementData>()); |
|
|
|
} |
|
|
|
|
|
|
|
public MaterialGraphDataSource(IGraphAsset graphAsset) |
|
|
|
{ |
|
|
|
this.graphAsset = graphAsset; |
|
|
|
|
|
|
|
if (graphAsset == null) |
|
|
|
return; |
|
|
|
|
|
|
|
UpdateData(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void AddNode(INode node) |
|
|
|
{ |
|
|
|
graphAsset.graph.AddNode(node); |
|
|
|
UpdateData(); |
|
|
|
} |
|
|
|
|
|
|
|
public IEnumerable<GraphElementData> elements |
|
|
|