浏览代码

Merge pull request #71 from Unity-Technologies/no-presenters

No presenters
/main
GitHub 7 年前
当前提交
5363a614
共有 17 个文件被更改,包括 704 次插入360 次删除
  1. 206
      MaterialGraphProject/Assets/PartyPreview.ShaderGraph
  2. 22
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs
  3. 120
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  4. 61
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  5. 51
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs
  6. 241
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  7. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/GraphTypeMapper.cs
  8. 13
      MaterialGraphProject/ProjectSettings/DynamicsManager.asset
  9. 16
      MaterialGraphProject/ProjectSettings/Physics2DSettings.asset
  10. 39
      MaterialGraphProject/ProjectSettings/ProjectSettings.asset
  11. 28
      MaterialGraphProject/Assets/New Shader Graph.ShaderGraph
  12. 9
      MaterialGraphProject/Assets/New Shader Graph.ShaderGraph.meta
  13. 84
      MaterialGraphProject/GeneratedShader.shader
  14. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs.meta
  15. 147
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs
  16. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes.meta

206
MaterialGraphProject/Assets/PartyPreview.ShaderGraph
文件差异内容过多而无法显示
查看文件

22
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs


using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
using Object = UnityEngine.Object;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
namespace UnityEditor.MaterialGraph.Drawing
{

return;
var graphPresenter = graphEditorView.graphPresenter;
var selected = graphPresenter.elements.Where(e => e.selected);
var graphView = graphEditorView.graphView;
var selection = graphView.selection.OfType<GraphElement>();
var filtered = new List<GraphElementPresenter>();
var filtered = new List<GraphElement>();
foreach (var presenter in selected)
foreach (var element in selection)
var nodePresenter = presenter as MaterialNodePresenter;
if (nodePresenter != null)
var nodeView = element as MaterialNodeView;
if (nodeView != null)
if (!(nodePresenter.node is PropertyNode))
filtered.Add(nodePresenter);
if (!(nodeView.node is PropertyNode))
filtered.Add(nodeView);
filtered.Add(presenter);
filtered.Add(element);
}
}

graphPresenter.graph.Connect(new SlotReference(subGraphNode.guid, edgeMap.Value.inputSlot.slotId), edgeMap.Key.inputSlot);
}
var toDelete = graphPresenter.elements.Where(e => e.selected).OfType<MaterialNodePresenter>();
graphPresenter.RemoveElements(toDelete, new List<GraphEdgePresenter>());
var toDelete = graphView.selection.OfType<MaterialNodeView>();
graphPresenter.RemoveElements(toDelete, new List<Edge>());
}
private void UpdateAbstractSubgraphOnDisk<T>(string path) where T : AbstractSubGraph

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


using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Graphing;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
namespace UnityEditor.MaterialGraph.Drawing
{

private GraphView m_GraphView;
PreviewSystem m_PreviewSystem;
public IGraph graph { get; private set; }

NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, inNode);
foreach (var node in dependentNodes)
{
var theElements = m_Elements.OfType<MaterialNodePresenter>().ToList();
var found = theElements.Where(x => x.node.guid == node.guid).ToList();
foreach (var drawableNodeData in found)
var theViews = m_GraphView.nodes.ToList().OfType<MaterialNodeView>();
var viewsFound = theViews.Where(x => x.node.guid == node.guid).ToList();
foreach (var drawableNodeData in viewsFound)
drawableNodeData.OnModified(scope);
}

public virtual void Initialize(IGraph graph, IMaterialGraphEditWindow container, PreviewSystem previewSystem)
public virtual void Initialize(GraphView graphView, IGraph graph, IMaterialGraphEditWindow container, PreviewSystem previewSystem)
m_GraphView = graphView;
m_PreviewSystem = previewSystem;
this.graph = graph;

void NodeAdded(NodeAddedGraphChange change)
{
var nodePresenter = CreateInstance<MaterialNodePresenter>();
var nodeView = new MaterialNodeView();
nodePresenter.Initialize(change.node, m_PreviewSystem);
m_Elements.Add(nodePresenter);
nodeView.Initialize(change.node, m_PreviewSystem);
m_GraphView.AddElement(nodeView);
var nodePresenter = m_Elements.OfType<MaterialNodePresenter>().FirstOrDefault(p => p.node.guid == change.node.guid);
if (nodePresenter != null)
m_Elements.Remove(nodePresenter);
var nodeView = m_GraphView.nodes.ToList().OfType<MaterialNodeView>().FirstOrDefault(p => p.node != null && p.node.guid == change.node.guid);
if (nodeView != null)
m_GraphView.RemoveElement(nodeView);
}
void EdgeAdded(EdgeAddedGraphChange change)

