|
|
|
|
|
|
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(); |
|
|
|