浏览代码

Duplication/insert etc. now selects the new elements

/main
Peter Bay Bastian 7 年前
当前提交
c88791bb
共有 4 个文件被更改,包括 58 次插入140 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
  2. 86
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  3. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  4. 71
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs


public Object selected
{
get { return m_Selected; }
set { m_Selected = value; }
private set { m_Selected = value; }
}
void Update()

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


namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
public class MaterialGraphPresenter : GraphViewPresenter
public class MaterialGraphPresenter
bool m_AddToSelection;
protected MaterialGraphPresenter() { }
public override List<NodeAnchorPresenter> GetCompatibleAnchors(NodeAnchorPresenter startAnchor, NodeAdapter nodeAdapter)
{
var compatibleAnchors = new List<NodeAnchorPresenter>();
var startAnchorPresenter = startAnchor as GraphAnchorPresenter;
if (startAnchorPresenter == null)
return compatibleAnchors;
var startSlot = startAnchorPresenter.slot as MaterialSlot;
if (startSlot == null)
return compatibleAnchors;
var startStage = startSlot.shaderStage;
if (startStage == ShaderStage.Dynamic)
startStage = NodeUtils.FindEffectiveShaderStage(startSlot.owner, startSlot.isOutputSlot);
foreach (var candidateAnchorPresenter in allChildren.OfType<GraphAnchorPresenter>())
{
if (!candidateAnchorPresenter.IsConnectable())
continue;
if (candidateAnchorPresenter.orientation != startAnchor.orientation)
continue;
if (candidateAnchorPresenter.direction == startAnchor.direction)
continue;
if (nodeAdapter.GetAdapter(candidateAnchorPresenter.source, startAnchor.source) == null)
continue;
var candidateSlot = candidateAnchorPresenter.slot as MaterialSlot;
if (candidateSlot == null)
continue;
if (candidateSlot.owner == startSlot.owner)
continue;
if (!startSlot.IsCompatibleWithInputSlotType(candidateSlot.concreteValueType))
continue;
if (startStage != ShaderStage.Dynamic)
{
var candidateStage = candidateSlot.shaderStage;
if (candidateStage == ShaderStage.Dynamic)
candidateStage = NodeUtils.FindEffectiveShaderStage(candidateSlot.owner, !startSlot.isOutputSlot);
if (candidateStage != ShaderStage.Dynamic && candidateStage != startStage)
continue;
}
compatibleAnchors.Add(candidateAnchorPresenter);
}
return compatibleAnchors;
}
void OnNodeChanged(INode inNode, ModificationScope scope)
{
var dependentNodes = new List<INode>();

nodeView.userData = change.node;
change.node.onModified += OnNodeChanged;
m_GraphView.AddElement(nodeView);
if (m_AddToSelection)
m_GraphView.AddToSelection(nodeView);
}
void NodeRemoved(NodeRemovedGraphChange change)

edgeView.input = targetAnchor;
edgeView.input.Connect(edgeView);
m_GraphView.AddElement(edgeView);
if (m_AddToSelection)
m_GraphView.AddToSelection(edgeView);
}
void EdgeRemoved(EdgeRemovedGraphChange change)

}
}
internal static CopyPasteGraph CreateCopyPasteGraph(IEnumerable<GraphElement> selection)
static CopyPasteGraph CreateCopyPasteGraph(IEnumerable<GraphElement> selection)
{
var graph = new CopyPasteGraph();
foreach (var element in selection)

if (copyGraph == null || graph == null)
return;
m_GraphView.ClearSelection();
m_AddToSelection = true;
var addedNodes = new List<INode>();
var nodeGuidMap = new Dictionary<Guid, Guid>();
foreach (var node in copyGraph.GetNodes<INode>())

}
graph.ValidateGraph();
if (onSelectionChanged != null)
onSelectionChanged(addedNodes);
m_AddToSelection = false;
get { return elements.Any(e => e.selected) || (m_GraphView != null && m_GraphView.selection.OfType<GraphElement>().Any(e => e.selected)); }
get { return m_GraphView != null && m_GraphView.selection.OfType<GraphElement>().Any(e => e.selected); }
}
public void Copy()

RemoveElements(
m_GraphView.selection.OfType<MaterialNodeView>(),
m_GraphView.selection.OfType<Edge>());
}
public delegate void OnSelectionChanged(IEnumerable<INode> nodes);
public OnSelectionChanged onSelectionChanged;
public void UpdateSelection(IEnumerable<MaterialNodeView> nodes)
{
if (graph == null)
return;
if (onSelectionChanged != null)
onSelectionChanged(nodes.Select(x => x.userData as INode));
}
public override void AddElement(GraphElementPresenter element)
{
throw new ArgumentException("Not supported on Serializable Graph, data comes from data store");
}
public override void RemoveElement(GraphElementPresenter element)
{
throw new ArgumentException("Not supported on Serializable Graph, data comes from data store");
}
}
}

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


using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
using UnityEngine.Graphing;
using Object = UnityEngine.Object;
GraphView m_GraphView;
MaterialGraphView m_GraphView;
GraphInspectorView m_GraphInspectorView;
ToolbarView m_ToolbarView;
ToolbarButtonView m_TimeButton;

