浏览代码

Merge remote-tracking branch 'refs/remotes/origin/master' into lt-pipeline-masters

/main
Matt Dean 7 年前
当前提交
fc0d26d6
共有 38 个文件被更改,包括 399 次插入222 次删除
  1. 58
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/NodeUtils.cs
  2. 39
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs
  3. 8
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/ObjectPool.cs
  4. 44
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs
  5. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEditorPresenter.cs
  6. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs
  7. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  8. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs
  9. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  10. 17
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/UIUtilities.cs
  11. 2
      MaterialGraphProject/ProjectSettings/ProjectVersion.txt
  12. 107
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs
  13. 87
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  14. 31
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/AbstractNodeEditorView.cs
  15. 53
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/StandardNodeEditorView.cs
  16. 35
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/SurfaceMasterNodeEditorView.cs
  17. 25
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/QueuePool.cs
  18. 3
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/QueuePool.cs.meta
  19. 25
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/StackPool.cs
  20. 3
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/StackPool.cs.meta
  21. 52
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorPresenter.cs
  22. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters.meta
  23. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views.meta
  24. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorPresenter.cs.meta
  25. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs.meta
  26. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/StandardNodeEditorView.cs.meta
  27. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs
  28. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  29. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs.meta
  30. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/AbstractNodeEditorView.cs
  31. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/AbstractNodeEditorView.cs.meta
  32. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/SurfaceMasterNodeEditorView.cs.meta
  33. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/NodeEditorHeaderView.cs
  34. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/NodeEditorHeaderView.cs.meta
  35. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/StandardNodeEditorView.cs
  36. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/SurfaceMasterNodeEditorView.cs

58
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/NodeUtils.cs


if (node == null)
return;
// already added this node
if (nodeList.Contains(node))
return;
var remapper = node as INodeGroupRemapper;
if (remapper != null)
using (var stackDisposable = StackPool<INode>.GetDisposable())
using (var queueDisposable = QueuePool<INode>.GetDisposable())
remapper.DepthFirstCollectNodesFromNodeSlotList(nodeList, includeSelf);
return;
}
var stack = stackDisposable.value;
var queue = queueDisposable.value;
queue.Enqueue(node);
var ids = node.GetInputSlots<ISlot>().Select(x => x.id);
if (slotIds != null)
ids = node.GetInputSlots<ISlot>().Where(x => slotIds.Contains(x.id)).Select(x => x.id);
foreach (var slot in ids)
{
foreach (var edge in node.owner.GetEdges(node.GetSlotReference(slot)))
while (queue.Any())
var outputNode = node.owner.GetNodeFromGuid(edge.outputSlot.nodeGuid);
DepthFirstCollectNodesFromNode(nodeList, outputNode);
var fromNode = queue.Dequeue();
// already added this node
if (nodeList.Contains(fromNode))
continue;
var remapper = fromNode as INodeGroupRemapper;
if (remapper != null)
{
remapper.DepthFirstCollectNodesFromNodeSlotList(nodeList, includeSelf);
continue;
}
foreach (var slot in fromNode.GetInputSlots<ISlot>())
{
if (slotIds != null && !slotIds.Contains(slot.id))
continue;
foreach (var edge in fromNode.owner.GetEdges(fromNode.GetSlotReference(slot.id)))
{
var outputNode = fromNode.owner.GetNodeFromGuid(edge.outputSlot.nodeGuid);
queue.Enqueue(outputNode);
stack.Push(outputNode);
}
}
}
if (includeSelf == IncludeSelf.Include)
nodeList.Add(node);
while (stack.Any())
nodeList.Add(stack.Pop());
if (includeSelf == IncludeSelf.Include)
nodeList.Add(node);
}
}
public static void CollectNodesNodeFeedsInto(List<INode> nodeList, INode node, IncludeSelf includeSelf = IncludeSelf.Include)

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


List<IEdge> m_Edges = new List<IEdge>();
[NonSerialized]
Dictionary<Guid, List<IEdge>> m_NodeEdges = new Dictionary<Guid, List<IEdge>>();
[NonSerialized]
Dictionary<Guid, INode> m_Nodes = new Dictionary<Guid, INode>();
[SerializeField]

