浏览代码

Merge pull request #359 from Unity-Technologies/node-placement-copy

Node placement copy
/main
GitHub 7 年前
当前提交
36539f3e
共有 5 个文件被更改,包括 62 次插入10 次删除
  1. 1
      CHANGELOG.md
  2. 5
      com.unity.shadergraph/Editor/Data/Graphs/SerializableGuid.cs
  3. 1
      com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs
  4. 47
      com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs
  5. 18
      com.unity.shadergraph/Editor/Util/CopyPasteGraph.cs

1
CHANGELOG.md


- Fixed an issue where vector 1 node was not evaluating properly. ([#334](https://github.com/Unity-Technologies/ShaderGraph/issues/334) and [#337](https://github.com/Unity-Technologies/ShaderGraph/issues/337))
- Properties can now be copied and pasted.
- Pasting a property node into another graph will now convert it to a concrete node. ([#300](https://github.com/Unity-Technologies/ShaderGraph/issues/300))
- Make nodes that are copied from one graph to another spawn in the center of the current view. ([#333](https://github.com/Unity-Technologies/ShaderGraph/issues/333))

5
com.unity.shadergraph/Editor/Data/Graphs/SerializableGuid.cs


m_Guid = Guid.NewGuid();
}
public SerializableGuid(Guid guid)
{
m_Guid = guid;
}
[NonSerialized]
private Guid m_Guid;

1
com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs


var metaProperties = graphView.graph.properties.Where(x => propertyNodeGuids.Contains(x.guid));
var copyPasteGraph = new CopyPasteGraph(
graphView.graph.guid,
graphView.selection.OfType<MaterialNodeView>().Where(x => !(x.node is PropertyNode)).Select(x => x.node as INode),
graphView.selection.OfType<Edge>().Select(x => x.userData as IEdge),
graphView.selection.OfType<BlackboardField>().Select(x => x.userData as IShaderProperty),

47
com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs


var propertyNodeGuids = nodes.OfType<PropertyNode>().Select(x => x.propertyGuid);
var metaProperties = this.graph.properties.Where(x => propertyNodeGuids.Contains(x.guid));
var graph = new CopyPasteGraph(nodes, edges, properties, metaProperties);
var graph = new CopyPasteGraph(this.graph.guid, nodes, edges, properties, metaProperties);
return JsonUtility.ToJson(graph, true);
}

}
using (var remappedNodesDisposable = ListPool<INode>.GetDisposable())
{
if (graphView.graph.guid != copyGraph.sourceGraphGuid)
{
// Compute the mean of the copied nodes.
Vector2 centroid = Vector2.zero;
var count = 1;
foreach (var node in remappedNodes)
{
var position = node.drawState.position.position;
centroid = centroid + (position - centroid) / count;
++count;
}
// Get the center of the current view
var viewCenter = graphView.contentViewContainer.WorldToLocal(graphView.layout.center);
foreach (var node in remappedNodes)
{
var drawState = node.drawState;
var positionRect = drawState.position;
var position = positionRect.position;
position += viewCenter - centroid;
positionRect.position = position;
drawState.position = positionRect;
node.drawState = drawState;
}
}
{
var edge = element as Edge;
if (edge != null && remappedEdges.Contains(edge.userData as IEdge))
graphView.AddToSelection(edge);
{
var edge = element as Edge;
if (edge != null && remappedEdges.Contains(edge.userData as IEdge))
graphView.AddToSelection(edge);
var nodeView = element as MaterialNodeView;
if (nodeView != null && remappedNodes.Contains(nodeView.node))
graphView.AddToSelection(nodeView);
});
var nodeView = element as MaterialNodeView;
if (nodeView != null && remappedNodes.Contains(nodeView.node))
graphView.AddToSelection(nodeView);
});
}
}
}
}

18
com.unity.shadergraph/Editor/Util/CopyPasteGraph.cs


[NonSerialized]
HashSet<IShaderProperty> m_MetaProperties = new HashSet<IShaderProperty>();
[NonSerialized]
SerializableGuid m_SourceGraphGuid;
[SerializeField]
List<SerializationHelper.JSONSerializedElement> m_SerializableNodes = new List<SerializationHelper.JSONSerializedElement>();

[SerializeField]
List<SerializationHelper.JSONSerializedElement> m_SerializableMetaProperties = new List<SerializationHelper.JSONSerializedElement>();
[SerializeField]
SerializationHelper.JSONSerializedElement m_SerializeableSourceGraphGuid = new SerializationHelper.JSONSerializedElement();
public CopyPasteGraph(IEnumerable<INode> nodes, IEnumerable<IEdge> edges, IEnumerable<IShaderProperty> properties, IEnumerable<IShaderProperty> metaProperties)
public CopyPasteGraph(Guid sourceGraphGuid, IEnumerable<INode> nodes, IEnumerable<IEdge> edges, IEnumerable<IShaderProperty> properties, IEnumerable<IShaderProperty> metaProperties)
m_SourceGraphGuid = new SerializableGuid(sourceGraphGuid);
foreach (var node in nodes)
{
AddNode(node);

get { return m_MetaProperties; }
}
public Guid sourceGraphGuid
{
get { return m_SourceGraphGuid.guid; }
}
m_SerializeableSourceGraphGuid = SerializationHelper.Serialize(m_SourceGraphGuid);
m_SerializableNodes = SerializationHelper.Serialize<INode>(m_Nodes);
m_SerializableEdges = SerializationHelper.Serialize<IEdge>(m_Edges);
m_SerilaizeableProperties = SerializationHelper.Serialize<IShaderProperty>(m_Properties);

public void OnAfterDeserialize()
{
m_SourceGraphGuid = SerializationHelper.Deserialize<SerializableGuid>(m_SerializeableSourceGraphGuid, GraphUtil.GetLegacyTypeRemapping());
var nodes = SerializationHelper.Deserialize<INode>(m_SerializableNodes, GraphUtil.GetLegacyTypeRemapping());
m_Nodes.Clear();
foreach (var node in nodes)

正在加载...
取消
保存