var sourceNode = graph.GetNodeFromGuid(edge.outputSlot.nodeGuid);
var sourceSlot = sourceNode.FindOutputSlot<ISlot>(edge.outputSlot.slotId);
var sourceNodePresenter = m_Elements.OfType<MaterialNodePresenter>().FirstOrDefault(x => x.node == sourceNode);
var sourceAnchorPresenter = sourceNodePresenter.outputAnchors.OfType<GraphAnchorPresenter>().FirstOrDefault(x => x.slot.Equals(sourceSlot));
var targetNodePresenter = m_Elements.OfType<MaterialNodePresenter>().FirstOrDefault(x => x.node == targetNode);
var targetAnchor = targetNodePresenter.inputAnchors.OfType<GraphAnchorPresenter>().FirstOrDefault(x => x.slot.Equals(targetSlot));
var edgePresenter = CreateInstance<GraphEdgePresenter>();
edgePresenter.Initialize(edge);
edgePresenter.output = sourceAnchorPresenter;
edgePresenter.output.Connect(edgePresenter);
edgePresenter.input = targetAnchor;
edgePresenter.input.Connect(edgePresenter);
m_Elements.Add(edgePresenter);
var sourceNodeView = m_GraphView.nodes.ToList().OfType<MaterialNodeView>().FirstOrDefault(x => x.node == sourceNode);
if (sourceNodeView == null)
return;
var sourceAnchor = sourceNodeView.outputContainer.Children().OfType<NodeAnchor>().FirstOrDefault(x => x.userData is ISlot && (x.userData as ISlot).Equals(sourceSlot));
var targetNodeView = m_GraphView.nodes.ToList().OfType<MaterialNodeView>().FirstOrDefault(x => x.node == targetNode);
var targetAnchor = targetNodeView.inputContainer.Children().OfType<NodeAnchor>().FirstOrDefault(x => x.userData is ISlot && (x.userData as ISlot).Equals(targetSlot));
var edgeView = new Edge();
edgeView.userData = edge;
edgeView.output = sourceAnchor;
edgeView.output.Connect(edgeView);
edgeView.input = targetAnchor;
edgeView.input.Connect(edgeView);
m_GraphView.AddElement(edgeView);
var edgePresenter = m_Elements.OfType<GraphEdgePresenter>().FirstOrDefault(p => p.edge == change.edge);
if (edgePresenter != null)
var edgeView = m_GraphView.graphElements.ToList().OfType<Edge>().FirstOrDefault(p => p.userData is IEdge && (IEdge)p.userData == change.edge);
if (edgeView != null)
edgePresenter.output.Disconnect(edgePresenter);
edgePresenter.input.Disconnect(edgePresenter);
m_Elements.Remove(edgePresenter);
edgeView.output.Disconnect(edgeView);
edgeView.input.Disconnect(edgeView);
m_GraphView.RemoveElement(edgeView);
}
}

graph.AddNode(node);
}
public void RemoveElements(IEnumerable<MaterialNodePresenter> nodes, IEnumerable<GraphEdgePresenter> edges)
public void RemoveElements(IEnumerable<MaterialNodeView> nodes, IEnumerable<Edge> edges)
graph.RemoveElements(nodes.Select(x => x.node as INode), edges.Select(x => x.edge));
graph.RemoveElements(nodes.Select(x => x.node as INode), edges.Select(x => x.userData as IEdge));
public void Connect(GraphAnchorPresenter left, GraphAnchorPresenter right)
public void Connect(NodeAnchor left, NodeAnchor right)
graph.Connect(left.slot.slotReference, right.slot.slotReference);
var leftSlot = left.userData as ISlot;
var rightSlot = right.userData as ISlot;
if (leftSlot == null || rightSlot == null)
return;
graph.Connect(leftSlot.slotReference, rightSlot.slotReference);
internal static CopyPasteGraph CreateCopyPasteGraph(IEnumerable<GraphElementPresenter> selection)
internal static CopyPasteGraph CreateCopyPasteGraph(IEnumerable<GraphElement> selection)
foreach (var presenter in selection)
foreach (var element in selection)
var nodePresenter = presenter as MaterialNodePresenter;
if (nodePresenter != null)
var nodeView = element as MaterialNodeView;
if (nodeView != null)
graph.AddNode(nodePresenter.node);
foreach (var edge in NodeUtils.GetAllEdges(nodePresenter.node))
graph.AddNode(nodeView.node);
foreach (var edge in NodeUtils.GetAllEdges(nodeView.userData as INode))
var edgePresenter = presenter as GraphEdgePresenter;
if (edgePresenter != null)
graph.AddEdge(edgePresenter.edge);
var edgeView = element as Edge;
if (edgeView != null)
graph.AddEdge(edgeView.userData as IEdge);
}
return graph;
}