public Action onConvertToSubgraphClick { get; set; }
public Action onShowInProjectClick { get; set; }
public GraphView graphView
public MaterialGraphView graphView
{
get { return m_GraphView; }
}

}
Add(m_ToolbarView);
m_GraphPresenter = ScriptableObject.CreateInstance<MaterialGraphPresenter>();
m_GraphPresenter = new MaterialGraphPresenter();
var content = new VisualElement();
content.name = "content";
var content = new VisualElement { name = "content" };
m_GraphView = new MaterialGraphView { name = "GraphView", presenter = m_GraphPresenter };
m_GraphView = new MaterialGraphView(m_GraphPresenter) { name = "GraphView" };
m_GraphPresenter.onSelectionChanged += m_GraphInspectorView.UpdateSelection;
m_GraphView.onSelectionChanged += m_GraphInspectorView.UpdateSelection;
content.Add(m_GraphView);
content.Add(m_GraphInspectorView);

m_GraphPresenter.Initialize(m_GraphView, graph, previewSystem);
m_GraphPresenter.onSelectionChanged += m_GraphInspectorView.UpdateSelection;
private GraphViewChange GraphViewChanged(GraphViewChange graphViewChange)
GraphViewChange GraphViewChanged(GraphViewChange graphViewChange)
/*
if (graphViewChange.elementsToRemove != null)
{
graphViewChange.elementsToRemove.To
foreach (GraphElement element in graphViewChange.elementsToRemove)
{
if (element is Node)
{
m_GraphPresenter.RemoveElements(
m_GraphView.selection.OfType<MaterialNodeView>().Where(e => e.selected && e.presenter == null),
m_GraphView.selection.OfType<Edge>().Where(e => e.selected));
}
else if (element is Edge)
{
EdgeDisconnected(element as Edge);
}
}
}
*/
if (graphViewChange.edgesToCreate != null)
{
foreach (var edge in graphViewChange.edgesToCreate)

if (graphViewChange.movedElements != null)
{
foreach (GraphElement element in graphViewChange.movedElements)
foreach (var element in graphViewChange.movedElements)
{
var node = element.userData as INode;
if (node == null)

71
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs


{
public sealed class MaterialGraphView : GraphView
{
public MaterialGraphView()
MaterialGraphPresenter m_Presenter;
public MaterialGraphView(MaterialGraphPresenter presenter)
m_Presenter = presenter;
RegisterCallback<MouseUpEvent>(DoContextMenu, Capture.Capture);
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
this.AddManipulator(new ContentDragger());

public bool CanAddToNodeMenu(Type type)
{
return true;
}
void DoContextMenu(MouseUpEvent evt)
{
if (evt.button == (int)MouseButton.RightMouse)
{
var gm = new GenericMenu();
foreach (Type type in Assembly.GetAssembly(typeof(AbstractMaterialNode)).GetTypes())
{
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(AbstractMaterialNode))))
{
var attrs = type.GetCustomAttributes(typeof(TitleAttribute), false) as TitleAttribute[];
if (attrs != null && attrs.Length > 0 && CanAddToNodeMenu(type))
{
gm.AddItem(new GUIContent(attrs[0].m_Title), false, AddNode, new AddNodeCreationObject(type, evt.mousePosition));
}
}
}
gm.ShowAsContext();
}
evt.StopPropagation();
}
public override List<NodeAnchor> GetCompatibleAnchors(NodeAnchor startAnchor, NodeAdapter nodeAdapter)

return compatibleAnchors;
}
void DoContextMenu(MouseUpEvent evt)
{
if (evt.button == (int)MouseButton.RightMouse)
{
var gm = new GenericMenu();
foreach (Type type in Assembly.GetAssembly(typeof(AbstractMaterialNode)).GetTypes())
{
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(AbstractMaterialNode))))
{
var attrs = type.GetCustomAttributes(typeof(TitleAttribute), false) as TitleAttribute[];
if (attrs != null && attrs.Length > 0 && CanAddToNodeMenu(type))
{
gm.AddItem(new GUIContent(attrs[0].m_Title), false, AddNode, new AddNodeCreationObject(type, evt.mousePosition));
}
}
}
gm.ShowAsContext();
}
evt.StopPropagation();
}
class AddNodeCreationObject
{
public Vector2 m_Pos;

drawstate.position = new Rect(localPos.x, localPos.y, 0, 0);
node.drawState = drawstate;
var graphDataSource = GetPresenter<MaterialGraphPresenter>();
graphDataSource.AddNode(node);
m_Presenter.AddNode(node);
void PropagateSelection()
public delegate void OnSelectionChanged(IEnumerable<INode> nodes);
public OnSelectionChanged onSelectionChanged;
void SelectionChanged()
var graphPresenter = GetPresenter<MaterialGraphPresenter>();
if (graphPresenter == null)
return;
graphPresenter.UpdateSelection(selectedNodes);
if (onSelectionChanged != null)
onSelectionChanged(selectedNodes.Select(x => x.userData as INode));
PropagateSelection();
SelectionChanged();
PropagateSelection();
SelectionChanged();
PropagateSelection();
SelectionChanged();
}
}
}
正在加载...
取消
保存