浏览代码

[MaterialGraph]Add mapping between data base type and draw data type.

/main
Tim Cooper 8 年前
当前提交
a6b1e348
共有 2 个文件被更改,包括 34 次插入15 次删除
  1. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs
  2. 41
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs

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


{
m_Contents = new MaterialGraphView();
m_Contents.name = "theView";
m_Contents.dataSource = new MaterialGraphDataSource(m_LastSelection);
var source = CreateInstance<MaterialGraphDataSource>();
source.Initialize (m_LastSelection);
m_Contents.dataSource = source;
m_Contents.StretchToParentSize();
windowRoot.AddChild(m_Contents);

graph.ValidateGraph();
m_LastSelection = selection;
m_Contents.dataSource = new MaterialGraphDataSource(m_LastSelection);
var source = CreateInstance<MaterialGraphDataSource>();
source.Initialize (m_LastSelection);
m_Contents.dataSource = source;
m_Contents.StretchToParentSize();
Repaint();

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


[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)

foreach (var drawableNodeData in found)
drawableNodeData.MarkDirtyHack();
}
}
}
private void UpdateData()
{

foreach (var node in graphAsset.graph.GetNodes<INode>())
{
MaterialNodeData nodeData;
var type = node.GetType ();
if (node is ColorNode)
nodeData = ScriptableObject.CreateInstance<ColorNodeData>();
else
nodeData = ScriptableObject.CreateInstance<MaterialNodeData>();
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)ScriptableObject.CreateInstance(found);
node.onModified += OnNodeChanged;
nodeData.Initialize(node);

m_Elements.AddRange(drawableEdges.OfType<GraphElementData>());
}
public MaterialGraphDataSource(IGraphAsset graphAsset)
{
this.graphAsset = graphAsset;
public void Initialize(IGraphAsset graphAsset)
{
m_DataMapper.Clear ();
m_DataMapper [typeof(AbstractMaterialNode)] = typeof(MaterialNodeData);
m_DataMapper [typeof(ColorNode)] = typeof(ColorNodeData);
if (graphAsset == null)
return;
this.graphAsset = graphAsset;
UpdateData();
}
if (graphAsset == null)
return;
UpdateData();
}
protected MaterialGraphDataSource()
{ }
public void AddNode(INode node)
{

正在加载...
取消
保存