public bool canCopy
{
get { return elements.Any(e => e.selected); }
get { return elements.Any(e => e.selected) || (m_GraphView != null && m_GraphView.selection.OfType<GraphElement>().Any(e => e.selected)); }
var graph = CreateCopyPasteGraph(elements.Where(e => e.selected));
var graph = CreateCopyPasteGraph(m_GraphView.selection.OfType<GraphElement>());
EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(graph, true);
}

{
Copy();
graph.owner.RegisterCompleteObjectUndo("Cut");
RemoveElements(elements.OfType<MaterialNodePresenter>().Where(e => e.selected), elements.OfType<GraphEdgePresenter>().Where(e => e.selected));
RemoveElements(
m_GraphView.selection.OfType<MaterialNodeView>(),
m_GraphView.selection.OfType<Edge>());
}
public bool canPaste

public void Duplicate()
{
var deserializedGraph = DeserializeCopyBuffer(JsonUtility.ToJson(CreateCopyPasteGraph(elements.Where(e => e.selected)), true));
var deserializedGraph = DeserializeCopyBuffer(JsonUtility.ToJson(CreateCopyPasteGraph(m_GraphView.selection.OfType<GraphElement>()), true));
graph.owner.RegisterCompleteObjectUndo("Duplicate");
InsertCopyPasteGraph(deserializedGraph);
}

public void Delete()
{
graph.owner.RegisterCompleteObjectUndo("Delete");
RemoveElements(elements.OfType<MaterialNodePresenter>().Where(e => e.selected), elements.OfType<GraphEdgePresenter>().Where(e => e.selected));
RemoveElements(
m_GraphView.selection.OfType<MaterialNodeView>(),
m_GraphView.selection.OfType<Edge>());
public override void AddElement(EdgePresenter edge)
{
Connect(edge.output as GraphAnchorPresenter, edge.input as GraphAnchorPresenter);
}
public delegate void OnSelectionChanged(IEnumerable<INode> presenters);
public delegate void OnSelectionChanged(IEnumerable<INode> nodes);
public void UpdateSelection(IEnumerable<MaterialNodePresenter> presenters)
public void UpdateSelection(IEnumerable<MaterialNodeView> nodes)
onSelectionChanged(presenters.Select(x => x.node as INode));
onSelectionChanged(nodes.Select(x => x.userData as INode));
}
public override void AddElement(GraphElementPresenter element)

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


using System;
using System.Linq;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.MaterialGraph.Drawing;
using UnityEditor.MaterialGraph.Drawing.Inspector;

using UnityEngine.Graphing;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph.Drawing

previewSystem = new PreviewSystem(graph);
m_GraphPresenter = ScriptableObject.CreateInstance<MaterialGraphPresenter>();
m_GraphPresenter.Initialize(graph, container, previewSystem);
m_ToolbarView = new ToolbarView { name = "TitleBar" };
{
m_ToolbarView.Add(new ToolbarSpaceView());

}
Add(m_ToolbarView);
m_GraphPresenter = ScriptableObject.CreateInstance<MaterialGraphPresenter>();
var content = new VisualElement();
content.name = "content";
{

content.Add(m_GraphView);
content.Add(m_GraphInspectorView);
m_GraphView.graphViewChanged = GraphViewChanged;
m_GraphPresenter.Initialize(m_GraphView, graph, container, previewSystem);
m_GraphPresenter.onSelectionChanged += m_GraphInspectorView.UpdateSelection;
}
private 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)
{
m_GraphPresenter.Connect(edge.output, edge.input);
}
graphViewChange.edgesToCreate.Clear();
}
if (graphViewChange.movedElements != null)
{
foreach (GraphElement element in graphViewChange.movedElements)
{
var node = element.userData as INode;
if (node == null)
continue;
var drawState = node.drawState;
drawState.position = element.layout;
node.drawState = drawState;
}
}
return graphViewChange;
}
public void Dispose()

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


using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor.Experimental.UIElements.GraphView;