m_Nodes.Remove(node.guid);
}
void AddEdgeToNodeEdges(IEdge edge)
{
List<IEdge> inputEdges;
if (!m_NodeEdges.TryGetValue(edge.inputSlot.nodeGuid, out inputEdges))
m_NodeEdges[edge.inputSlot.nodeGuid] = inputEdges = new List<IEdge>();
inputEdges.Add(edge);
List<IEdge> outputEdges;
if (!m_NodeEdges.TryGetValue(edge.outputSlot.nodeGuid, out outputEdges))
m_NodeEdges[edge.outputSlot.nodeGuid] = outputEdges = new List<IEdge>();
outputEdges.Add(edge);
}
public virtual Dictionary<SerializationHelper.TypeSerializationInfo, SerializationHelper.TypeSerializationInfo> GetLegacyTypeRemapping()
{
return new Dictionary<SerializationHelper.TypeSerializationInfo, SerializationHelper.TypeSerializationInfo>();

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

public virtual void RemoveEdge(IEdge e)
{
m_Edges.Remove(e);
RemoveEdgeNoValidate(e);
ValidateGraph();
}

void RemoveEdgeNoValidate(IEdge e)
{
m_Edges.Remove(e);
List<IEdge> inputNodeEdges;
if (m_NodeEdges.TryGetValue(e.inputSlot.nodeGuid, out inputNodeEdges))
inputNodeEdges.Remove(e);
List<IEdge> outputNodeEdges;
if (m_NodeEdges.TryGetValue(e.outputSlot.nodeGuid, out outputNodeEdges))
outputNodeEdges.Remove(e);
}
public INode GetNodeFromGuid(Guid guid)

public IEnumerable<IEdge> GetEdges(SlotReference s)
{
if (s == null)
return new Edge[0];
return Enumerable.Empty<IEdge>();
List<IEdge> candidateEdges;
if (!m_NodeEdges.TryGetValue(s.nodeGuid, out candidateEdges))
return Enumerable.Empty<IEdge>();
return m_Edges.Where(x =>
return candidateEdges.Where(x =>
|| x.inputSlot.nodeGuid == s.nodeGuid && x.inputSlot.slotId == s.slotId).ToList();
|| x.inputSlot.nodeGuid == s.nodeGuid && x.inputSlot.slotId == s.slotId);
}
public virtual void OnBeforeSerialize()

m_Edges = SerializationHelper.Deserialize<IEdge>(m_SerializableEdges, null);
m_SerializableEdges = null;
foreach (var edge in m_Edges)
AddEdgeToNodeEdges(edge);
ValidateGraph();
}

8
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/ObjectPool.cs


