浏览代码

Add edge change notifications to IGraph

Move time-dependent preview tracking into PreviewSystem
/main
Peter Bay Bastian 7 年前
当前提交
75826752
共有 5 个文件被更改,包括 51 次插入26 次删除
  1. 3
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs
  2. 20
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/GraphChange.cs
  3. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  4. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs
  5. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/UIUtilities.cs

3
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs


var newEdge = new Edge(outputSlot, inputSlot);
m_Edges.Add(newEdge);
NotifyChange(new EdgeAddedGraphChange(newEdge));
AddEdgeToNodeEdges(newEdge);
Debug.Log("Connected edge: " + newEdge);

List<IEdge> outputNodeEdges;
if (m_NodeEdges.TryGetValue(e.outputSlot.nodeGuid, out outputNodeEdges))
outputNodeEdges.Remove(e);
NotifyChange(new EdgeRemovedGraphChange(e));
}
public INode GetNodeFromGuid(Guid guid)

20
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/GraphChange.cs


public INode node { get; private set; }
}
public sealed class EdgeAddedGraphChange : GraphChange
{
public EdgeAddedGraphChange(IEdge edge)
{
this.edge = edge;
}
public IEdge edge { get; private set; }
}
public sealed class EdgeRemovedGraphChange : GraphChange
{
public EdgeRemovedGraphChange(IEdge edge)
{
this.edge = edge;
}
public IEdge edge { get; private set; }
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


edgePresenter.output.Disconnect(edgePresenter);
edgePresenter.input.Disconnect(edgePresenter);
var fromNodeGuid = edgePresenter.edge.outputSlot.nodeGuid;
var fromNodePresenter = m_Elements.OfType<MaterialNodePresenter>().FirstOrDefault(nd => nd.node.guid == fromNodeGuid);
if (toNode != null && toNode.onModified != null)
// Make the input node (i.e. right side of the connection) re-render
toNode.onModified(toNode, ModificationScope.Graph);
deletedElementPresenters.Add(edgePresenter);
}

var targetAnchors = targetNodePresenter.inputAnchors.OfType<GraphAnchorPresenter>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == targetSlot);
if (targetNodePresenter.node.onModified != null)
targetNodePresenter.node.onModified(targetNodePresenter.node, ModificationScope.Graph);
var edgePresenter = CreateInstance<GraphEdgePresenter>();
edgePresenter.Initialize(edge);
edgePresenter.output = sourceAnchorPresenter;

}
m_Elements.AddRange(edgePresenters.OfType<GraphElementPresenter>());
m_PreviewSystem.UpdateTimeDependentPreviews();
}
public virtual void Initialize(IGraph graph, IMaterialGraphEditWindow container, PreviewSystem previewSystem)

38
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs


using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using UnityEditor.Graphing.Util;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;

AddPreview(((NodeAddedGraphChange)change).node);
else if (change is NodeRemovedGraphChange)
RemovePreview(((NodeRemovedGraphChange)change).node);
else if (change is EdgeAddedGraphChange)
{
var edge = ((EdgeAddedGraphChange)change).edge;
m_DirtyShaders.Add(edge.inputSlot.nodeGuid);
}
else if (change is EdgeRemovedGraphChange)
{
var edge = ((EdgeRemovedGraphChange)change).edge;
m_DirtyShaders.Add(edge.inputSlot.nodeGuid);
}
}
void AddPreview(INode node)

m_Previews.Add(node.guid, previewData);
m_DirtyShaders.Add(node.guid);
node.onModified += OnNodeModified;
if (node.RequiresTime())
m_TimeDependentPreviews.Add(node.guid);
}
void RemovePreview(INode node)

m_TimeDependentPreviews.Remove(node.guid);
}
void OnNodeModified(INode node, ModificationScope scope)

else if (scope == ModificationScope.Node)
m_DirtyPreviews.Add(node.guid);
if (node.RequiresTime())
m_TimeDependentPreviews.Add(node.guid);
else
m_TimeDependentPreviews.Remove(node.guid);
void PropagateNodeSet(HashSet<Guid> nodeGuidSet, bool forward = true)
void PropagateNodeSet(HashSet<Guid> nodeGuidSet, bool forward = true, IEnumerable<Guid> initialWavefront = null)
foreach (var guid in nodeGuidSet)
foreach (var guid in initialWavefront ?? nodeGuidSet)
m_Wavefront.Push(guid);
while (m_Wavefront.Count > 0)
{

}
}
public void UpdateTimeDependentPreviews()
{
m_TimeDependentPreviews.Clear();
foreach (var node in m_Graph.GetNodes<INode>())
{
var timeNode = node as IMayRequireTime;
if (timeNode != null && timeNode.RequiresTime())
m_TimeDependentPreviews.Add(node.guid);
}
PropagateNodeSet(m_TimeDependentPreviews);
}
HashSet<Guid> m_PropertyNodeGuids = new HashSet<Guid>();
List<PreviewProperty> m_PreviewProperties = new List<PreviewProperty>();

m_DirtyPreviews.UnionWith(m_DirtyShaders);
m_DirtyShaders.Clear();
PropagateNodeSet(m_DirtyPreviews);
PropagateNodeSet(m_DirtyPreviews);
// Find nodes we need properties from
m_PropertyNodeGuids.Clear();

5
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/UIUtilities.cs


}
return hashCode;
}
public static IEnumerable<T> ToEnumerable<T>(this T item)
{
yield return item;
}
}
}
正在加载...
取消
保存