using UnityEngine.Experimental.UIElements;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
using MouseButton = UnityEngine.Experimental.UIElements.MouseButton;
namespace UnityEditor.MaterialGraph.Drawing

this.AddManipulator(new ClickSelector());
Insert(0, new GridBackground());
typeFactory[typeof(MaterialNodePresenter)] = typeof(MaterialNodeView);
typeFactory[typeof(GraphAnchorPresenter)] = typeof(NodeAnchor);
typeFactory[typeof(EdgePresenter)] = typeof(Edge);
AddStyleSheetPath("Styles/MaterialGraph");
}

evt.StopPropagation();
}
public override List<NodeAnchor> GetCompatibleAnchors(NodeAnchor startAnchor, NodeAdapter nodeAdapter)
{
var compatibleAnchors = new List<NodeAnchor>();
var startSlot = startAnchor.userData as MaterialSlot;
if (startSlot == null)
return compatibleAnchors;
var startStage = startSlot.shaderStage;
if (startStage == ShaderStage.Dynamic)
startStage = NodeUtils.FindEffectiveShaderStage(startSlot.owner, startSlot.isOutputSlot);
foreach (var candidateAnchor in anchors.ToList())
{
if (!candidateAnchor.IsConnectable())
continue;
if (candidateAnchor.orientation != startAnchor.orientation)
continue;
if (candidateAnchor.direction == startAnchor.direction)
continue;
if (nodeAdapter.GetAdapter(candidateAnchor.source, startAnchor.source) == null)
continue;
var candidateSlot = candidateAnchor.userData 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(candidateAnchor);
}
return compatibleAnchors;
}
class AddNodeCreationObject
{
public Vector2 m_Pos;

if (graphPresenter == null)
return;
var selectedNodes = selection.OfType<MaterialNodeView>().Select(x => (MaterialNodePresenter)x.presenter);
var selectedNodes = selection.OfType<MaterialNodeView>().Where(x => x.userData is INode);
graphPresenter.UpdateSelection(selectedNodes);
}

241
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs


using UnityEngine.MaterialGraph;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
using UnityEngine.Experimental.UIElements.StyleSheets;
namespace UnityEditor.MaterialGraph.Drawing

public AbstractMaterialNode node { get; private set; }
protected List<GraphControlPresenter> m_Controls = new List<GraphControlPresenter>();
public List<GraphControlPresenter> controls
{
get { return m_Controls; }
}
int m_Version;
PreviewData m_Preview;
public Texture previewTexture { get; private set; }
public override bool expanded
{
get { return base.expanded; }
set
{
if (base.expanded != value)
{
base.expanded = value;
var ds = node.drawState;
ds.expanded = value;
node.drawState = ds;
}
}
}
public virtual void OnModified(ModificationScope scope)
{
m_Version++;
expanded = node.drawState.expanded;
if (scope == ModificationScope.Topological)
{
var slots = node.GetSlots<ISlot>().ToList();
var anchorsToRemove = new List<VisualElement>();
foreach (var anchor in inputContainer.Children())
{
if (!slots.Contains(anchor.userData as ISlot))
anchorsToRemove.Add(anchor);
}
foreach (var ve in anchorsToRemove)
inputContainer.Remove(ve);
anchorsToRemove.Clear();
foreach (var anchor in outputContainer.Children())
{
if (!slots.Contains(anchor.userData as ISlot))
anchorsToRemove.Add(anchor);
}
foreach (var ve in anchorsToRemove)
outputContainer.Remove(ve);
AddSlots(slots.Except(inputContainer.Children().Concat(outputContainer.Children()).Select(data => data.userData as ISlot)));
inputContainer.Sort((x, y) => slots.IndexOf(x.userData as ISlot) - slots.IndexOf(y.userData as ISlot));
outputContainer.Sort((x, y) => slots.IndexOf(x.userData as ISlot) - slots.IndexOf(y.userData as ISlot));
}
}
protected virtual IEnumerable<GraphControlPresenter> GetControlData()
{
return Enumerable.Empty<GraphControlPresenter>();
}
protected void AddSlots(IEnumerable<ISlot> slots)
{
foreach (var slot in slots)
{
if (slot.hidden)
continue;
var data = InstantiateNodeAnchor(Orientation.Horizontal, slot.isInputSlot ? Direction.Input : Direction.Output, typeof(Vector4));
data.capabilities &= ~Capabilities.Movable;
data.anchorName = slot.displayName;
data.userData = slot;
if (slot.isOutputSlot)
{
outputContainer.Add(data);
}
else
{
inputContainer.Add(data);
}
}
}
public virtual void Initialize(INode inNode, PreviewSystem previewSystem)
{
node = inNode as AbstractMaterialNode;
userData = node;
if (node == null)
return;
title = inNode.name;
expanded = node.drawState.expanded;
AddSlots(node.GetSlots<ISlot>());
var controlData = GetControlData();
controls.AddRange(controlData);
SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0));
m_Version = 0;
m_Preview = previewSystem.GetPreview(inNode);
m_Preview.onPreviewChanged += OnPreviewChanged;
node.onReplaced += OnReplaced;
// From OnDataChange()
m_PreviewToggle.text = node.previewExpanded ? "▲" : "▼";
if (node.hasPreview)
m_PreviewToggle.RemoveFromClassList("inactive");
else
m_PreviewToggle.AddToClassList("inactive");
UpdateControls();
UpdatePreviewTexture(node.previewExpanded ? previewTexture : null);
m_NodeGuid = node.guid;
if (node is PreviewNode)
{
if (!m_ResizeHandleAdded)
{
m_ResizeHandle = new VisualElement() { name = "resize", text = "" };
m_ResizeHandle.AddManipulator(new Draggable(OnResize));
Add(m_ResizeHandle);
m_ResizeHandleAdded = true;
}
UpdateSize();
}
}
void OnReplaced(INode previous, INode current)
{
node = current as AbstractMaterialNode;
}
void OnPreviewChanged()
{
previewTexture = m_Preview.texture;
UpdatePreviewTexture(node.previewExpanded ? previewTexture : null);
m_Version++;
}
public void Dispose()
{
if (m_Preview != null)
{
m_Preview.onPreviewChanged -= OnPreviewChanged;
m_Preview = null;
}
}
////////////////////////////////////////////////////////////////////////////////////
VisualElement m_ControlsContainer;
List<VisualElement> m_ControlViews;
Guid m_NodeGuid;

