Tim Cooper
9 年前
当前提交
bb779dab
共有 15 个文件被更改,包括 1063 次插入 和 1049 次删除
-
186UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialGraphDataSource.cs
-
7UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialWindow.cs
-
33UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialGraph.cs
-
2UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs
-
7UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TextureNode.cs
-
3UnityProject/Assets/UnityShaderEditor/Editor/Source/Prop/TextureProperty.cs
-
24UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ShaderGenerator.cs
-
143UnityProject/Assets/UnityShaderEditor/Graphs/GlowMud.ShaderGraph
-
815UnityProject/Assets/UnityShaderEditor/Graphs/LayeredTarp.ShaderGraph
-
809UnityProject/Assets/UnityShaderEditor/Graphs/SimpleMetal.ShaderGraph
-
1UnityProject/UnityProject.sln.DotSettings
-
64UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialGraphStyles.cs
-
12UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialGraphStyles.cs.meta
-
6UnityProject/Assets/StandaredAssetJazz/ImageEffects.meta
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEditor.Experimental; |
|||
using UnityEditor.Experimental.Graph; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
public class MaterialGraphDataSource : ICanvasDataSource |
|||
{ |
|||
readonly List<DrawableMaterialNode> m_DrawableNodes = new List<DrawableMaterialNode>(); |
|||
|
|||
public MaterialGraph graph { get; set; } |
|||
|
|||
public ICollection<DrawableMaterialNode> lastGeneratedNodes |
|||
{ |
|||
get { return m_DrawableNodes; } |
|||
} |
|||
|
|||
public CanvasElement[] FetchElements() |
|||
{ |
|||
m_DrawableNodes.Clear(); |
|||
Debug.Log("trying to convert"); |
|||
var pixelGraph = graph.currentGraph; |
|||
foreach (var node in pixelGraph.nodes) |
|||
{ |
|||
// add the nodes
|
|||
var bmn = node as BaseMaterialNode; |
|||
m_DrawableNodes.Add(new DrawableMaterialNode(bmn, (bmn is PixelShaderNode) ? 600.0f : 200.0f, typeof(Vector4), this)); |
|||
} |
|||
|
|||
// Add the edges now
|
|||
var drawableEdges = new List<Edge<NodeAnchor>>(); |
|||
foreach (var drawableMaterialNode in m_DrawableNodes) |
|||
{ |
|||
var baseNode = drawableMaterialNode.m_Node; |
|||
foreach (var slot in baseNode.outputSlots) |
|||
{ |
|||
var sourceAnchor = (NodeAnchor)drawableMaterialNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == slot); |
|||
|
|||
foreach (var edge in slot.edges) |
|||
{ |
|||
var targetNode = m_DrawableNodes.FirstOrDefault(x => x.m_Node == edge.toSlot.node); |
|||
var targetAnchor = (NodeAnchor)targetNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == edge.toSlot); |
|||
drawableEdges.Add(new Edge<NodeAnchor>(this, sourceAnchor, targetAnchor)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
var toReturn = new List<CanvasElement>(); |
|||
toReturn.AddRange(m_DrawableNodes.Select(x => (CanvasElement)x)); |
|||
toReturn.AddRange(drawableEdges.Select(x => (CanvasElement)x)); |
|||
|
|||
Debug.LogFormat("REturning {0} nodes", toReturn.Count); |
|||
return toReturn.ToArray(); |
|||
} |
|||
|
|||
public void DeleteElement(CanvasElement e) |
|||
{ |
|||
Debug.Log("Trying to delete " + e); |
|||
|
|||
if (e is Edge<NodeAnchor>) |
|||
{ |
|||
//find the edge
|
|||
var localEdge = (Edge<NodeAnchor>) e; |
|||
var edge = graph.currentGraph.edges.FirstOrDefault(x => x.fromSlot == localEdge.Left.m_Slot && x.toSlot == localEdge.Right.m_Slot); |
|||
|
|||
Debug.Log("Deleting edge " + edge); |
|||
graph.currentGraph.RemoveEdge(edge); |
|||
} |
|||
else if (e is DrawableMaterialNode) |
|||
{ |
|||
Debug.Log("Deleting node " + e + " " + ((DrawableMaterialNode) e).m_Node); |
|||
graph.currentGraph.RemoveNode(((DrawableMaterialNode) e).m_Node); |
|||
} |
|||
|
|||
e.ParentCanvas().ReloadData(); |
|||
e.ParentCanvas().Repaint(); |
|||
} |
|||
|
|||
public void Connect(NodeAnchor a, NodeAnchor b) |
|||
{ |
|||
var pixelGraph = graph.currentGraph; |
|||
pixelGraph.Connect(a.m_Slot, b.m_Slot); |
|||
} |
|||
} |
|||
} |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using UnityEditor.Experimental; |
|||
using UnityEditor.Experimental.Graph; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
public class MaterialGraphDataSource : ICanvasDataSource |
|||
{ |
|||
readonly List<DrawableMaterialNode> m_DrawableNodes = new List<DrawableMaterialNode>(); |
|||
|
|||
public MaterialGraph graph { get; set; } |
|||
|
|||
public ICollection<DrawableMaterialNode> lastGeneratedNodes |
|||
{ |
|||
get { return m_DrawableNodes; } |
|||
} |
|||
|
|||
public CanvasElement[] FetchElements() |
|||
{ |
|||
m_DrawableNodes.Clear(); |
|||
Debug.Log("trying to convert"); |
|||
var pixelGraph = graph.currentGraph; |
|||
foreach (var node in pixelGraph.nodes) |
|||
{ |
|||
// add the nodes
|
|||
var bmn = node as BaseMaterialNode; |
|||
m_DrawableNodes.Add(new DrawableMaterialNode(bmn, (bmn is PixelShaderNode) ? 600.0f : 200.0f, typeof(Vector4), this)); |
|||
} |
|||
|
|||
// Add the edges now
|
|||
var drawableEdges = new List<Edge<NodeAnchor>>(); |
|||
foreach (var drawableMaterialNode in m_DrawableNodes) |
|||
{ |
|||
var baseNode = drawableMaterialNode.m_Node; |
|||
foreach (var slot in baseNode.outputSlots) |
|||
{ |
|||
var sourceAnchor = (NodeAnchor)drawableMaterialNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == slot); |
|||
|
|||
foreach (var edge in slot.edges) |
|||
{ |
|||
var targetNode = m_DrawableNodes.FirstOrDefault(x => x.m_Node == edge.toSlot.node); |
|||
var targetAnchor = (NodeAnchor)targetNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == edge.toSlot); |
|||
drawableEdges.Add(new Edge<NodeAnchor>(this, sourceAnchor, targetAnchor)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
var toReturn = new List<CanvasElement>(); |
|||
toReturn.AddRange(m_DrawableNodes.Select(x => (CanvasElement)x)); |
|||
toReturn.AddRange(drawableEdges.Select(x => (CanvasElement)x)); |
|||
|
|||
Debug.LogFormat("REturning {0} nodes", toReturn.Count); |
|||
return toReturn.ToArray(); |
|||
} |
|||
|
|||
public void DeleteElement(CanvasElement e) |
|||
{ |
|||
Debug.Log("Trying to delete " + e); |
|||
|
|||
if (e is Edge<NodeAnchor>) |
|||
{ |
|||
//find the edge
|
|||
var localEdge = (Edge<NodeAnchor>) e; |
|||
var edge = graph.currentGraph.edges.FirstOrDefault(x => x.fromSlot == localEdge.Left.m_Slot && x.toSlot == localEdge.Right.m_Slot); |
|||
|
|||
Debug.Log("Deleting edge " + edge); |
|||
graph.currentGraph.RemoveEdge(edge); |
|||
} |
|||
else if (e is DrawableMaterialNode) |
|||
{ |
|||
Debug.Log("Deleting node " + e + " " + ((DrawableMaterialNode) e).m_Node); |
|||
graph.currentGraph.RemoveNode(((DrawableMaterialNode) e).m_Node); |
|||
} |
|||
|
|||
e.ParentCanvas().ReloadData(); |
|||
e.ParentCanvas().Repaint(); |
|||
} |
|||
|
|||
public void Connect(NodeAnchor a, NodeAnchor b) |
|||
{ |
|||
var pixelGraph = graph.currentGraph; |
|||
pixelGraph.Connect(a.m_Slot, b.m_Slot); |
|||
} |
|||
|
|||
private string m_LastPath; |
|||
public void Export(bool quickExport) |
|||
{ |
|||
var path = quickExport ? m_LastPath : EditorUtility.SaveFilePanelInProject("Export shader to file...", "shader.shader", "shader", "Enter file name"); |
|||
m_LastPath = path; // For quick exporting
|
|||
if (!string.IsNullOrEmpty(path)) |
|||
graph.ExportShader(path); |
|||
else |
|||
EditorUtility.DisplayDialog("Export Shader Error", "Cannot export shader", "Ok"); |
|||
} |
|||
} |
|||
} |
143
UnityProject/Assets/UnityShaderEditor/Graphs/GlowMud.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
815
UnityProject/Assets/UnityShaderEditor/Graphs/LayeredTarp.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
809
UnityProject/Assets/UnityShaderEditor/Graphs/SimpleMetal.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
public class MaterialGraphStyles |
|||
{ |
|||
private static MaterialGraphStyles s_Styles; |
|||
|
|||
private const float kHeadingSpace = 22.0f; |
|||
private readonly GUIStyle m_Header = "ShurikenModuleTitle"; |
|||
|
|||
private MaterialGraphStyles() |
|||
{ |
|||
m_Header.font = (new GUIStyle("Label")).font; |
|||
m_Header.border = new RectOffset(15, 7, 4, 4); |
|||
m_Header.fixedHeight = kHeadingSpace; |
|||
m_Header.contentOffset = new Vector2(20f, -2f); |
|||
} |
|||
|
|||
private static MaterialGraphStyles styles |
|||
{ |
|||
get { return s_Styles ?? (s_Styles = new MaterialGraphStyles()); } |
|||
} |
|||
|
|||
public static bool DoDrawDefaultInspector(SerializedObject obj) |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
obj.Update(); |
|||
|
|||
// Loop through properties and create one field (including children) for each top level property.
|
|||
SerializedProperty property = obj.GetIterator(); |
|||
bool expanded = true; |
|||
while (property.NextVisible(expanded)) |
|||
{ |
|||
EditorGUI.BeginDisabledGroup("m_Script" == property.propertyPath); |
|||
EditorGUILayout.PropertyField(property, true); |
|||
EditorGUI.EndDisabledGroup(); |
|||
expanded = false; |
|||
} |
|||
|
|||
obj.ApplyModifiedProperties(); |
|||
return EditorGUI.EndChangeCheck(); |
|||
} |
|||
|
|||
public static bool Header(string title, bool display) |
|||
{ |
|||
GUILayout.Box(title, styles.m_Header); |
|||
|
|||
var rect = GUILayoutUtility.GetLastRect(); |
|||
|
|||
Rect toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f); |
|||
if (Event.current.type == EventType.Repaint) |
|||
EditorStyles.foldout.Draw(toggleRect, false, false, display, false); |
|||
|
|||
Event e = Event.current; |
|||
if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition)) |
|||
{ |
|||
display = !display; |
|||
e.Use(); |
|||
} |
|||
return display; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ed34d5e4ca869634b9a5fa2a86bf539c |
|||
timeCreated: 1450776377 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 0d6ddd252915e0644ace6732c35612a9 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
撰写
预览
正在加载...
取消
保存
Reference in new issue