浏览代码

allow adding nodes again.

/main
Tim Cooper 8 年前
当前提交
66cea910
共有 2 个文件被更改,包括 27 次插入12 次删除
  1. 33
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs
  2. 6
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs

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


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

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


var drawstate = node.drawState;
drawstate.position = new Rect(posObj.m_Pos.x, posObj.m_Pos.y, 0 , 0);
node.drawState = drawstate;
/*m_DataSource.Addnode(node);
Rebuild();
Repaint();*/
var graphDataSource = dataSource as MaterialGraphDataSource;
graphDataSource.AddNode(node);
}
}
}
正在加载...
取消
保存