浏览代码

Merge pull request #229 from Unity-Technologies/safer-callbacks

Safer callbacks
/main
GitHub 7 年前
当前提交
a1c15f0d
共有 4 个文件被更改,包括 19 次插入8 次删除
  1. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Interfaces/Graph/INode.cs
  2. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
  3. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs
  4. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Interfaces/Graph/INode.cs


public interface INode
{
OnNodeModified onModified { get; set; }
void RegisterCallback(OnNodeModified callback);
void UnregisterCallback(OnNodeModified callback);
void Dirty(ModificationScope scope);
IGraph owner { get; set; }
Guid guid { get; }

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs


public IGraph owner { get; set; }
public OnNodeModified onModified { get; set; }
OnNodeModified m_OnModified;
public void RegisterCallback(OnNodeModified callback)
{
m_OnModified += callback;
}
public void UnregisterCallback(OnNodeModified callback)
{
m_OnModified -= callback;
}
if (onModified != null)
onModified(this, scope);
if (m_OnModified != null)
m_OnModified(this, scope);
}
public Guid guid

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs


Set(m_Identifiers, node.tempId, node.tempId);
Set(m_RenderDatas, node.tempId, renderData);
m_DirtyShaders.Add(node.tempId.index);
node.onModified += OnNodeModified;
node.RegisterCallback(OnNodeModified);
if (node.RequiresTime())
m_TimeDependentPreviews.Add(node.tempId.index);

Object.DestroyImmediate(renderData.renderTexture, true);
if (renderData.shaderData != null && renderData.shaderData.node != null)
renderData.shaderData.node.onModified -= OnNodeModified;
renderData.shaderData.node.UnregisterCallback(OnNodeModified);
}
void DestroyPreview(Identifier nodeId)

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs


foreach (var node in m_Graph.removedNodes)
{
node.onModified -= OnNodeChanged;
node.UnregisterCallback(OnNodeChanged);
var nodeView = m_GraphView.nodes.ToList().OfType<MaterialNodeView>().FirstOrDefault(p => p.node != null && p.node.guid == node.guid);
if (nodeView != null)
{

var nodeView = new MaterialNodeView { userData = node };
m_GraphView.AddElement(nodeView);
nodeView.Initialize(node as AbstractMaterialNode, m_PreviewManager, m_EdgeConnectorListener);
node.onModified += OnNodeChanged;
node.RegisterCallback(OnNodeChanged);
nodeView.Dirty(ChangeType.Repaint);
if (m_SearchWindowProvider.nodeNeedsRepositioning && m_SearchWindowProvider.targetSlotReference.nodeGuid.Equals(node.guid))

正在加载...
取消
保存