浏览代码

Merge commit '76ff1855a761cc5b39944f12a7456bbed2c79efb' into exposed-prop-subgraph

/main
Tim Cooper 7 年前
当前提交
9557fcee
共有 52 个文件被更改,包括 1235 次插入724 次删除
  1. 26
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/Edge.cs
  2. 97
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs
  3. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs
  4. 26
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableSlot.cs
  5. 41
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/GraphChange.cs
  6. 4
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/IEdge.cs
  7. 1
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/IGraph.cs
  8. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/INode.cs
  9. 4
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/ISlot.cs
  10. 25
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/SlotReference.cs
  11. 217
      MaterialGraphProject/Assets/PartyPreview.ShaderGraph
  12. 5
      MaterialGraphProject/Assets/PartyPreview.ShaderGraph.meta
  13. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs
  14. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorPresenter.cs
  15. 183
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  16. 17
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs
  17. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEditorPresenter.cs
  18. 237
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  19. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialNodePresenter.cs
  20. 67
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs
  21. 71
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  22. 54
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
  23. 130
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  24. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/UIUtilities.cs
  25. 72
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/AbstractMaterialGraph.cs
  26. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/AbstractShaderProperty.cs
  27. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/TextureShaderProperty.cs
  28. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/AbstractLightweightMasterNode.cs
  29. 17
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
  30. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MasterRemapGraph.cs
  31. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/AbstractSubGraphNode.cs
  32. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphOutputNode.cs
  33. 2
      MaterialGraphProject/ProjectSettings/ProjectVersion.txt
  34. 105
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs
  35. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs.meta
  36. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewRate.cs
  37. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewRate.cs.meta
  38. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/ToolbarView.cs
  39. 28
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Interfaces/MaterialGraphChange.cs
  40. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Interfaces/MaterialGraphChange.cs.meta
  41. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PreviewNode.cs
  42. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PreviewNode.cs.meta
  43. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TitleBarButtonPresenter.cs
  44. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TitleBarButtonPresenter.cs.meta
  45. 83
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TitleBarPresenter.cs
  46. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TitleBarPresenter.cs.meta
  47. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/TitleBarButtonView.cs.meta
  48. 81
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/TitleBarButtonView.cs
  49. 68
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/TitleBarView.cs
  50. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/TitleBar.uss.meta
  51. 54
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/TitleBar.uss
  52. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/ToolbarView.cs.meta

26
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/Edge.cs


{
get { return m_InputSlot; }
}
protected bool Equals(Edge other)
{
return Equals(m_OutputSlot, other.m_OutputSlot) && Equals(m_InputSlot, other.m_InputSlot);
}
public bool Equals(IEdge other)
{
return Equals(other as object);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((Edge)obj);
}
public override int GetHashCode()
{
unchecked
{
return ((m_OutputSlot != null ? m_OutputSlot.GetHashCode() : 0) * 397) ^ (m_InputSlot != null ? m_InputSlot.GetHashCode() : 0);
}
}
}
}

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


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using NUnit.Framework;
namespace UnityEngine.Graphing
{

public virtual void AddNode(INode node)
{
AddNodeNoValidate(node);
ValidateGraph();
}
void AddNodeNoValidate(INode node)
{
ValidateGraph();
}
public virtual void RemoveNode(INode node)

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

void RemoveEdgeNoValidate(IEdge e)
{
e = m_Edges.FirstOrDefault(x => x.Equals(e));
Assert.NotNull(e);
m_Edges.Remove(e);
List<IEdge> inputNodeEdges;

List<IEdge> outputNodeEdges;
if (m_NodeEdges.TryGetValue(e.outputSlot.nodeGuid, out outputNodeEdges))
outputNodeEdges.Remove(e);
NotifyChange(new EdgeRemovedGraphChange(e));
}
public INode GetNodeFromGuid(Guid guid)

if (s == null)
return Enumerable.Empty<IEdge>();
var node = GetNodeFromGuid(s.nodeGuid);
if (node == null)
{
Debug.LogWarning("Node does not exist");
return Enumerable.Empty<IEdge>();
}
ISlot slot = slot = node.FindSlot<ISlot>(s.slotId);
return candidateEdges.Where(x =>
(x.outputSlot.nodeGuid == s.nodeGuid && x.outputSlot.slotId == s.slotId)
|| x.inputSlot.nodeGuid == s.nodeGuid && x.inputSlot.slotId == s.slotId);
return candidateEdges.Where(candidateEdge =>
{
var cs = slot.isInputSlot ? candidateEdge.inputSlot : candidateEdge.outputSlot;
return cs.nodeGuid == s.nodeGuid && cs.slotId == s.slotId;
});
}
public virtual void OnBeforeSerialize()

node.ValidateNode();
}
public virtual void ReplaceWith(IGraph other)
{
using (var pooledList = ListPool<IEdge>.GetDisposable())
{
var removedNodeEdges = pooledList.value;
foreach (var edge in m_Edges)
{
// Remove the edge if it doesn't exist in the other graph.
if (!other.ContainsNodeGuid(edge.inputSlot.nodeGuid) || !other.GetEdges(edge.inputSlot).Any(otherEdge => otherEdge.outputSlot.Equals(edge.outputSlot)))
removedNodeEdges.Add(edge);
}
foreach (var edge in removedNodeEdges)
RemoveEdge(edge);
}
using (var removedNodesPooledObject = ListPool<Guid>.GetDisposable())
using (var replacedNodesPooledObject = ListPool<INode>.GetDisposable())
{
var removedNodeGuids = removedNodesPooledObject.value;
var replacedNodes = replacedNodesPooledObject.value;
foreach (var node in m_Nodes.Values)
{
if (!other.ContainsNodeGuid(node.guid))
// Remove the node if it doesn't exist in the other graph.
removedNodeGuids.Add(node.guid);
else
// Replace the node with the one from the other graph otherwise.
replacedNodes.Add(node);
}
foreach (var nodeGuid in removedNodeGuids)
RemoveNode(m_Nodes[nodeGuid]);
foreach (var node in replacedNodes)
{
var currentNode = other.GetNodeFromGuid(node.guid);
currentNode.owner = this;
m_Nodes[node.guid] = currentNode;
currentNode.onModified = node.onModified;
currentNode.onReplaced = node.onReplaced;
// Notify listeners that the reference has changed.
if (node.onReplaced != null)
node.onReplaced(node, currentNode);
if (currentNode.onModified != null)
currentNode.onModified(node, ModificationScope.Node);
node.onModified = null;
node.onReplaced = null;
}
}
// Add nodes from other graph which don't exist in this one.
foreach (var node in other.GetNodes<INode>())
{
if (!ContainsNodeGuid(node.guid))
AddNode(node);
}
// Add edges from other graph which don't exist in this one.
foreach (var edge in other.edges)
{
if (!GetEdges(edge.inputSlot).Any(otherEdge => otherEdge.outputSlot.Equals(edge.outputSlot)))
Connect(edge.outputSlot, edge.inputSlot);
}
}
public void OnEnable()
{
foreach (var node in GetNodes<INode>().OfType<IOnAssetEnabled>())

public OnGraphChange onChange { get; set; }
void NotifyChange(GraphChange change)
protected void NotifyChange(GraphChange change)
{
if (onChange != null)
onChange(change);

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs


public OnNodeModified onModified { get; set; }
public OnNodeReplaced onReplaced { get; set; }
public IEnumerable<T> GetInputSlots<T>() where T : ISlot
{
return GetSlots<T>().Where(x => x.isInputSlot);

26
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableSlot.cs


m_SlotType = slotType;
m_Hidden = hidden;
}
protected bool Equals(SerializableSlot other)
{
return m_Id == other.m_Id && owner.guid.Equals(other.owner.guid);
}
public bool Equals(ISlot other)
{
return Equals(other as object);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((SerializableSlot)obj);
}
public override int GetHashCode()
{
unchecked
{
return (m_Id * 397) ^ (owner != null ? owner.GetHashCode() : 0);
}
}
}
}

41
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/GraphChange.cs


