浏览代码

Add meta properties in the CopyPasteGraph

/main
Jens Holm 7 年前
当前提交
8201871e
共有 3 个文件被更改,包括 52 次插入3 次删除
  1. 7
      com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs
  2. 15
      com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs
  3. 33
      com.unity.shadergraph/Editor/Util/CopyPasteGraph.cs

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


var middle = bounds.center;
bounds.center = Vector2.zero;
// Collect the property nodes and get the corresponding properties
var propertyNodeGuids = graphView.selection.OfType<MaterialNodeView>().Where(x => (x.node is PropertyNode)).Select(x => ((PropertyNode)x.node).propertyGuid);
var metaProperties = graphView.graph.properties.Where(x => propertyNodeGuids.Contains(x.guid));
graphView.selection.OfType<BlackboardField>().Select(x => x.userData as IShaderProperty));
graphView.selection.OfType<BlackboardField>().Select(x => x.userData as IShaderProperty),
metaProperties);
var deserialized = CopyPasteGraph.FromJson(JsonUtility.ToJson(copyPasteGraph, false));
if (deserialized == null)

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


var nodes = elements.OfType<MaterialNodeView>().Select(x => (INode)x.node);
var edges = elements.OfType<Edge>().Select(x => x.userData).OfType<IEdge>();
var properties = selection.OfType<BlackboardField>().Select(x => x.userData as IShaderProperty);
var graph = new CopyPasteGraph(nodes, edges, properties);
// Collect the property nodes and get the corresponding properties
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);
return JsonUtility.ToJson(graph, true);
}

IShaderProperty copiedProperty = property.Copy();
copiedProperty.displayName = propertyName;
graphView.graph.AddShaderProperty(copiedProperty);
// Update the property nodes that depends on the copied node
var dependentPropertyNodes = copyGraph.GetNodes<PropertyNode>().Where(x => x.propertyGuid == property.guid);
foreach (var node in dependentPropertyNodes)
{
node.owner = graphView.graph;
node.propertyGuid = copiedProperty.guid;
}
}
using (var remappedNodesDisposable = ListPool<INode>.GetDisposable())

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


[NonSerialized]
HashSet<IShaderProperty> m_Properties = new HashSet<IShaderProperty>();
// The meta properties are properties that are not copied into the tatget graph
// but sent along to allow property nodes to still hvae the data from the original
// property present.
[NonSerialized]
HashSet<IShaderProperty> m_MetaProperties = new HashSet<IShaderProperty>();
[SerializeField]
List<SerializationHelper.JSONSerializedElement> m_SerializableNodes = new List<SerializationHelper.JSONSerializedElement>();

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

foreach (var property in properties)
AddProperty(property);
foreach (var metaProperty in metaProperties)
AddMetaProperty(metaProperty);
}
public void AddNode(INode node)

m_Properties.Add(property);
}
public void AddMetaProperty(IShaderProperty metaProperty)
{
m_MetaProperties.Add(metaProperty);
}
public IEnumerable<T> GetNodes<T>() where T : INode
{
return m_Nodes.OfType<T>();

get { return m_Properties; }
}
public IEnumerable<IShaderProperty> metaProperties
{
get { return m_MetaProperties; }
}
m_SerializableMetaProperties = SerializationHelper.Serialize<IShaderProperty>(m_MetaProperties);
}
public void OnAfterDeserialize()

foreach (var property in properties)
m_Properties.Add(property);
m_SerilaizeableProperties = null;
var metaProperties = SerializationHelper.Deserialize<IShaderProperty>(m_SerializableMetaProperties, GraphUtil.GetLegacyTypeRemapping());
m_MetaProperties.Clear();
foreach (var metaProperty in metaProperties)
{
m_MetaProperties.Add(metaProperty);
}
m_SerializableMetaProperties = null;
}
internal static CopyPasteGraph FromJson(string copyBuffer)

正在加载...
取消
保存