namespace UnityEngine.Graphing
{
internal class ObjectPool<T> where T : new()
class ObjectPool<T> where T : new()
private readonly Stack<T> m_Stack = new Stack<T>();
private readonly UnityAction<T> m_ActionOnGet;
private readonly UnityAction<T> m_ActionOnRelease;
readonly Stack<T> m_Stack = new Stack<T>();
readonly UnityAction<T> m_ActionOnGet;
readonly UnityAction<T> m_ActionOnRelease;
public int countAll { get; private set; }
public int countActive { get { return countAll - countInactive; } }

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


GraphEditorView m_GraphEditorView;
GraphEditorView graphEditorView
{
get { return m_GraphEditorView; }
set
{
if (m_GraphEditorView != null)
m_GraphEditorView.Dispose();
m_GraphEditorView = value;
}
}
public TGraphType inMemoryAsset
{
get { return m_InMemoryAsset; }

void Update()
{
if (m_GraphEditorView != null)
if (graphEditorView != null)
if (m_GraphEditorView.presenter == null)
if (graphEditorView.presenter == null)
m_GraphEditorView.presenter.graphPresenter.UpdateTimeDependentNodes();
graphEditorView.presenter.graphPresenter.UpdateTimeDependentNodes();
m_GraphEditorView = new GraphEditorView();
rootVisualContainer.Add(m_GraphEditorView);
graphEditorView = new GraphEditorView();
rootVisualContainer.Add(graphEditorView);
}
void OnDisable()

{
UpdateAsset();
}
graphEditorView.Dispose();
var presenter = m_GraphEditorView.presenter;
var presenter = graphEditorView.presenter;
var e = Event.current;
if (e.type == EventType.ValidateCommand && (

if (e.type == EventType.KeyDown)
{
if (e.keyCode == KeyCode.A)
m_GraphEditorView.graphView.FrameAll();
graphEditorView.graphView.FrameAll();
m_GraphEditorView.graphView.FrameSelection();
graphEditorView.graphView.FrameSelection();
m_GraphEditorView.graphView.FrameOrigin();
graphEditorView.graphView.FrameOrigin();
m_GraphEditorView.graphView.FrameNext();
graphEditorView.graphView.FrameNext();
m_GraphEditorView.graphView.FramePrev();
graphEditorView.graphView.FramePrev();
}
}

if (path.Length == 0)
return;
var graphPresenter = m_GraphEditorView.presenter.graphPresenter;
var graphPresenter = graphEditorView.presenter.graphPresenter;
var selected = graphPresenter.elements.Where(e => e.selected).ToArray();
var deserialized = MaterialGraphPresenter.DeserializeCopyBuffer(JsonUtility.ToJson(MaterialGraphPresenter.CreateCopyPasteGraph(selected)));

{
var presenter = CreateInstance<GraphEditorPresenter>();
presenter.Initialize(inMemoryAsset, this, selected.name);
m_GraphEditorView.presenter = presenter;
m_GraphEditorView.RegisterCallback<PostLayoutEvent>(OnPostLayout);
graphEditorView.presenter = presenter;
graphEditorView.RegisterCallback<PostLayoutEvent>(OnPostLayout);
m_GraphEditorView.UnregisterCallback<PostLayoutEvent>(OnPostLayout);
m_GraphEditorView.graphView.FrameAll();
graphEditorView.UnregisterCallback<PostLayoutEvent>(OnPostLayout);
graphEditorView.graphView.FrameAll();
}
}
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEditorPresenter.cs


set { m_GraphInspectorPresenter = value; }
}
public void Initialize(IGraph graph, IMaterialGraphEditWindow container, string graphName)
public void Initialize(IGraph graph, IMaterialGraphEditWindow container, string assetName)
m_GraphInspectorPresenter.Initialize(graphName);
m_GraphInspectorPresenter.Initialize(assetName, graph);
m_GraphPresenter = CreateInstance<MaterialGraphPresenter>();
m_GraphPresenter.Initialize(graph, container);

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/NodePreviewPresenter.cs


var resultShader = GetPreviewShaderString();
Debug.Log("RecreateShaderAndMaterial : " + m_Node.GetVariableNameForNode() + Environment.NewLine + resultShader);
string shaderOuputString = resultShader.Replace("UnityEngine.MaterialGraph", "Generated");
System.IO.File.WriteAllText(Application.dataPath + "/GeneratedShader.shader", shaderOuputString);
System.IO.File.WriteAllText(Application.dataPath + "/../GeneratedShader.shader", shaderOuputString);
if (string.IsNullOrEmpty(resultShader))
return false;

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


using System;
using UnityEngine;
using Object = UnityEngine.Object;
public class GraphEditorView : DataWatchContainer
public class GraphEditorView : DataWatchContainer, IDisposable
{
GraphView m_GraphView;
GraphInspectorView m_GraphInspectorView;

protected override Object[] toWatch
{
get { return new Object[] { m_Presenter }; }
}
public void Dispose()
{
if (m_GraphInspectorView != null) m_GraphInspectorView.Dispose();
}
}
}

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


public MaterialGraphView()
{
RegisterCallback<MouseUpEvent>(DoContextMenu, Capture.Capture);
this.AddManipulator(new ContentZoomer());
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
this.AddManipulator(new ContentDragger());
this.AddManipulator(new RectangleSelector());
this.AddManipulator(new SelectionDragger());

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


padding-bottom: 10;
}
GraphInspectorView > #contentContainer > #selectionCount {
text-color: rgb(180, 180, 180);
padding-left: 16;
padding-right: 16;
padding-top: 10;
padding-bottom: 10;
}
.nodeEditor {
border-color: rgb(79, 79, 79);
border-bottom-width: 1;

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


using System;
using System.Linq;
namespace UnityEditor.Graphing.Util
{

}
return true;
}
public static int GetHashCode(params object[] objects)
{
return GetHashCode(objects.AsEnumerable());
}
public static int GetHashCode<T>(IEnumerable<T> objects)
{
var hashCode = 17;
foreach (var @object in objects)
{
hashCode = hashCode * 31 + (@object == null ? 79 : @object.GetHashCode());
}
return hashCode;
}
}
}