float updatedWidth = Mathf.Min(leftContainer.layout.width + deltaSize.x, 1000f);
float updatedHeight = m_PreviewImage.layout.height + deltaSize.y;
PreviewNode previewNode = GetPresenter<MaterialNodePresenter>().node as PreviewNode;
PreviewNode previewNode = node as PreviewNode;
if (previewNode != null)
{

void OnPreviewToggle()
{
var node = GetPresenter<MaterialNodePresenter>().node;
node.previewExpanded = !node.previewExpanded;
m_PreviewToggle.text = node.previewExpanded ? "▲" : "▼";
}

if (previewTexture == null)
if (previewTexture == null)
{
m_PreviewImage.visible = false;
m_PreviewImage.RemoveFromClassList("visible");

}
void UpdateControls(MaterialNodePresenter nodePresenter)
void UpdateControls()
if (!nodePresenter.node.guid.Equals(m_NodeGuid))
if (!node.guid.Equals(m_NodeGuid))
foreach (var propertyInfo in nodePresenter.node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
foreach (var propertyInfo in node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
m_ControlViews.Add(attribute.InstantiateControl(nodePresenter.node, propertyInfo));
m_ControlViews.Add(attribute.InstantiateControl(node, propertyInfo));
if (!nodePresenter.expanded)
if (!expanded)
m_ControlsContainer.Clear();
m_ControlsContainer.Clear();
}
else if (m_ControlsContainer.childCount != m_ControlViews.Count)
{

}
}
public override void SetPosition(Rect newPos)
{
var nodePresenter = GetPresenter<MaterialNodePresenter>();
if (nodePresenter != null)
nodePresenter.position = newPos;
base.SetPosition(newPos);
}
public override void OnDataChanged()
{
base.OnDataChanged();
var nodePresenter = GetPresenter<MaterialNodePresenter>();
if (nodePresenter == null)
{
m_ControlsContainer.Clear();
m_ControlViews.Clear();
UpdatePreviewTexture(null);
return;
}
m_PreviewToggle.text = nodePresenter.node.previewExpanded ? "▲" : "▼";
if (nodePresenter.node.hasPreview)
m_PreviewToggle.RemoveFromClassList("inactive");
else
m_PreviewToggle.AddToClassList("inactive");
UpdateControls(nodePresenter);
UpdatePreviewTexture(nodePresenter.node.previewExpanded ? nodePresenter.previewTexture : null);
m_NodeGuid = nodePresenter.node.guid;
if (GetPresenter<MaterialNodePresenter>().node is PreviewNode)
{
if (!m_ResizeHandleAdded)
{
m_ResizeHandle = new VisualElement() { name = "resize", text = "" };
m_ResizeHandle.AddManipulator(new Draggable(OnResize));
Add(m_ResizeHandle);
m_ResizeHandleAdded = true;
}
UpdateSize();
}
}
var node = GetPresenter<MaterialNodePresenter>().node as PreviewNode;
var previewNode = node as PreviewNode;
if (node == null)
if (previewNode == null)
float width = node.width;
float height = node.height;
float width = previewNode.width;
float height = previewNode.height;
leftContainer.style.width = width;
m_PreviewImage.style.height = height;

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/GraphTypeMapper.cs


using System;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
public class GraphTypeMapper : BaseTypeFactory<INode, ScriptableObject>
public class GraphTypeMapper : BaseTypeFactory<INode, GraphElement>
protected override ScriptableObject InternalCreate(Type valueType)
protected override GraphElement InternalCreate(Type valueType)
return ScriptableObject.CreateInstance(valueType);
return (GraphElement) Activator.CreateInstance(valueType);
}
}
}