using System;
namespace UnityEngine.Graphing
{
public abstract class GraphChange {}

}
public INode node { get; private set; }
}
public sealed class EdgeAddedGraphChange : GraphChange
{
public EdgeAddedGraphChange(IEdge edge)
{
this.edge = edge;
}
public IEdge edge { get; private set; }
}
public sealed class EdgeRemovedGraphChange : GraphChange
{
public EdgeRemovedGraphChange(IEdge edge)
{
this.edge = edge;
}
public IEdge edge { get; private set; }
}
public static class GraphChangeExtensions
{
public static void Match(this GraphChange change,
Action<NodeAddedGraphChange> nodeAdded = null,
Action<NodeRemovedGraphChange> nodeRemoved = null,
Action<EdgeAddedGraphChange> edgeAdded = null,
Action<EdgeRemovedGraphChange> edgeRemoved = null)
{
if (change is NodeAddedGraphChange && nodeAdded != null)
nodeAdded((NodeAddedGraphChange)change);
else if (change is NodeRemovedGraphChange && nodeRemoved != null)
nodeRemoved((NodeRemovedGraphChange)change);
else if (change is EdgeAddedGraphChange && edgeAdded != null)
edgeAdded((EdgeAddedGraphChange)change);
else if (change is EdgeRemovedGraphChange && edgeRemoved != null)
edgeRemoved((EdgeRemovedGraphChange)change);
}
}
}

4
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/IEdge.cs


using System;
public interface IEdge
public interface IEdge : IEquatable<IEdge>
{
SlotReference outputSlot { get; }
SlotReference inputSlot { get; }

1
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/IGraph.cs


T GetNodeFromGuid<T>(Guid guid) where T : INode;
IEnumerable<IEdge> GetEdges(SlotReference s);
void ValidateGraph();
void ReplaceWith(IGraph other);
OnGraphChange onChange { get; set; }
}
}

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/INode.cs


}
public delegate void OnNodeModified(INode node, ModificationScope scope);
public delegate void OnNodeReplaced(INode previous, INode current);
OnNodeReplaced onReplaced { get; set; }
IGraph owner { get; set; }
Guid guid { get; }
Guid RewriteGuid();

4
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/ISlot.cs