2
MaterialGraphProject/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2017.3.0a4
m_EditorVersion: 2017.3.0b1

107
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs


using System;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.Graphing;
using Object = UnityEngine.Object;
public class IMGUISlotEditorView : DataWatchContainer
public class IMGUISlotEditorView : VisualElement
[SerializeField]
IMGUISlotEditorPresenter m_Presenter;
MaterialSlot m_Slot;
int m_SlotsHash;
ConcreteSlotValueType m_CurrentValueType = ConcreteSlotValueType.Error;
public override void OnDataChanged()
public IMGUISlotEditorView(MaterialSlot slot)
if (presenter == null)
{
Clear();
return;
}
if (presenter.slot.concreteValueType == m_CurrentValueType)
return;
Clear();
m_CurrentValueType = presenter.slot.concreteValueType;
Action onGUIHandler;
if (presenter.slot.concreteValueType == ConcreteSlotValueType.Vector4)
onGUIHandler = Vector4OnGUIHandler;
else if (presenter.slot.concreteValueType == ConcreteSlotValueType.Vector3)
onGUIHandler = Vector3OnGUIHandler;
else if (presenter.slot.concreteValueType == ConcreteSlotValueType.Vector2)
onGUIHandler = Vector2OnGUIHandler;
else if (presenter.slot.concreteValueType == ConcreteSlotValueType.Vector1)
onGUIHandler = Vector1OnGUIHandler;
else
return;
Add(new IMGUIContainer(onGUIHandler));
m_Slot = slot;
Add(new IMGUIContainer(OnGUIHandler));
void Vector4OnGUIHandler()
void OnGUIHandler()
if (presenter.slot == null)
if (m_Slot == null)
presenter.value = EditorGUILayout.Vector4Field(presenter.slot.displayName, presenter.value);
var newValue = SlotField(m_Slot);
if (newValue != m_Slot.currentValue)
{
m_Slot.currentValue = newValue;
m_Slot.owner.onModified(m_Slot.owner, ModificationScope.Node);
}
void Vector3OnGUIHandler()
static Vector4 SlotField(MaterialSlot slot)
if (presenter.slot == null)
return;
var previousWideMode = EditorGUIUtility.wideMode;
EditorGUIUtility.wideMode = true;
presenter.value = EditorGUILayout.Vector3Field(presenter.slot.displayName, presenter.value);
EditorGUIUtility.wideMode = previousWideMode;
}
void Vector2OnGUIHandler()
{
if (presenter.slot == null)
return;
var previousWideMode = EditorGUIUtility.wideMode;
EditorGUIUtility.wideMode = true;
presenter.value = EditorGUILayout.Vector2Field(presenter.slot.displayName, presenter.value);
EditorGUIUtility.wideMode = previousWideMode;
}
void Vector1OnGUIHandler()
{
if (presenter.slot == null)
return;
var previousWideMode = EditorGUIUtility.wideMode;
EditorGUIUtility.wideMode = true;
presenter.value = new Vector4(EditorGUILayout.FloatField(presenter.slot.displayName, presenter.value.x), 0, 0, 0);
EditorGUIUtility.wideMode = previousWideMode;
}
protected override Object[] toWatch
{
get { return new Object[] { presenter }; }
}
public IMGUISlotEditorPresenter presenter
{
get { return m_Presenter; }
set
{
if (value == m_Presenter)
return;
RemoveWatch();
m_Presenter = value;
OnDataChanged();
AddWatch();
}
if (slot.concreteValueType == ConcreteSlotValueType.Vector1)
return new Vector4(EditorGUILayout.FloatField(slot.displayName, slot.currentValue.x), 0, 0, 0);
if (slot.concreteValueType == ConcreteSlotValueType.Vector2)
return EditorGUILayout.Vector2Field(slot.displayName, slot.currentValue);
if (slot.concreteValueType == ConcreteSlotValueType.Vector3)
return EditorGUILayout.Vector3Field(slot.displayName, slot.currentValue);
if (slot.concreteValueType == ConcreteSlotValueType.Vector4)
return EditorGUILayout.Vector4Field(slot.displayName, slot.currentValue);
return Vector4.zero;
}
}
}