13
MaterialGraphProject/ProjectSettings/DynamicsManager.asset


--- !u!55 &1
PhysicsManager:
m_ObjectHideFlags: 0
serializedVersion: 3
serializedVersion: 7
m_Gravity: {x: 0, y: -9.81, z: 0}
m_DefaultMaterial: {fileID: 0}
m_BounceThreshold: 2

m_QueriesHitBackfaces: 0
m_QueriesHitTriggers: 1
m_EnableAdaptiveForce: 0
m_EnablePCM: 1
m_ClothInterCollisionDistance: 0
m_ClothInterCollisionStiffness: 0
m_ContactsGeneration: 1
m_ClothInterCollisionSettingsToggle: 0
m_ContactPairsMode: 0
m_BroadphaseType: 0
m_WorldBounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 250, y: 250, z: 250}
m_WorldSubdivisions: 8

16
MaterialGraphProject/ProjectSettings/Physics2DSettings.asset


--- !u!19 &1
Physics2DSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
serializedVersion: 3
m_Gravity: {x: 0, y: -9.81}
m_DefaultMaterial: {fileID: 0}
m_VelocityIterations: 8

m_MaxAngularCorrection: 8
m_MaxTranslationSpeed: 100
m_MaxRotationSpeed: 360
m_MinPenetrationForPenalty: 0.01
m_DefaultContactOffset: 0.01
m_AutoSimulation: 1
m_CallbacksOnDisable: 1
m_AutoSyncTransforms: 1
m_AlwaysShowColliders: 0
m_ShowColliderSleep: 1
m_ShowColliderContacts: 0
m_ShowColliderAABB: 0
m_ContactArrowScale: 0.2
m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412}
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

39
MaterialGraphProject/ProjectSettings/ProjectSettings.asset


--- !u!129 &1
PlayerSettings:
m_ObjectHideFlags: 0
serializedVersion: 13
serializedVersion: 14
productGUID: 918d4c17ff3414942ad7fbe59f853890
AndroidProfiler: 0
AndroidFilterTouchesWhenObscured: 0

allowedAutorotateToLandscapeLeft: 1
useOSAutorotation: 1
use32BitDisplayBuffer: 1
preserveFramebufferAlpha: 0
disableDepthAndStencilBuffers: 0
androidBlitType: 0
defaultIsFullScreen: 1

visibleInBackground: 1
allowFullscreenSwitch: 1
graphicsJobMode: 0
macFullscreenMode: 2
d3d9FullscreenMode: 1
d3d11FullscreenMode: 1
fullscreenMode: -1
xboxSpeechDB: 0
xboxEnableHeadOrientation: 0
xboxEnableGuest: 0

n3dsEnableSharedListOpt: 1
n3dsEnableVSync: 0
ignoreAlphaClear: 0
xboxOneResolution: 0
xboxOneMonoLoggingLevel: 0
xboxOneLoggingLevel: 1

useSustainedPerformanceMode: 0
enableVideoLayer: 0
useProtectedVideoMemory: 0
minimumSupportedHeadTracking: 0
maximumSupportedHeadTracking: 1
targetPixelDensity: 0
targetPixelDensity: 30
resolutionScalingMode: 0
androidSupportedAspectRatio: 1
androidMaxAspectRatio: 2.1