using System;
public interface ISlot
public interface ISlot : IEquatable<ISlot>
{
int id { get; }
string displayName { get; set; }

25
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/SlotReference.cs


namespace UnityEngine.Graphing
{
[Serializable]
public class SlotReference : ISerializationCallbackReceiver
public class SlotReference : ISerializationCallbackReceiver, IEquatable<SlotReference>
{
[SerializeField]
private int m_SlotId;

public void OnAfterDeserialize()
{
m_NodeGUID = new Guid(m_NodeGUIDSerialized);
}
public bool Equals(SlotReference other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return m_SlotId == other.m_SlotId && m_NodeGUID.Equals(other.m_NodeGUID);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((SlotReference)obj);
}
public override int GetHashCode()
{
unchecked
{
return (m_SlotId * 397) ^ m_NodeGUID.GetHashCode();
}
}
}
}

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

5
MaterialGraphProject/Assets/PartyPreview.ShaderGraph.meta


fileFormatVersion: 2
guid: e67b8be7b087145ab87b7ae0a690c35e
timeCreated: 1505629362
licenseType: Pro
nonModifiableTextures: []
nonModifiableTextures:
- Texture: {fileID: 2800000, guid: e2e7994f2c9b58f40aaebdaabbbd0ad8, type: 3}
userData:
assetBundleName:
assetBundleVariant:

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


void Repaint();
void ToggleRequiresTime();
void ToSubGraph();
void Show();

public abstract AbstractMaterialGraph GetMaterialGraph();
public abstract void PingAsset();
public abstract void UpdateAsset();
public abstract void ToggleRequiresTime();
public abstract void ToSubGraph();
public abstract Object selected { get; set; }
public abstract void ChangeSelection(Object newSelection);

public abstract class AbstractMaterialGraphEditWindow<TGraphType> : HelperMaterialGraphEditWindow where TGraphType : AbstractMaterialGraph
{
public static bool allowAlwaysRepaint = true;
[SerializeField]
Object m_Selected;

void OnEnable()
{
graphEditorView = new GraphEditorView();
graphEditorView.onUpdateAssetClick += UpdateAsset;
graphEditorView.onConvertToSubgraphClick += ToSubGraph;
graphEditorView.onShowInProjectClick += PingAsset;
rootVisualContainer.Add(graphEditorView);
}

return;
var subGraphNode = new SubGraphNode();
graphPresenter.AddNode(subGraphNode);
graphPresenter.graph.AddNode(subGraphNode);
subGraphNode.subGraphAsset = subGraph;
/* foreach (var edgeMap in inputsNeedingConnection)

File.WriteAllText(path, EditorJsonUtility.ToJson(inMemoryAsset, true));
shaderImporter.SaveAndReimport();
AssetDatabase.ImportAsset(path);
}
public override void ToggleRequiresTime()
{
allowAlwaysRepaint = !allowAlwaysRepaint;
}
public override void ChangeSelection(Object newSelection)

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


this.assetName = assetName;
selectedNodes = new List<INode>();
Change(ChangeType.Graph | ChangeType.SelectedNodes | ChangeType.AssetName);
NotifyChange(ChangeType.Graph | ChangeType.SelectedNodes | ChangeType.AssetName);
Change(ChangeType.PreviewTexture);
NotifyChange(ChangeType.PreviewTexture);
}
public void UpdateSelection(IEnumerable<INode> nodes)

Change(ChangeType.SelectedNodes);
NotifyChange(ChangeType.SelectedNodes);
void Change(ChangeType changeType)
void NotifyChange(ChangeType changeType)
{
if (onChange != null)
onChange(changeType);

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


using System;
using System.Linq;
using UnityEditor.Graphing.Util;
using UnityEditor.Graphing.Util;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleEnums;

int m_SelectionHash;
VisualElement m_Title;
VisualElement m_PropertiesContainer;
VisualElement m_PropertyItems;
VisualElement m_TopContainer;
var topContainer = new VisualElement { name = "top" };
m_TopContainer = new VisualElement { name = "top" };
{
var headerContainer = new VisualElement { name = "header" };
{

topContainer.Add(headerContainer);
m_TopContainer.Add(headerContainer);
topContainer.Add(m_ContentContainer);
m_TopContainer.Add(m_ContentContainer);
Add(topContainer);
ReaddProps();
Add(m_TopContainer);
var propertiesContainer = new VisualElement { name = "properties" };
{
var header = new VisualElement { name = "header" };
{
var title = new VisualElement { name = "title", text = "Properties" };
header.Add(title);
var addPropertyButton = new Button(OnAddProperty) { text = "Add", name = "addButton" };
header.Add(addPropertyButton);
}
propertiesContainer.Add(header);
m_PropertyItems = new VisualContainer { name = "items" };
propertiesContainer.Add(m_PropertyItems);
}
bottomContainer.Add(propertiesContainer);
m_Preview = new Image { name = "preview", image = Texture2D.blackTexture};
bottomContainer.Add(m_Preview);
}

};
}
private void ReaddProps()
{
if (m_PropertiesContainer != null)
Remove(m_PropertiesContainer);
m_PropertiesContainer = new VisualElement()
{
new IMGUIContainer(OnGuiHandler)
};
m_PropertiesContainer.style.flexDirection = StyleValue<FlexDirection>.Create(FlexDirection.Column);
Add(m_PropertiesContainer);
}
private void OnGuiHandler()
void OnAddProperty()
if (m_Presenter == null)
return;
if (GUILayout.Button("Add Property"))
{
var gm = new GenericMenu();
gm.AddItem(new GUIContent("Float"), false, () =>
{
m_Presenter.graph.AddShaderProperty(new FloatShaderProperty());
ReaddProps();
});
gm.AddItem(new GUIContent("Vector2"), false, () =>
{
m_Presenter.graph.AddShaderProperty(new Vector2ShaderProperty());
ReaddProps();
});
gm.AddItem(new GUIContent("Vector3"), false, () =>
{
m_Presenter.graph.AddShaderProperty(new Vector3ShaderProperty());
ReaddProps();
});
gm.AddItem(new GUIContent("Vector4"), false, () =>
{
m_Presenter.graph.AddShaderProperty(new Vector4ShaderProperty());
ReaddProps();
});
gm.AddItem(new GUIContent("Color"), false, () =>
{
m_Presenter.graph.AddShaderProperty(new ColorShaderProperty());
ReaddProps();
});
gm.AddItem(new GUIContent("Texture"), false, () =>
{
m_Presenter.graph.AddShaderProperty(new TextureShaderProperty());
ReaddProps();
});
var gm = new GenericMenu();
gm.AddItem(new GUIContent("Float"), false, () => m_Presenter.graph.AddShaderProperty(new FloatShaderProperty()));
gm.AddItem(new GUIContent("Vector2"), false, () => m_Presenter.graph.AddShaderProperty(new Vector2ShaderProperty()));
gm.AddItem(new GUIContent("Vector3"), false, () => m_Presenter.graph.AddShaderProperty(new Vector3ShaderProperty()));
gm.AddItem(new GUIContent("Vector4"), false, () => m_Presenter.graph.AddShaderProperty(new Vector4ShaderProperty()));
gm.AddItem(new GUIContent("Color"), false, () => m_Presenter.graph.AddShaderProperty(new ColorShaderProperty()));
gm.AddItem(new GUIContent("Texture"), false, () => m_Presenter.graph.AddShaderProperty(new TextureShaderProperty()));
EditorGUI.BeginChangeCheck();
foreach (var property in m_Presenter.graph.properties.ToArray())
{
property.displayName = EditorGUILayout.DelayedTextField("Display Name", property.displayName);
if (property is FloatShaderProperty)
{
var fProp = property as FloatShaderProperty;
fProp.value = EditorGUILayout.FloatField("Value", fProp.value);
}
else if (property is Vector2ShaderProperty)
{
var fProp = property as Vector2ShaderProperty;
fProp.value = EditorGUILayout.Vector2Field("Value", fProp.value);
}
else if (property is Vector3ShaderProperty)
{
var fProp = property as Vector3ShaderProperty;
fProp.value = EditorGUILayout.Vector3Field("Value", fProp.value);
}
else if (property is Vector4ShaderProperty)
{
var fProp = property as Vector4ShaderProperty;
fProp.value = EditorGUILayout.Vector4Field("Value", fProp.value);
}
else if (property is ColorShaderProperty)
{
var fProp = property as ColorShaderProperty;
fProp.value = EditorGUILayout.ColorField("Value", fProp.value);
}
else if (property is TextureShaderProperty)
{
var fProp = property as TextureShaderProperty;
fProp.value.texture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), fProp.value.texture, typeof(Texture), null) as Texture;
fProp.modifiable = EditorGUILayout.Toggle("Modifiable", fProp.modifiable);
}
if (GUILayout.Button("Remove"))
{
m_Presenter.graph.RemoveShaderProperty(property.guid);
}
EditorGUILayout.Separator();
}
if (EditorGUI.EndChangeCheck())
{
foreach (var node in m_Presenter.graph.GetNodes<PropertyNode>())
node.onModified(node, ModificationScope.Node);
}
}
public void OnChange(GraphInspectorPresenter.ChangeType changeType)
{
if (presenter == null)

{
m_Preview.image = presenter.previewTexture ?? Texture2D.blackTexture;
}
if ((changeType & GraphInspectorPresenter.ChangeType.Graph) != 0)
{
if (m_Graph != null)
{
m_Graph.onChange -= OnGraphChange;
m_PropertyItems.Clear();
m_Graph = null;
}
if (m_Presenter.graph != null)
{
m_Graph = m_Presenter.graph;
foreach (var property in m_Graph.properties)
m_PropertyItems.Add(new ShaderPropertyView(m_Graph, property));
m_Graph.onChange += OnGraphChange;
}
}
void OnGraphChange(GraphChange change)
{
var propertyAdded = change as ShaderPropertyAdded;
if (propertyAdded != null)
m_PropertyItems.Add(new ShaderPropertyView(m_Graph, propertyAdded.shaderProperty));
var propertyRemoved = change as ShaderPropertyRemoved;
if (propertyRemoved != null)
{
var propertyView = m_PropertyItems.OfType<ShaderPropertyView>().FirstOrDefault(v => v.property.guid == propertyRemoved.guid);
if (propertyView != null)
m_PropertyItems.Remove(propertyView);
}
}
AbstractMaterialGraph m_Graph;
public GraphInspectorPresenter presenter
{

17
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphPreviewGenerator.cs


Light1.color = new Color(.4f, .4f, .45f, 0f) * .7f;
m_CheckerboardMaterial = new Material(Shader.Find("Hidden/Checkerboard"));
m_CheckerboardMaterial.SetFloat("_X", 32);
m_CheckerboardMaterial.SetFloat("_Y", 32);
if (s_Meshes[0] == null)
{

return;
m_Camera.targetTexture = renderTexture;
Unsupported.SetOverrideRenderSettings(m_Scene);
RenderTexture.active = renderTexture;
GL.Clear(true, true, Color.black);
m_CheckerboardMaterial.SetFloat("_X", 32);
m_CheckerboardMaterial.SetFloat("_Y", 32);
Graphics.Blit(Texture2D.whiteTexture, renderTexture, m_CheckerboardMaterial);
if (mode == PreviewMode.Preview3D)
{
m_Camera.transform.position = -Vector3.forward * 5;

m_Camera.orthographic = true;
}
var ambientProbe = RenderSettings.ambientProbe;
Unsupported.SetOverrideRenderSettings(m_Scene);
RenderSettings.ambientProbe = ambientProbe;
RenderTexture.active = renderTexture;
GL.Clear(true, true, Color.black);
Graphics.Blit(Texture2D.whiteTexture, renderTexture, m_CheckerboardMaterial);
EditorUtility.SetCameraAnimateMaterialsTime(m_Camera, time);
Light0.enabled = true;

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


public class GraphEditorPresenter : ScriptableObject, IDisposable
{
[SerializeField]
TitleBarPresenter m_TitleBarPresenter;
[SerializeField]
MaterialGraphPresenter m_GraphPresenter;
[SerializeField]

public TitleBarPresenter titleBarPresenter
public PreviewRate previewRate
get { return m_TitleBarPresenter; }
set { m_TitleBarPresenter = value; }
get { return m_PreviewSystem.previewRate; }
set { m_PreviewSystem.previewRate = value; }
}
public MaterialGraphPresenter graphPresenter

public void Initialize(AbstractMaterialGraph graph, HelperMaterialGraphEditWindow container, string assetName)
{
m_PreviewSystem = new PreviewSystem(graph);
m_TitleBarPresenter = CreateInstance<TitleBarPresenter>();
m_TitleBarPresenter.Initialize(container);
m_GraphInspectorPresenter = CreateInstance<GraphInspectorPresenter>();
m_GraphInspectorPresenter.Initialize(assetName, m_PreviewSystem, container);

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


namespace UnityEditor.MaterialGraph.Drawing
{
public class MaterialGraphObject : ScriptableObject
{
[SerializeField]
public string serializedGraph;
[SerializeField]
public int version;
}
[Serializable]
public class MaterialGraphPresenter : GraphViewPresenter
{

[SerializeField]
IMaterialGraphEditWindow m_Container;
[SerializeField]
MaterialGraphObject m_GraphObject;
[SerializeField]
int m_GraphVersion;
protected MaterialGraphPresenter()
{

drawableNodeData.OnModified(scope);
}
if (scope == ModificationScope.Topological)
UpdateData();
// We might need to do something here
// if (scope == ModificationScope.Topological)
void UpdateData()
public virtual void Initialize(IGraph graph, IMaterialGraphEditWindow container, PreviewSystem previewSystem)
var deletedElementPresenters = new List<GraphElementPresenter>();
// Find all nodes currently being drawn which are no longer in the graph (i.e. deleted)
foreach (var presenter in m_Elements)
{
var nodePresenter = presenter as MaterialNodePresenter;
if (nodePresenter != null && !graph.ContainsNodeGuid(nodePresenter.node.guid))
{
nodePresenter.Dispose();
deletedElementPresenters.Add(nodePresenter);
}
}
m_PreviewSystem = previewSystem;
this.graph = graph;
m_Container = container;
// Find all edges currently being drawn which are no longer in the graph (i.e. deleted)
var deletedEdgePresenters = m_Elements.OfType<GraphEdgePresenter>()
.Where(ed => !graph.edges.Contains(ed.edge));
foreach (var edgePresenter in deletedEdgePresenters)
{
// Make sure to disconnect the node, otherwise new connections won't be allowed for the used slots
edgePresenter.output.Disconnect(edgePresenter);
edgePresenter.input.Disconnect(edgePresenter);
if (graph == null)
return;
var fromNodeGuid = edgePresenter.edge.outputSlot.nodeGuid;
var fromNodePresenter = m_Elements.OfType<MaterialNodePresenter>().FirstOrDefault(nd => nd.node.guid == fromNodeGuid);
foreach (var node in graph.GetNodes<INode>())
NodeAdded(new NodeAddedGraphChange(node));
foreach (var edge in graph.edges)
EdgeAdded(new EdgeAddedGraphChange(edge));
var toNodeGuid = edgePresenter.edge.inputSlot.nodeGuid;
var toNode = graph.GetNodeFromGuid(toNodeGuid);
this.graph.onChange += OnChange;
if (toNode != null && toNode.onModified != null)
// Make the input node (i.e. right side of the connection) re-render
toNode.onModified(toNode, ModificationScope.Graph);
m_GraphObject = CreateInstance<MaterialGraphObject>();
Undo.undoRedoPerformed += UndoRedoPerformed;
deletedElementPresenters.Add(edgePresenter);
}
RecordState();
}
// Remove all nodes and edges marked for deletion
foreach (var elementPresenter in deletedElementPresenters)
void UndoRedoPerformed()
{
if (m_GraphObject.version != m_GraphVersion)
m_Elements.Remove(elementPresenter);
var targetGraph = JsonUtility.FromJson(m_GraphObject.serializedGraph, graph.GetType()) as IGraph;
graph.ReplaceWith(targetGraph);
m_GraphVersion = m_GraphObject.version;
}
var addedNodePresenters = new List<MaterialNodePresenter>();
void RecordState()
{
m_GraphObject.serializedGraph = JsonUtility.ToJson(graph, false);
m_GraphObject.version++;
m_GraphVersion = m_GraphObject.version;
}
// Find all new nodes and mark for addition
foreach (var node in graph.GetNodes<INode>())
{
// Check whether node already exists
if (m_Elements.OfType<MaterialNodePresenter>().Any(e => e.node == node))
continue;
void OnChange(GraphChange change)
{
change.Match(NodeAdded, NodeRemoved, EdgeAdded, EdgeRemoved);
}
var nodePresenter = (MaterialNodePresenter)typeMapper.Create(node);
node.onModified += OnNodeChanged;
nodePresenter.Initialize(node, m_PreviewSystem);
addedNodePresenters.Add(nodePresenter);
}
void NodeAdded(NodeAddedGraphChange change)
{
var nodePresenter = (MaterialNodePresenter)typeMapper.Create(change.node);
change.node.onModified += OnNodeChanged;
nodePresenter.Initialize(change.node, m_PreviewSystem);
m_Elements.Add(nodePresenter);
}
// Create edge data for nodes marked for addition
var edgePresenters = new List<GraphEdgePresenter>();
foreach (var addedNodePresenter in addedNodePresenters)
{
var addedNode = addedNodePresenter.node;
foreach (var slot in addedNode.GetOutputSlots<ISlot>())
{
var sourceAnchors = addedNodePresenter.outputAnchors.OfType<GraphAnchorPresenter>();
var sourceAnchor = sourceAnchors.FirstOrDefault(x => x.slot == slot);
void NodeRemoved(NodeRemovedGraphChange change)
{
change.node.onModified -= OnNodeChanged;
var nodePresenter = m_Elements.OfType<MaterialNodePresenter>().FirstOrDefault(p => p.node.guid == change.node.guid);
if (nodePresenter != null)
m_Elements.Remove(nodePresenter);
}
var edges = addedNode.owner.GetEdges(new SlotReference(addedNode.guid, slot.id));
foreach (var edge in edges)
{
var toNode = addedNode.owner.GetNodeFromGuid(edge.inputSlot.nodeGuid);
var toSlot = toNode.FindInputSlot<ISlot>(edge.inputSlot.slotId);
var targetNode = addedNodePresenters.FirstOrDefault(x => x.node == toNode);
var targetAnchors = targetNode.inputAnchors.OfType<GraphAnchorPresenter>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == toSlot);
var edgePresenter = CreateInstance<GraphEdgePresenter>();
edgePresenter.Initialize(edge);
edgePresenter.output = sourceAnchor;
edgePresenter.output.Connect(edgePresenter);
edgePresenter.input = targetAnchor;
edgePresenter.input.Connect(edgePresenter);
edgePresenters.Add(edgePresenter);
}
}
}
void EdgeAdded(EdgeAddedGraphChange change)
{
var edge = change.edge;
// Add nodes marked for addition
m_Elements.AddRange(addedNodePresenters.OfType<GraphElementPresenter>());
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));
// Find edges in the graph that are not being drawn and create edge data for them
foreach (var edge in graph.edges)
{
if (m_Elements.OfType<GraphEdgePresenter>().Any(ed => ed.edge == edge))
continue;
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 sourceAnchorPresenters = sourceNodePresenter.outputAnchors.OfType<GraphAnchorPresenter>();
var sourceAnchorPresenter = sourceAnchorPresenters.FirstOrDefault(x => x.slot == sourceSlot);
var targetNode = graph.GetNodeFromGuid(edge.inputSlot.nodeGuid);
var targetSlot = targetNode.FindInputSlot<ISlot>(edge.inputSlot.slotId);
var targetNodePresenter = m_Elements.OfType<MaterialNodePresenter>().FirstOrDefault(x => x.node == targetNode);
var targetAnchors = targetNodePresenter.inputAnchors.OfType<GraphAnchorPresenter>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == targetSlot);
if (targetNodePresenter.node.onModified != null)
targetNodePresenter.node.onModified(targetNodePresenter.node, ModificationScope.Graph);
var edgePresenter = CreateInstance<GraphEdgePresenter>();
edgePresenter.Initialize(edge);
edgePresenter.output = sourceAnchorPresenter;
edgePresenter.output.Connect(edgePresenter);
edgePresenter.input = targetAnchor;
edgePresenter.input.Connect(edgePresenter);
edgePresenters.Add(edgePresenter);
}
var targetNode = graph.GetNodeFromGuid(edge.inputSlot.nodeGuid);
var targetSlot = targetNode.FindInputSlot<ISlot>(edge.inputSlot.slotId);
var targetNodePresenter = m_Elements.OfType<MaterialNodePresenter>().FirstOrDefault(x => x.node == targetNode);
var targetAnchor = targetNodePresenter.inputAnchors.OfType<GraphAnchorPresenter>().FirstOrDefault(x => x.slot.Equals(targetSlot));
m_Elements.AddRange(edgePresenters.OfType<GraphElementPresenter>());
m_PreviewSystem.UpdateTimeDependentPreviews();
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);
public virtual void Initialize(IGraph graph, IMaterialGraphEditWindow container, PreviewSystem previewSystem)
void EdgeRemoved(EdgeRemovedGraphChange change)
m_PreviewSystem = previewSystem;
this.graph = graph;
m_Container = container;
if (graph == null)
return;
UpdateData();
var edgePresenter = m_Elements.OfType<GraphEdgePresenter>().FirstOrDefault(p => p.edge == change.edge);
if (edgePresenter != null)
{
edgePresenter.output.Disconnect(edgePresenter);
edgePresenter.input.Disconnect(edgePresenter);
m_Elements.Remove(edgePresenter);
}
Undo.RecordObject(m_GraphObject, "Add " + node.name);
UpdateData();
RecordState();
graph.RemoveElements(nodes.Select(x => x.node), edges.Select(x => x.edge));
graph.RemoveElements(nodes.Select(x => x.node as INode), edges.Select(x => x.edge));
UpdateData();
}
public void Connect(GraphAnchorPresenter left, GraphAnchorPresenter right)

Undo.RecordObject(m_GraphObject, "Connect Edge");
UpdateData();
RecordState();
}
}

return;
var addedNodes = new List<INode>();
var nodeGuidMap = new Dictionary<Guid, Guid>();
foreach (var node in copyGraph.GetNodes<INode>())
{

// only connect edges within pasted elements, discard
// external edges.
var addedEdges = new List<IEdge>();
foreach (var edge in copyGraph.edges)
{
var outputSlot = edge.outputSlot;

{
var outputSlotRef = new SlotReference(remappedOutputNodeGuid, outputSlot.slotId);
var inputSlotRef = new SlotReference(remappedInputNodeGuid, inputSlot.slotId);
addedEdges.Add(graph.Connect(outputSlotRef, inputSlotRef));
graph.Connect(outputSlotRef, inputSlotRef);
UpdateData();
//TODO: Fix this
//drawingData.selection = addedNodes.Select(n => n.guid);
if (onSelectionChanged != null)
onSelectionChanged(addedNodes);
}
public bool canCopy

public void Cut()
{
Copy();
Undo.RecordObject(m_GraphObject, "Cut");
RecordState();
}
public bool canPaste

public void Paste()
{
var pastedGraph = DeserializeCopyBuffer(EditorGUIUtility.systemCopyBuffer);
Undo.RecordObject(m_GraphObject, "Paste");
RecordState();
}
public bool canDuplicate

public void Duplicate()
{
var graph = DeserializeCopyBuffer(JsonUtility.ToJson(CreateCopyPasteGraph(elements.Where(e => e.selected)), true));
Undo.RecordObject(m_GraphObject, "Duplicate");
RecordState();
}
public bool canDelete

public void Delete()
{
RecordState();
Undo.RecordObject(m_GraphObject, "Delete");
RecordState();
}
public override void AddElement(EdgePresenter edge)

if (graph == null)
return;
if (onSelectionChanged != null)
onSelectionChanged(presenters.Select(x => x.node));
onSelectionChanged(presenters.Select(x => x.node as INode));
}
public override void AddElement(GraphElementPresenter element)

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


[Serializable]
public class MaterialNodePresenter : NodePresenter, IDisposable
{
public INode node { get; private set; }
public AbstractMaterialNode node { get; private set; }
[SerializeField]
protected List<GraphControlPresenter> m_Controls = new List<GraphControlPresenter>();

public virtual void Initialize(INode inNode, PreviewSystem previewSystem)
{
node = inNode;
node = inNode as AbstractMaterialNode;
if (node == null)
return;

m_Preview = previewSystem.GetPreview(inNode);
m_Preview.onPreviewChanged += OnPreviewChanged;
node.onReplaced += OnReplaced;
}
void OnReplaced(INode previous, INode current)
{
node = current as AbstractMaterialNode;
}
void OnPreviewChanged()

67
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs


using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using UnityEditor.Graphing.Util;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;

MaterialPropertyBlock m_PreviewPropertyBlock;
MaterialGraphPreviewGenerator m_PreviewGenerator = new MaterialGraphPreviewGenerator();
Texture2D m_ErrorTexture;
DateTime m_LastUpdate;
public PreviewRate previewRate { get; set; }
public PreviewSystem(AbstractMaterialGraph graph)
{

void OnGraphChange(GraphChange change)
{
if (change is NodeAddedGraphChange)
AddPreview(((NodeAddedGraphChange)change).node);
else if (change is NodeRemovedGraphChange)
RemovePreview(((NodeRemovedGraphChange)change).node);
change.Match(
nodeAdded: c => AddPreview(c.node),
nodeRemoved: c => RemovePreview(c.node),
edgeAdded: c => m_DirtyShaders.Add(c.edge.inputSlot.nodeGuid),
edgeRemoved: c => m_DirtyShaders.Add(c.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);
m_DirtyPreviews.Remove(node.guid);
m_DirtyShaders.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);
}
if (previewRate == PreviewRate.Off)
return;
var updateTime = DateTime.Now;
if (previewRate == PreviewRate.Throttled && (updateTime - m_LastUpdate) < TimeSpan.FromSeconds(1.0 / 10.0))
return;
m_LastUpdate = updateTime;
PropagateNodeSet(m_DirtyShaders);
foreach (var nodeGuid in m_DirtyShaders)
{

m_DirtyShaders.Clear();
PropagateNodeSet(m_DirtyPreviews);
PropagateNodeSet(m_DirtyPreviews);
// Find nodes we need properties from
m_PropertyNodeGuids.Clear();

foreach (var nodeGuid in m_PropertyNodeGuids)
{
var node = m_Graph.GetNodeFromGuid<AbstractMaterialNode>(nodeGuid);
if (node == null)
continue;
node.CollectPreviewMaterialProperties(m_PreviewProperties);
foreach (var prop in m_Graph.properties)
m_PreviewProperties.Add(prop.GetPreviewMaterialProperty());

var time = Time.realtimeSinceStartup;
foreach (var nodeGuid in m_DirtyPreviews)
{
var previewData = m_Previews[nodeGuid];
PreviewData previewData;
if (!m_Previews.TryGetValue(nodeGuid, out previewData))
continue;
if (previewData.shader == null)
{
previewData.texture = null;

foreach (var nodeGuid in m_DirtyPreviews)
{
var previewData = m_Previews[nodeGuid];
PreviewData previewData;
if (!m_Previews.TryGetValue(nodeGuid, out previewData))
continue;
if (previewData.onPreviewChanged != null)
previewData.onPreviewChanged();
}

void UpdateShader(Guid nodeGuid)
{
var node = m_Graph.GetNodeFromGuid<AbstractMaterialNode>(nodeGuid);
if (node == null)
return;
PreviewData previewData;
if (!m_Previews.TryGetValue(nodeGuid, out previewData))
return;

{
ShaderUtil.UpdateShaderAsset(previewData.shader, previewData.shaderString);
}
if (MaterialGraphAsset.ShaderHasError(previewData.shader))
Debug.LogWarningFormat("ShaderHasError: {0}\n{1}", node.GetVariableNameForNode(), previewData.shaderString);
}
void DestroyPreview(Guid nodeGuid, PreviewData previewData)

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


using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.MaterialGraph.Drawing;
using UnityEditor.MaterialGraph.Drawing.Inspector;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using Object = UnityEngine.Object;

get { return m_GraphView; }
}
TitleBarView m_TitleBarView;
ToolbarView m_ToolbarView;
public Action onUpdateAssetClick { get; set; }
public Action onConvertToSubgraphClick { get; set; }
public Action onShowInProjectClick { get; set; }
m_TitleBarView = new TitleBarView { name = "TitleBar" };
Add(m_TitleBarView);
m_ToolbarView = new ToolbarView { name = "TitleBar" };
{
m_ToolbarView.Add(new ToolbarSpaceView());
m_ToolbarView.Add(new ToolbarSeparatorView());
var updateAssetButton = new ToolbarButtonView { text = "Update asset" };
updateAssetButton.AddManipulator(new Clickable(() =>
{
if (onUpdateAssetClick != null) onUpdateAssetClick();
}));
m_ToolbarView.Add(updateAssetButton);
m_ToolbarView.Add(new ToolbarSeparatorView());
m_ToolbarView.Add(new ToolbarSpaceView());
m_ToolbarView.Add(new ToolbarSeparatorView());
var convertToSubgraphButton = new ToolbarButtonView { text = "Convert to subgraph" };
convertToSubgraphButton.AddManipulator(new Clickable(() =>
{
if (onConvertToSubgraphClick != null) onConvertToSubgraphClick();
}));
m_ToolbarView.Add(convertToSubgraphButton);
m_ToolbarView.Add(new ToolbarSeparatorView());
m_ToolbarView.Add(new ToolbarSpaceView());
m_ToolbarView.Add(new ToolbarSeparatorView());
var showInProjectButton = new ToolbarButtonView { text = "Show in project" };
showInProjectButton.AddManipulator(new Clickable(() =>
{
if (onShowInProjectClick != null) onShowInProjectClick();
}));
m_ToolbarView.Add(showInProjectButton);
m_ToolbarView.Add(new ToolbarSeparatorView());
m_ToolbarView.Add(new ToolbarSpaceView());
m_ToolbarView.Add(new ToolbarSeparatorView());
m_TimeButton = new ToolbarButtonView { text = "" };
m_TimeButton.AddManipulator(new Clickable(() =>
{
if (presenter == null)
return;
if (presenter.previewRate == PreviewRate.Full)
presenter.previewRate = PreviewRate.Throttled;
else if (presenter.previewRate == PreviewRate.Throttled)
presenter.previewRate = PreviewRate.Off;
else if (presenter.previewRate == PreviewRate.Off)
presenter.previewRate = PreviewRate.Full;
m_TimeButton.text = "Preview rate: " + presenter.previewRate;
}));
m_ToolbarView.Add(m_TimeButton);
m_ToolbarView.Add(new ToolbarSeparatorView());
}
Add(m_ToolbarView);
var content = new VisualElement();
content.name = "content";

public override void OnDataChanged()
{
m_GraphView.presenter = m_Presenter.graphPresenter;
m_TitleBarView.dataProvider = m_Presenter.titleBarPresenter;
m_TimeButton.text = "Preview rate: " + presenter.previewRate;
ToolbarButtonView m_TimeButton;
public GraphEditorPresenter presenter
{

public void Dispose()
{
onUpdateAssetClick = null;
onConvertToSubgraphClick = null;
onShowInProjectClick = null;
if (m_GraphInspectorView != null) m_GraphInspectorView.Dispose();
}
}

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


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

{
VisualElement m_ControlsContainer;
List<GraphControlPresenter> m_CurrentControls;
VisualElement m_PreviewContainer;
VisualElement m_PreviewToggle;
Image m_PreviewImage;
bool m_IsScheduled;

leftContainer.Add(m_ControlsContainer);
m_CurrentControls = new List<GraphControlPresenter>();
m_PreviewContainer = new VisualElement { name = "preview" };
m_PreviewToggle = new VisualElement { name = "toggle", text = "" };
m_PreviewToggle.AddManipulator(new Clickable(OnPreviewToggle));
leftContainer.Add(m_PreviewToggle);
m_PreviewImage = new Image
m_PreviewImage = new Image
{
pickingMode = PickingMode.Ignore,
image = Texture2D.whiteTexture
};
}
leftContainer.Add(m_PreviewContainer);
name = "preview",
pickingMode = PickingMode.Ignore,
image = Texture2D.whiteTexture
};
leftContainer.Add(m_PreviewImage);
}
void OnPreviewToggle()
{
var node = GetPresenter<MaterialNodePresenter>().node;
node.previewExpanded = !node.previewExpanded;
m_PreviewToggle.text = node.previewExpanded ? "▲" : "▼";
}
void UpdatePreviewTexture(Texture previewTexture)

m_PreviewContainer.Clear();
m_PreviewImage.visible = false;
m_PreviewImage.RemoveFromClassList("visible");
m_PreviewImage.AddToClassList("hidden");
if (m_PreviewContainer.childCount == 0)
m_PreviewContainer.Add(m_PreviewImage);
m_PreviewImage.visible = true;
m_PreviewImage.AddToClassList("visible");
m_PreviewImage.RemoveFromClassList("hidden");
Dirty(ChangeType.Repaint | ChangeType.Layout);
Dirty(ChangeType.Repaint);
}
void UpdateControls(MaterialNodePresenter nodeData)

public override void OnDataChanged()
{
base.OnDataChanged();
var nodePresenter = GetPresenter<MaterialNodePresenter>();
if (nodePresenter == null)

m_PreviewContainer.Clear();
m_PreviewToggle.text = nodePresenter.node.previewExpanded ? "▲" : "▼";
if (nodePresenter.node.hasPreview)
m_PreviewToggle.RemoveFromClassList("inactive");
else
m_PreviewToggle.AddToClassList("inactive");
// if (nodePresenter.expanded)
UpdatePreviewTexture(nodePresenter.previewTexture);
// else
// m_PreviewContainer.Clear();
UpdatePreviewTexture(nodePresenter.node.previewExpanded ? nodePresenter.previewTexture : null);
}
}
}

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


width: 400;
}
MaterialNodeView > .mainContainer > #left > #preview > Image {
MaterialNodeView > .mainContainer > #left > #preview.active {
width: 200;
}
MaterialNodeView > .mainContainer > #left > #preview.visible {
width: 200;
}
MaterialNodeView > .mainContainer > #left > #toggle {
text-color: rgb(153, 153, 153);
text-alignment: middle-center;
}
MaterialNodeView > .mainContainer > #left > #toggle.inactive {
height: 0;
}
MaterialNodeView > .mainContainer > #left > #toggle:hover {
background-color: rgba(0, 0, 0, 0.33);
}
MaterialNodeView > .mainContainer > #left > #toggle:active {
background-color: rgba(0, 0, 0, 0.66);
}
GridBackground {

background-color: rgb(79, 79, 79);
}
GraphInspectorView > #bottom > #properties {
border-color: rgb(41, 41, 41);
border-top-width: 1;
border-bottom-width: 1;
border-left-width: 1;
border-right-width: 1;
margin-top: 8;
margin-bottom: 8;
margin-left: 8;
margin-right: 8;
}
GraphInspectorView > #bottom > #properties > #header {
border-color: rgb(41, 41, 41);
border-bottom-width: 1;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
GraphInspectorView > #bottom > #properties > #header > #title {
text-color: rgb(180, 180, 180);
font-style: bold;
padding-top: 8;
padding-bottom: 8;
padding-left: 8;
padding-right: 8;
}
GraphInspectorView > #bottom > #properties > #header > #addButton {
height: 24;
margin-top: 0;
margin-bottom: 0;
margin-left: 0;
margin-right: 8;
}
GraphInspectorView > #bottom > #properties > #items {
padding-bottom: 4;
}
ShaderPropertyView {
flex-direction: row;
justify-content: space-between;
align-items: center;
padding-top: 8;
padding-bottom: 4;
padding-left: 8;
padding-right: 8;
}
ShaderPropertyView > #displayName {
flex: 1;
margin-right: 8;
}
ShaderPropertyView > #value {
flex: 2;
margin-right: 8;
}
ShaderPropertyView > #remove {
font-size: 9;
padding-top: 0;
padding-bottom: 0;
padding-left: 1;
padding-right: 1;
margin-top: 0;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
}
.nodeEditor {
border-color: rgb(79, 79, 79);
border-bottom-width: 1;

flex-direction: column;
padding-bottom: 2;
}
ToolbarView {
flex-direction: row;
border-color: rgb(32, 32, 32);
border-bottom-width: 1;
}
ToolbarSeparatorView {
background-color: rgb(32, 32, 32);
width: 1;
}
ToolbarSpaceView {
width: 5;
}
ToolbarButtonView {
font-size: 10;
text-color: rgb(180, 180, 180);
padding-top: 3;
padding-bottom: 3;
padding-left: 4;
padding-right: 4;
}
ToolbarButtonView:hover {
background-color: rgba(255, 255, 255, 0.25);
}
ToolbarButtonView:active {
background-color: rgba(0, 0, 0, 0.25);
}

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


}
return hashCode;
}
public static IEnumerable<T> ToEnumerable<T>(this T item)
{
yield return item;
}
}
}

72
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/AbstractMaterialGraph.cs


[Serializable]
public abstract class AbstractMaterialGraph : SerializableGraph, IGenerateProperties
{
[NonSerialized] private List<IShaderProperty> m_Properties = new List<IShaderProperty>();
[NonSerialized]
List<IShaderProperty> m_Properties = new List<IShaderProperty>();
[SerializeField] private List<SerializationHelper.JSONSerializedElement> m_SerializedProperties = new List<SerializationHelper.JSONSerializedElement>();
[SerializeField]
List<SerializationHelper.JSONSerializedElement> m_SerializedProperties = new List<SerializationHelper.JSONSerializedElement>();
public IEnumerable<IShaderProperty> properties
{

return;
m_Properties.Add(property);
NotifyChange(new ShaderPropertyAdded(property));
m_Properties.RemoveAll(x => x.guid == guid);
if (m_Properties.RemoveAll(x => x.guid == guid) > 0)
NotifyChange(new ShaderPropertyRemoved(guid));
}
public override Dictionary<SerializationHelper.TypeSerializationInfo, SerializationHelper.TypeSerializationInfo> GetLegacyTypeRemapping()

};
result[worldPosNode] = SerializationHelper.GetTypeSerializableAsString(typeof(WorldSpacePositionNode));
return result;
}
return result;
class IndexedProperty
{
public int index;
public IShaderProperty property;
}
public override void ReplaceWith(IGraph other)
{
var otherMG = other as AbstractMaterialGraph;
if (otherMG != null)
{
using (var removedPropertiesPooledObject = ListPool<Guid>.GetDisposable())
using (var replacedPropertiesPooledObject = ListPool<IndexedProperty>.GetDisposable())
{
var removedPropertyGuids = removedPropertiesPooledObject.value;
var replacedProperties = replacedPropertiesPooledObject.value;
var index = 0;
foreach (var property in m_Properties)
{
var otherProperty = otherMG.properties.FirstOrDefault(op => op.guid == property.guid);
if (otherProperty == null)
removedPropertyGuids.Add(property.guid);
else
replacedProperties.Add(new IndexedProperty { index = index, property = otherProperty });
index++;
}
foreach (var propertyGuid in removedPropertyGuids)
RemoveShaderProperty(propertyGuid);
foreach (var indexedProperty in replacedProperties)
{
m_Properties[indexedProperty.index] = indexedProperty.property;
// TODO: Notify of change
}
foreach (var otherProperty in otherMG.properties)
{
if (!properties.Any(p => p.guid == otherProperty.guid))
AddShaderProperty(otherProperty);
}
}
}
base.ReplaceWith(other);
}
public override void OnBeforeSerialize()

base.OnAfterDeserialize();
}
private static ShaderGraphRequirements GetRequierments(AbstractMaterialNode nodeForRequirements)
static ShaderGraphRequirements GetRequierments(AbstractMaterialNode nodeForRequirements)
{
var activeNodeList = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(activeNodeList, nodeForRequirements);

// if anything needs tangentspace we have make
// sure to have our othonormal basis!
var compoundSpaces = requiresBitangent | requiresNormal | requiresPosition
| requiresTangent | requiresViewDir | requiresPosition
| requiresNormal;
| requiresTangent | requiresViewDir | requiresPosition
| requiresNormal;
var needsTangentSpace = (compoundSpaces & NeededCoordinateSpace.Tangent) > 0;
if (needsTangentSpace)

return reqs;
}
private static void GenerateSpaceTranslationSurfaceInputs(
static void GenerateSpaceTranslationSurfaceInputs(
NeededCoordinateSpace neededSpaces,
ShaderGenerator surfaceInputs,
string objectSpaceName,

public string GetShader(AbstractMaterialNode node, GenerationMode mode, string name, out List<PropertyCollector.TextureInfo> configuredTextures, out PreviewMode previewMode)
{
if (node == null)
throw new ArgumentNullException(nameof(node));
throw new ArgumentNullException("node");
var vertexShader = new ShaderGenerator();
var surfaceDescriptionFunction = new ShaderGenerator();

{
foreach (var slot in node.GetInputSlots<MaterialSlot>())
surfaceDescriptionStruct.AddShaderChunk(AbstractMaterialNode.ConvertConcreteSlotValueTypeToString(AbstractMaterialNode.OutputPrecision.@float, slot.concreteValueType) + " " + slot.shaderOutputName + ";", false);
}
surfaceDescriptionStruct.Deindent();
surfaceDescriptionStruct.AddShaderChunk("};", false);

{
var foundEdges = GetEdges(input.slotReference).ToArray();
if (foundEdges.Any())
{
{
var outputRef = foundEdges[0].outputSlot;
var fromNode = GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid);
surfaceDescriptionFunction.AddShaderChunk(string.Format("surface.{0} = {1};", input.shaderOutputName, fromNode.GetVariableNameForSlot(outputRef.slotId)), true);

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/AbstractShaderProperty.cs


}
}
public string overrideReferenceName { get; set; } = string.Empty;
public string overrideReferenceName { get; set; }
public abstract PropertyType propertyType { get; }

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/TextureShaderProperty.cs


return "UNITY_DECLARE_TEX2D(" + referenceName + ");";
}
public override string GetInlinePropertyDeclarationString()
{
return "UNITY_DECLARE_TEX2D_NOSAMPLER(" + referenceName + ");";
}
public override PreviewProperty GetPreviewMaterialProperty()
{

1
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/AbstractLightweightMasterNode.cs


surfaceOutputRemap.Deindent();
surfaceOutputRemap.AddShaderChunk("}", false);
}
}
public override IEnumerable<string> GetSubshader(ShaderGraphRequirements graphRequirements, MasterRemapGraph remapper)

17
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

//[SerializeField]
private OutputPrecision m_OutputPrecision = OutputPrecision.@float;
[SerializeField]
bool m_PreviewExpanded = true;
public bool previewExpanded
{
get { return m_PreviewExpanded; }
set
{
if (previewExpanded == value)
return;
m_PreviewExpanded = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
// Nodes that want to have a preview area can override this and return true
public virtual bool hasPreview

10
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MasterRemapGraph.cs


[Serializable]
public class MasterRemapGraph : AbstractSubGraph
{
public override void AddShaderProperty(IShaderProperty property)
{
if (property.GetType() == typeof(TextureShaderProperty))
{
Debug.LogWarning("Can not add Texture properties to remap graphs");
return;
}
base.AddShaderProperty(property);
}
public override void AddNode(INode node)
{

5
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/AbstractSubGraphNode.cs


}
}
public virtual INode outputNode { get; } = null;
public virtual INode outputNode
{
get { return null; }
}
public virtual void OnEnable()
{

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphOutputNode.cs


RemoveSlot(index);
}
public override bool allowedInRemapGraph { get; } = false;
public override bool allowedInRemapGraph { get { return false; } }
}
}

2
MaterialGraphProject/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2017.3.0b1
m_EditorVersion: 2018.1.0a1

105
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs


using System;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing.Inspector
{
public class ShaderPropertyView : VisualElement
{
Action m_ValueAction;
public AbstractMaterialGraph graph { get; private set; }
public IShaderProperty property { get; private set; }
public ShaderPropertyView(AbstractMaterialGraph graph, IShaderProperty property)
{
this.graph = graph;
this.property = property;
m_ValueAction = null;
if (property is FloatShaderProperty)
m_ValueAction = FloatField;
else if (property is Vector2ShaderProperty)
m_ValueAction = Vector2Field;
else if (property is Vector3ShaderProperty)
m_ValueAction = Vector3Field;
else if (property is Vector4ShaderProperty)
m_ValueAction = Vector4Field;
else if (property is ColorShaderProperty)
m_ValueAction = ColorField;
else if (property is TextureShaderProperty)
m_ValueAction = TextureField;
Assert.IsNotNull(m_ValueAction);
Add(new IMGUIContainer(DisplayNameField) { name = "displayName" });
Add(new IMGUIContainer(ValueField) { name = "value" });
Add(new Button(OnClickRemove) { name = "remove", text = "Remove" });
}
void OnClickRemove()
{
graph.RemoveShaderProperty(property.guid);
NotifyNodes();
}
void DisplayNameField()
{
EditorGUI.BeginChangeCheck();
property.displayName = EditorGUILayout.DelayedTextField(property.displayName);
if (EditorGUI.EndChangeCheck())
NotifyNodes();
}
void ValueField()
{
EditorGUI.BeginChangeCheck();
m_ValueAction();
if (EditorGUI.EndChangeCheck())
NotifyNodes();
}
void NotifyNodes()
{
foreach (var node in graph.GetNodes<PropertyNode>())
node.onModified(node, ModificationScope.Node);
}
void FloatField()
{
var fProp = (FloatShaderProperty) property;
fProp.value = EditorGUILayout.FloatField(fProp.value);
}
void Vector2Field()
{
var fProp = (Vector2ShaderProperty) property;
fProp.value = EditorGUILayout.Vector2Field("", fProp.value);
}
void Vector3Field()
{
var fProp = (Vector3ShaderProperty) property;
fProp.value = EditorGUILayout.Vector3Field("", fProp.value);
}
void Vector4Field()
{
var fProp = (Vector4ShaderProperty) property;
fProp.value = EditorGUILayout.Vector4Field("", fProp.value);
}
void ColorField()
{
var fProp = (ColorShaderProperty) property;
fProp.value = EditorGUILayout.ColorField("", fProp.value);
}
void TextureField()
{
var fProp = (TextureShaderProperty) property;
fProp.value.texture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), fProp.value.texture, typeof(Texture), null) as Texture;
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs.meta


fileFormatVersion: 2
guid: a7487f4dc0fc4cf6a84bde37e66b60cb
timeCreated: 1507035849

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewRate.cs


namespace UnityEditor.MaterialGraph.Drawing
{
public enum PreviewRate
{
Full,
Throttled,
Off
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewRate.cs.meta


fileFormatVersion: 2
guid: fa070520993a4b839e705dcd7f22e4d6
timeCreated: 1506421104

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


using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.MaterialGraph.Drawing
{
public class ToolbarView : VisualElement
{
public ToolbarView()
{
AddStyleSheetPath("Styles/MaterialGraph");
}
}
public class ToolbarButtonView : VisualElement
{
public ToolbarButtonView()
{
AddStyleSheetPath("Styles/MaterialGraph");
}
}
public class ToolbarSeparatorView : VisualElement
{
public ToolbarSeparatorView()
{
AddStyleSheetPath("Styles/MaterialGraph");
}
}
public class ToolbarSpaceView : VisualElement
{
public ToolbarSpaceView()
{
AddStyleSheetPath("Styles/MaterialGraph");
}
}
}

28
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Interfaces/MaterialGraphChange.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
public class ShaderPropertyAdded : GraphChange
{
public ShaderPropertyAdded(IShaderProperty shaderProperty)
{
this.shaderProperty = shaderProperty;
}
public IShaderProperty shaderProperty { get; private set; }
}
public class ShaderPropertyRemoved : GraphChange
{
public ShaderPropertyRemoved(Guid guid)
{
this.guid = guid;
}
public Guid guid { get; private set; }
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Interfaces/MaterialGraphChange.cs.meta


fileFormatVersion: 2
guid: 53af639a9c00c2740ba7f23e2b38cf34
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

32
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PreviewNode.cs


using System.Reflection;
namespace UnityEngine.MaterialGraph
{
[Title("Preview Node")]
public class PreviewNode : CodeFunctionNode
{
public override bool hasPreview { get { return true; } }
public PreviewNode()
{
name = "Preview";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Preview", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Preview(
[Slot(0, Binding.None)] DynamicDimensionVector input,
[Slot(1, Binding.None)] out DynamicDimensionVector output)
{
return
@"
{
output = input;
}
";
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PreviewNode.cs.meta


fileFormatVersion: 2
guid: 0a9c3dd2c3b0c4347876f3e448be2046
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TitleBarButtonPresenter.cs


using UnityEngine;
namespace UnityEditor.MaterialGraph.Drawing
{
// TODO JOCE: Needed at all?
public class TitleBarButtonPresenter : ScriptableObject
{
public delegate void ClickCallback();
public string text;
public ClickCallback onClick { get; set; }
protected TitleBarButtonPresenter() {}
}
}

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


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

83
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/TitleBarPresenter.cs


using UnityEngine;
using UnityEngine.Graphing;
using System.Collections.Generic;
using UnityEngine.MaterialGraph;
using System.IO;
using System.Linq;
using UnityEditor.MaterialGraph.Drawing;
namespace UnityEditor.MaterialGraph.Drawing
{
// TODO JOCE: Not sure the title bar requires a presenter at all.
public class TitleBarPresenter : ScriptableObject
{
List<TitleBarButtonPresenter> m_leftItems;
List<TitleBarButtonPresenter> m_rightItems;
IMaterialGraphEditWindow m_Owner;
public IEnumerable<TitleBarButtonPresenter> leftItems
{
get { return m_leftItems; }
}
public IEnumerable<TitleBarButtonPresenter> rightItems
{
get { return m_rightItems; }
}
protected TitleBarPresenter()
{}
public void Initialize(IMaterialGraphEditWindow graphWindow)
{
m_Owner = graphWindow;
m_leftItems = new List<TitleBarButtonPresenter>();
m_rightItems = new List<TitleBarButtonPresenter>();
var currentGraphItem = CreateInstance<TitleBarButtonPresenter>();
currentGraphItem.text = "Put name here";
m_leftItems.Add(currentGraphItem);
var updateAsset = CreateInstance<TitleBarButtonPresenter>();
updateAsset.text = "Update Asset";
updateAsset.onClick += UpdateAsset;
m_leftItems.Add(updateAsset);
var toSubGraph = CreateInstance<TitleBarButtonPresenter>();
toSubGraph.text = "Selection -> Subgraph";
toSubGraph.onClick += ToSubGraph;
m_leftItems.Add(toSubGraph);
var showInProjectItem = CreateInstance<TitleBarButtonPresenter>();
showInProjectItem.text = "Show in project";
showInProjectItem.onClick += OnShowInProjectClick;
m_leftItems.Add(showInProjectItem);
var optionsItem = CreateInstance<TitleBarButtonPresenter>();
optionsItem.text = "Time";
optionsItem.onClick += ToggleTime;
m_rightItems.Add(optionsItem);
}
void OnShowInProjectClick()
{
if (m_Owner != null)
m_Owner.PingAsset();
}
void UpdateAsset()
{
m_Owner.UpdateAsset();
}
void ToSubGraph()
{
m_Owner.ToSubGraph();
}
void ToggleTime()
{
m_Owner.ToggleRequiresTime();
}
}
}

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


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

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/TitleBarButtonView.cs.meta


fileFormatVersion: 2
guid: 8ed8055e98d8f4ff5a17ea3415c08411
timeCreated: 1479800767
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

81
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/TitleBarButtonView.cs


using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.MaterialGraph.Drawing
{
public class TitleBarButtonView : DataWatchContainer
{
TitleBarButtonPresenter m_dataProvider;
Clicker m_clicker;
VisualElement m_label;
public TitleBarButtonPresenter dataProvider
{
get { return m_dataProvider; }
set
{
if (m_dataProvider == value)
return;
RemoveWatch();
m_dataProvider = value;
OnDataChanged();
AddWatch();
}
}
public TitleBarButtonView(TitleBarButtonPresenter dataProvider)
{
AddToClassList("titleBarItem");
m_clicker = new Clicker();
m_clicker.onClick += OnClick;
m_clicker.onStateChange += OnClickStateChanged;
this.AddManipulator(m_clicker);
var ve = new VisualElement();
ve.AddToClassList("titleBarItemBorder");
Add(ve);
m_label = new VisualElement();
m_label.AddToClassList("titleBarItemLabel");
Add(m_label);
var ve2 = new VisualElement();
ve2.AddToClassList("titleBarItemBorder");
this.dataProvider = dataProvider;
}
public override void OnDataChanged()
{
if (m_dataProvider == null)
return;
m_label.text = m_dataProvider.text;
this.Dirty(ChangeType.Repaint);
}
void OnClick()
{
if (m_dataProvider != null && m_dataProvider.onClick != null)
m_dataProvider.onClick();
}
void OnClickStateChanged(ClickerState newState)
{
if (newState == ClickerState.Active)
AddToClassList("active");
else if (newState == ClickerState.Inactive)
RemoveFromClassList("active");
this.Dirty(ChangeType.Repaint);
}
protected override Object[] toWatch
{
get { return new Object[] {dataProvider}; }
}
}
}

68
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/TitleBarView.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.MaterialGraph.Drawing
{
public class TitleBarView : DataWatchContainer
{
TitleBarPresenter m_DataProvider;
VisualContainer m_LeftContainer;
VisualContainer m_RightContainer;
public TitleBarPresenter dataProvider
{
get { return m_DataProvider; }
set
{
if (m_DataProvider == value)
return;
RemoveWatch();
m_DataProvider = value;
OnDataChanged();
AddWatch();
}
}
public TitleBarView()
{
name = "TitleBar";
m_LeftContainer = new VisualContainer()
{
name = "left"
};
Add(m_LeftContainer);
m_RightContainer = new VisualContainer()
{
name = "right"
};
Add(m_RightContainer);
AddStyleSheetPath("Styles/TitleBar");
}
public override void OnDataChanged()
{
if (m_DataProvider == null)
return;
UpdateContainer(m_LeftContainer, m_DataProvider.leftItems);
UpdateContainer(m_RightContainer, m_DataProvider.rightItems);
}
static void UpdateContainer(VisualContainer container, IEnumerable<TitleBarButtonPresenter> itemDatas)
{
container.ClearChildren();
foreach (var itemPresenter in itemDatas)
container.AddChild(new TitleBarButtonView(itemPresenter));
}
protected override Object[] toWatch
{
get { return new Object[] {dataProvider}; }
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/TitleBar.uss.meta


fileFormatVersion: 2
guid: 2bdb46d80eb734cc2bc61fa6a2302e52
timeCreated: 1479148211
licenseType: Pro
StyleSheetImporter:
userData:
assetBundleName:
assetBundleVariant:

54
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/TitleBar.uss


TitleBarView {
flex-direction: row;
justify-content: space-between;
align-items: stretch;
background-color: rgba(33, 33, 33, 0.5);
padding-bottom: 1;
/*margin-top: -1;*/
}
TitleBarView #left,
TitleBarView #right {
flex: 1;
height: 16;
background-color: #3d3d3d;
align-items: stretch;
flex-direction: row;
}
TitleBarView #left {
justify-content: flex-start;
}
TitleBarView #right {
justify-content: flex-end;
}
.titleBarItem {
flex-direction: row;
}
.titleBarItem.active {
background-color: rgba(33, 33, 33, 0.5);
}
#left .titleBarItem {
margin-left: 5;
}
#right .titleBarItem {
margin-right: 5;
}
.titleBarItemBorder {
background-color: rgba(33, 33, 33, 0.5);
width: 1;
}
.titleBarItemLabel {
text-color: rgba(255, 255, 255, 0.6);
font-size: 9;
text-alignment: middle-left;
padding-left: 5;
padding-right: 5;
}

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/TitleBarView.cs.meta → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/ToolbarView.cs.meta

正在加载...
取消
保存