87
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs


using System;
using System.Linq;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
public class GraphInspectorView : DataWatchContainer
public class GraphInspectorView : VisualElement, IDisposable
int m_EditorHash;
int m_SelectionHash;
VisualElement m_EditorContainer;
VisualElement m_ContentContainer;
AbstractNodeEditorView m_EditorView;
TypeMapper m_TypeMapper;

var headerContainer = new VisualElement() { name = "header" };
m_Title = new VisualElement() { name = "title" };
headerContainer.Add(m_Title);
var headerContainer = new VisualElement { name = "header" };
{
m_Title = new VisualElement() { name = "title" };
headerContainer.Add(m_Title);
}
Add(m_EditorContainer = new VisualElement {name = "editorContainer"});
m_TypeMapper = new TypeMapper(typeof(AbstractNodeEditorPresenter), typeof(AbstractNodeEditorView))
m_ContentContainer = new VisualElement { name = "contentContainer" };
Add(m_ContentContainer);
// Nodes missing custom editors:
// - PropertyNode
// - SubGraphInputNode
// - SubGraphOutputNode
m_TypeMapper = new TypeMapper(typeof(INode), typeof(AbstractNodeEditorView), typeof(StandardNodeEditorView))
{typeof(StandardNodeEditorPresenter), typeof(StandardNodeEditorView)},
{typeof(SurfaceMasterNodeEditorPresenter), typeof(SurfaceMasterNodeEditorView)}
{ typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterNodeEditorView) }
public override void OnDataChanged()
public void OnChange(GraphInspectorPresenter.ChangeType changeType)
m_EditorContainer.Clear();
m_EditorHash = 0;
m_ContentContainer.Clear();
m_SelectionHash = 0;
m_Title.text = presenter.title;
if ((changeType & GraphInspectorPresenter.ChangeType.AssetName) != 0)
m_Title.text = presenter.assetName;
var editorHash = 17;
unchecked
if ((changeType & GraphInspectorPresenter.ChangeType.SelectedNodes) != 0)
foreach (var editorPresenter in presenter.editors)
editorHash = editorHash * 31 + editorPresenter.GetHashCode();
}
if (editorHash != m_EditorHash)
{
m_EditorHash = editorHash;
m_EditorContainer.Clear();
foreach (var editorPresenter in presenter.editors)
var selectionHash = UIUtilities.GetHashCode(presenter.selectedNodes.Count, presenter.selectedNodes != null ? presenter.selectedNodes.FirstOrDefault() : null);
if (selectionHash != m_SelectionHash)
var view = (AbstractNodeEditorView) Activator.CreateInstance(m_TypeMapper.MapType(editorPresenter.GetType()));
view.presenter = editorPresenter;
m_EditorContainer.Add(view);
m_SelectionHash = selectionHash;
m_ContentContainer.Clear();
if (presenter.selectedNodes.Count > 1)
{
var element = new VisualElement { name = "selectionCount", text = string.Format("{0} nodes selected.", presenter.selectedNodes.Count) };
m_ContentContainer.Add(element);
}
else if (presenter.selectedNodes.Count == 1)
{
var node = presenter.selectedNodes.First();
var view = (AbstractNodeEditorView)Activator.CreateInstance(m_TypeMapper.MapType(node.GetType()));
view.node = node;
m_ContentContainer.Add(view);
}
Dirty(ChangeType.Repaint);
}
public GraphInspectorPresenter presenter

{
if (m_Presenter == value)
return;
RemoveWatch();
if (m_Presenter != null)
m_Presenter.onChange -= OnChange;
OnDataChanged();
AddWatch();
OnChange(GraphInspectorPresenter.ChangeType.All);
m_Presenter.onChange += OnChange;
protected override Object[] toWatch
public void Dispose()
get { return new Object[] {m_Presenter}; }
if (m_Presenter != null)
m_Presenter.onChange -= OnChange;
}
}
}

31
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/AbstractNodeEditorView.cs