iPadLandscapeSplashScreen: {fileID: 0}
iPadHighResLandscapeSplashScreen: {fileID: 0}
appleTVSplashScreen: {fileID: 0}
appleTVSplashScreen2x: {fileID: 0}
tvOSSmallIconLayers2x: []
tvOSLargeIconLayers2x: []
tvOSTopShelfImageLayers2x: []
tvOSTopShelfImageWideLayers2x: []
iOSLaunchScreenType: 0
iOSLaunchScreenPortrait: {fileID: 0}
iOSLaunchScreenLandscape: {fileID: 0}

iOSManualSigningProvisioningProfileID:
tvOSManualSigningProvisioningProfileID:
appleEnableAutomaticSigning: 0
iOSRequireARKit: 0
clonedFromGUID: 00000000000000000000000000000000
AndroidTargetDevice: 0
AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0}

AndroidIsGame: 1
AndroidEnableTango: 0
AndroidTangoUsesCamera: 1
androidEnableBanner: 1
androidUseLowAccuracyLocation: 0
m_AndroidBanners:

Android: 1
iPhone: 1
tvOS: 1
m_BuildTargetGroupLightmapEncodingQuality:
- m_BuildTarget: Standalone
m_EncodingQuality: 1
- m_BuildTarget: XboxOne
m_EncodingQuality: 1
- m_BuildTarget: PS4
m_EncodingQuality: 1
wiiUTitleID: 0005000011000000
wiiUGroupID: 00010000
wiiUCommonSaveSize: 4096

ps4PronunciationSIGPath:
ps4BackgroundImagePath:
ps4StartupImagePath:
ps4StartupImagesFolder:
ps4IconImagesFolder:
ps4SaveDataImagePath:
ps4SdkOverride:
ps4BGMPath:

ps4pnFriends: 1
ps4pnGameCustomData: 1
playerPrefsSupport: 0
enableApplicationExit: 0
restrictedAudioUsageRights: 0
ps4UseResolutionFallback: 0
ps4ReprojectionSupport: 0

webGLUseEmbeddedResources: 0
webGLUseWasm: 0
webGLCompressionFormat: 1
scriptingDefineSymbols: {}
scriptingDefineSymbols:
1: UNITY_POST_PROCESSING_STACK_V2
platformArchitecture: {}
scriptingBackend: {}
incrementalIl2cppBuild: {}

n3dsTitle: GameName
n3dsProductCode:
n3dsApplicationId: 0xFF3FF
stvDeviceAddress:
stvProductDescription:
stvProductAuthor:
stvProductAuthorEmail:
stvProductLink:
stvProductCategory: 0
XboxOneProductId:
XboxOneUpdateKey:
XboxOneSandboxId:

28
MaterialGraphProject/Assets/New Shader Graph.ShaderGraph
文件差异内容过多而无法显示
查看文件

9
MaterialGraphProject/Assets/New Shader Graph.ShaderGraph.meta


fileFormatVersion: 2
guid: bc622a74b3c2c0d4db4c564bf551b9b5
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

84
MaterialGraphProject/GeneratedShader.shader