using UnityEditor.Experimental.UIElements.GraphView;
using System;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Graphing;
public class AbstractNodeEditorView : DataWatchContainer
public abstract class AbstractNodeEditorView : VisualElement, IDisposable
[SerializeField]
AbstractNodeEditorPresenter m_Presenter;
public abstract INode node { get; set; }
public AbstractNodeEditorPresenter presenter
{
get { return m_Presenter; }
set
{
if (value == m_Presenter)
return;
RemoveWatch();
m_Presenter = value;
m_ToWatch[0] = m_Presenter;
OnDataChanged();
AddWatch();
}
}
Object[] m_ToWatch = { null };
protected override Object[] toWatch
{
get { return m_ToWatch; }
}
public abstract void Dispose();
}
}

53
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/StandardNodeEditorView.cs


using System.Linq;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.Graphing.Util;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing.Inspector
{

VisualElement m_SlotsContainer;
VisualElement m_DefaultSlotValuesSection;
AbstractMaterialNode m_Node;
int m_SlotsHash;
new StandardNodeEditorPresenter presenter
public override INode node
{
get { return m_Node; }
set
{
if (value == m_Node)
return;
if (m_Node != null)
m_Node.onModified -= OnModified;
m_Node = value as AbstractMaterialNode;
OnModified(m_Node, ModificationScope.Node);
if (m_Node != null)
m_Node.onModified += OnModified;
}
}
public override void Dispose()
get { return (StandardNodeEditorPresenter) base.presenter; }
if (m_Node != null)
m_Node.onModified -= OnModified;
}
public StandardNodeEditorView()

Add(m_DefaultSlotValuesSection);
}
public override void OnDataChanged()
void OnModified(INode changedNode, ModificationScope scope)
if (presenter == null)
if (node == null)
m_HeaderView.title = presenter.node.name;
m_HeaderView.title = node.name;
var slotsHash = UIUtilities.GetHashCode(node.GetInputSlots<MaterialSlot>().Select(s => UIUtilities.GetHashCode(s.slotReference.nodeGuid.GetHashCode(), s.slotReference.slotId)));
m_SlotsContainer.Clear();
foreach (var slotEditorPresenter in presenter.slotEditorPresenters)
if (slotsHash != m_SlotsHash)
m_SlotsContainer.Add(new IMGUISlotEditorView { presenter = slotEditorPresenter });
}
m_SlotsHash = slotsHash;
m_SlotsContainer.Clear();
foreach (var slot in node.GetInputSlots<MaterialSlot>())
m_SlotsContainer.Add(new IMGUISlotEditorView(slot));
if (m_SlotsContainer.Any())
m_DefaultSlotValuesSection.RemoveFromClassList("hidden");
else
m_DefaultSlotValuesSection.AddToClassList("hidden");
if (m_SlotsContainer.Any())
m_DefaultSlotValuesSection.RemoveFromClassList("hidden");
else
m_DefaultSlotValuesSection.AddToClassList("hidden");
}
}
}
}

35
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/SurfaceMasterNodeEditorView.cs


public class SurfaceMasterNodeEditorView : AbstractNodeEditorView
{
NodeEditorHeaderView m_HeaderView;
AbstractSurfaceMasterNode m_Node;
new SurfaceMasterNodeEditorPresenter presenter
public override INode node
{
get { return m_Node; }
set
{
if (value == m_Node)
return;
if (m_Node != null)
m_Node.onModified -= OnModified;
m_Node = value as AbstractSurfaceMasterNode;
OnModified(m_Node, ModificationScope.Node);
if (m_Node != null)
m_Node.onModified += OnModified;
}
}
public override void Dispose()
get { return (SurfaceMasterNodeEditorPresenter)base.presenter; }
if (m_Node != null)
m_Node.onModified -= OnModified;
}
public SurfaceMasterNodeEditorView()

void OnGUIHandler()
{
if (presenter == null)
if (m_Node == null)
var options = presenter.node.options;
var options = m_Node.options;
EditorGUI.BeginChangeCheck();
options.srcBlend = (SurfaceMaterialOptions.BlendMode)EditorGUILayout.EnumPopup("Src Blend", options.srcBlend);

options.renderQueue = (SurfaceMaterialOptions.RenderQueue)EditorGUILayout.EnumPopup("Render Queue", options.renderQueue);
options.renderType = (SurfaceMaterialOptions.RenderType)EditorGUILayout.EnumPopup("Render Type", options.renderType);
if (EditorGUI.EndChangeCheck())
presenter.node.onModified(presenter.node, ModificationScope.Graph);
m_Node.onModified(m_Node, ModificationScope.Graph);
public override void OnDataChanged()
void OnModified(INode changedNode, ModificationScope scope)
if (presenter == null)
if (m_Node == null)
m_HeaderView.title = presenter.node.name;
m_HeaderView.title = m_Node.name;
Dirty(ChangeType.Repaint);
}
}
}

25
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/QueuePool.cs


using System.Collections.Generic;
namespace UnityEngine.Graphing
{
public static class QueuePool<T>
{
// Object pool to avoid allocations.
static readonly ObjectPool<Queue<T>> k_QueuePool = new ObjectPool<Queue<T>>(null, l => l.Clear());
public static Queue<T> Get()
{
return k_QueuePool.Get();
}
public static PooledObject<Queue<T>> GetDisposable()
{
return k_QueuePool.GetDisposable();
}
public static void Release(Queue<T> toRelease)
{
k_QueuePool.Release(toRelease);
}
}
}

3
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/QueuePool.cs.meta


fileFormatVersion: 2
guid: 4e895afeaf2a438195fbc4de17a4bedc
timeCreated: 1505278549

25
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/StackPool.cs


using System.Collections.Generic;
namespace UnityEngine.Graphing
{
public static class StackPool<T>
{
// Object pool to avoid allocations.
static readonly ObjectPool<Stack<T>> k_StackPool = new ObjectPool<Stack<T>>(null, l => l.Clear());
public static Stack<T> Get()
{
return k_StackPool.Get();
}
public static PooledObject<Stack<T>> GetDisposable()
{
return k_StackPool.GetDisposable();
}
public static void Release(Stack<T> toRelease)
{
k_StackPool.Release(toRelease);
}
}
}

3
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Util/StackPool.cs.meta


fileFormatVersion: 2
guid: 93c41a4331c94d09a7561ea6b4983439
timeCreated: 1505275069

52
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorPresenter.cs


using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.MaterialGraph.Drawing.Inspector
{
public class GraphInspectorPresenter : ScriptableObject
{
public IGraph graph { get; set; }
public string assetName { get; set; }
public List<INode> selectedNodes { get; set; }
[Flags]
public enum ChangeType
{
Graph = 1 << 0,
SelectedNodes = 1 << 1,
AssetName = 1 << 2,
All = -1
}
public delegate void OnChange(ChangeType changeType);
public OnChange onChange;
public void Initialize(string assetName, IGraph graph)
{
this.graph = graph;
this.assetName = assetName;
selectedNodes = new List<INode>();
Change(ChangeType.Graph | ChangeType.SelectedNodes | ChangeType.AssetName);
}
public void UpdateSelection(IEnumerable<INode> nodes)
{
selectedNodes.Clear();
selectedNodes.AddRange(nodes);
Change(ChangeType.SelectedNodes);
}
void Change(ChangeType changeType)
{
if (onChange != null)
onChange(changeType);
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters.meta


fileFormatVersion: 2
guid: 2d08dfb360644031a5e64558d4a93263
timeCreated: 1503663071

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views.meta


fileFormatVersion: 2
guid: 0969ff891b874694aa732e1240ee159b
timeCreated: 1503663067

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/GraphInspectorPresenter.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorPresenter.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/IMGUISlotEditorView.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/StandardNodeEditorView.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/StandardNodeEditorView.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/IMGUISlotEditorView.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/GraphInspectorView.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/GraphInspectorView.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/AbstractNodeEditorView.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/AbstractNodeEditorView.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/AbstractNodeEditorView.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/AbstractNodeEditorView.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/SurfaceMasterNodeEditorView.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/SurfaceMasterNodeEditorView.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/NodeEditorHeaderView.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/NodeEditorHeaderView.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/NodeEditorHeaderView.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/NodeEditorHeaderView.cs.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/StandardNodeEditorView.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/StandardNodeEditorView.cs

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/SurfaceMasterNodeEditorView.cs → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/SurfaceMasterNodeEditorView.cs

正在加载...
取消
保存