Shader "hidden/preview/Fractal_70AE3FBF"
{
Properties
{
}
CGINCLUDE
#include "UnityCG.cginc"
void Unity_Fractal_float(float2 uv, float2 pan, float zoom, float aspect, out float result)
{
const int Iterations = 128;
float2 c = (uv - 0.5) * zoom * float2(1, aspect) - pan;
float2 v = 0;
for (int n = 0; n < Iterations && dot(v,v) < 4; n++)
{
v = float2(v.x * v.x - v.y * v.y, v.x * v.y * 2) + c;
}
result = (dot(v, v) > 4) ? (float)n / (float)Iterations : 0;
}
struct GraphVertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float4 texcoord0 : TEXCOORD0;
float4 lightmapUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct SurfaceInputs{
half4 uv0;
};
struct SurfaceDescription{
float Fractal_70AE3FBF_result;
};
float4 Fractal_70AE3FBF_uv;
float4 Fractal_70AE3FBF_pan;
float Fractal_70AE3FBF_zoom;
float Fractal_70AE3FBF_aspect;
GraphVertexInput PopulateVertexData(GraphVertexInput v){
return v;
}
SurfaceDescription PopulateSurfaceData(SurfaceInputs IN) {
half4 uv0 = IN.uv0;
float Fractal_70AE3FBF_result;
Unity_Fractal_float(uv0, Fractal_70AE3FBF_pan, Fractal_70AE3FBF_zoom, Fractal_70AE3FBF_aspect, Fractal_70AE3FBF_result);
SurfaceDescription surface = (SurfaceDescription)0;
surface.Fractal_70AE3FBF_result = Fractal_70AE3FBF_result;
return surface;
}
ENDCG
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct GraphVertexOutput
{
float4 position : POSITION;
half4 uv0 : TEXCOORD;
};
GraphVertexOutput vert (GraphVertexInput v)
{
v = PopulateVertexData(v);
GraphVertexOutput o;
o.position = UnityObjectToClipPos(v.vertex);
o.uv0 = v.texcoord0;
return o;
}
fixed4 frag (GraphVertexOutput IN) : SV_Target
{
float4 uv0 = IN.uv0;
SurfaceInputs surfaceInput = (SurfaceInputs)0;;
surfaceInput.uv0 =uv0;
SurfaceDescription surf = PopulateSurfaceData(surfaceInput);
return half4(surf.Fractal_70AE3FBF_result, surf.Fractal_70AE3FBF_result, surf.Fractal_70AE3FBF_result, 1.0);
}
ENDCG
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs.meta


fileFormatVersion: 2
guid: 6d66b7c0ed7187d4f9ebae2c7f8d3167
timeCreated: 1476707367
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

147
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
using UnityEngine;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
public class MaterialNodePresenter : NodePresenter, IDisposable
{
public AbstractMaterialNode node { get; private set; }
[SerializeField]
protected List<GraphControlPresenter> m_Controls = new List<GraphControlPresenter>();
public List<GraphControlPresenter> controls
{
get { return m_Controls; }
}
[SerializeField]
int m_Version;
PreviewData m_Preview;
public Texture previewTexture { get; private set; }
public override bool expanded
{
get { return base.expanded; }
set
{
if (base.expanded != value)
{
base.expanded = value;
var ds = node.drawState;
ds.expanded = value;
node.drawState = ds;
}
}
}
public virtual void OnModified(ModificationScope scope)
{
m_Version++;
expanded = node.drawState.expanded;
if (scope == ModificationScope.Topological)
{
var slots = node.GetSlots<ISlot>().ToList();
inputAnchors.RemoveAll(data => !slots.Contains(((GraphAnchorPresenter)data).slot));
outputAnchors.RemoveAll(data => !slots.Contains(((GraphAnchorPresenter)data).slot));
AddSlots(slots.Except(inputAnchors.Concat(outputAnchors).Select(data => ((GraphAnchorPresenter)data).slot)));
inputAnchors.Sort((x, y) => slots.IndexOf(((GraphAnchorPresenter)x).slot) - slots.IndexOf(((GraphAnchorPresenter)y).slot));
outputAnchors.Sort((x, y) => slots.IndexOf(((GraphAnchorPresenter)x).slot) - slots.IndexOf(((GraphAnchorPresenter)y).slot));
}
}
public override void CommitChanges()
{
var drawState = node.drawState;
drawState.position = position;
node.drawState = drawState;
}
protected virtual IEnumerable<GraphControlPresenter> GetControlData()
{
return Enumerable.Empty<GraphControlPresenter>();
}
protected void AddSlots(IEnumerable<ISlot> slots)
{
foreach (var slot in slots)
{
if (slot.hidden)
continue;
var data = CreateInstance<GraphAnchorPresenter>();
data.capabilities &= ~Capabilities.Movable;
data.Initialize(slot);
if (slot.isOutputSlot)
{
outputAnchors.Add(data);
}
else
{
inputAnchors.Add(data);
}
}
}
protected MaterialNodePresenter()
{}
public virtual void Initialize(INode inNode, PreviewSystem previewSystem)
{
node = inNode as AbstractMaterialNode;
if (node == null)
return;
title = inNode.name;
expanded = node.drawState.expanded;
AddSlots(node.GetSlots<ISlot>());
var controlData = GetControlData();
controls.AddRange(controlData);
position = new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0);
m_Version = 0;
m_Preview = previewSystem.GetPreview(inNode);
m_Preview.onPreviewChanged += OnPreviewChanged;
node.onReplaced += OnReplaced;
}
void OnReplaced(INode previous, INode current)
{
node = current as AbstractMaterialNode;
}
void OnPreviewChanged()
{
previewTexture = m_Preview.texture;
m_Version++;
}
public void Dispose()
{
if (m_Preview != null)
{
m_Preview.onPreviewChanged -= OnPreviewChanged;
m_Preview = null;
}
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes.meta


fileFormatVersion: 2
guid: 7e4695133ddd49cf97b1629ca5537e5b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存