Tim Cooper
9 年前
当前提交
1b5c5494
共有 91 个文件被更改,包括 3105 次插入 和 707 次删除
-
1UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/INode.cs
-
25UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Tests/SerializedGraphTests.cs
-
9UnityProject/Assets/UnityShaderEditor/Editor/Nodes/AbstractMaterialNode.cs
-
4UnityProject/Assets/UnityShaderEditor/Editor/Nodes/AddNode.cs
-
13UnityProject/Assets/UnityShaderEditor/Editor/Nodes/Function2Input.cs
-
2UnityProject/Assets/UnityShaderEditor/Editor/Nodes/MaterialSlot.cs
-
4UnityProject/Assets/UnityShaderEditor/Editor/Nodes/PixelShaderNode.cs
-
3UnityProject/Assets/UnityShaderEditor/Editor/Nodes/PropertyNode.cs
-
22UnityProject/Assets/UnityShaderEditor/Editor/Nodes/Vector4Node.cs
-
3UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/Edge.cs
-
9UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableNode.cs
-
2UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MyNodeAdapters.cs
-
18UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeAnchor.cs
-
2UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DeleteSelected.cs
-
9UnityProject/Assets/GraphFramework/SerializableGraph/Editor.meta
-
9UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Assets.meta
-
9UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/GUIModificationType.cs.meta
-
9UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation.meta
-
9UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/IEdge.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/IGraph.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/INode.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/ISlot.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/SlotReference.cs.meta
-
9UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Tests.meta
-
9UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Util.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Util/Logging.cs.meta
-
12UnityProject/Assets/UnityShaderEditor/Editor/AbstractMaterialGraph.cs.meta
-
9UnityProject/Assets/UnityShaderEditor/Editor/AssetCallbacks.meta
-
9UnityProject/Assets/UnityShaderEditor/Editor/Drawing.meta
-
9UnityProject/Assets/UnityShaderEditor/Editor/Editors.meta
-
9UnityProject/Assets/UnityShaderEditor/Editor/Interfaces.meta
-
9UnityProject/Assets/UnityShaderEditor/Editor/Light.meta
-
12UnityProject/Assets/UnityShaderEditor/Editor/MaterialGraph.cs.meta
-
12UnityProject/Assets/UnityShaderEditor/Editor/MaterialGraphAsset.cs.meta
-
12UnityProject/Assets/UnityShaderEditor/Editor/MaterialOptions.cs.meta
-
9UnityProject/Assets/UnityShaderEditor/Editor/Nodes.meta
-
12UnityProject/Assets/UnityShaderEditor/Editor/PixelGraph.cs.meta
-
12UnityProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/AbstractMaterialGraphTests.cs.meta
-
12UnityProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialGraphTests.cs.meta
-
12UnityProject/Assets/UnityShaderEditor/Editor/TitleAttribute.cs.meta
-
9UnityProject/Assets/UnityShaderEditor/Editor/Util.meta
-
1001UnityProject/Assets/UnityShaderEditor/Graphs/TestGraph.ShaderGraph
-
8UnityProject/Assets/UnityShaderEditor/Graphs/TestGraph.ShaderGraph.meta
-
1001UnityProject/Assets/UnityShaderEditor/Graphs/stine.ShaderGraph
-
8UnityProject/Assets/UnityShaderEditor/Graphs/stine.ShaderGraph.meta
-
35UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Assets/SerializableGraphAsset.cs
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Assets/SerializableGraphAsset.cs.meta
-
152UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs.meta
-
159UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs
-
190UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs
-
68UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NullInputProxy.cs
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/Edge.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/NodeUtils.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableGraph.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableNode.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableSlot.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SlotType.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/Edge.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/GUIModificationType.cs.meta
-
8UnityProject/Assets/GraphFramework/SerializableGraph/NodeUtils.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/SerializableGraph.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/SerializableNode.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/SerializableSlot.cs.meta
-
12UnityProject/Assets/GraphFramework/SerializableGraph/SlotReference.cs.meta
-
12UnityProject/Assets/UnityShaderEditor/Editor/Drawing/DrawableMaterialNode.cs.meta
-
196UnityProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialWindow.cs
-
66UnityProject/Assets/UnityShaderEditor/Editor/Drawing/NullInputProxy.cs
-
152UnityProject/Assets/UnityShaderEditor/Editor/Drawing/DrawableMaterialNode.cs
-
165UnityProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphDataSource.cs
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/Edge.cs
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/NodeUtils.cs
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableGraph.cs
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableNode.cs
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SerializableSlot.cs
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Interfaces/SlotReference.cs
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Implementation/SlotType.cs
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs.meta
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs.meta
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MyNodeAdapters.cs
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MyNodeAdapters.cs.meta
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeAnchor.cs
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NodeAnchor.cs.meta
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DeleteSelected.cs
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DeleteSelected.cs.meta
-
0/UnityProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/NullInputProxy.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 93c541dd957a2ac40870d0b23d2dc115 |
|||
folderAsset: yes |
|||
timeCreated: 1464264920 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: fbce0c0b81b61ca4cb27684a4abb3fd1 |
|||
folderAsset: yes |
|||
timeCreated: 1464265232 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 1dc52c222e72d364ba1f1ce5d428d645 |
|||
folderAsset: yes |
|||
timeCreated: 1464264920 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: eda3c0504bf73e244befc23f40505007 |
|||
timeCreated: 1464264926 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 931ad3a4d181270419aa65ff77b3ec16 |
|||
folderAsset: yes |
|||
timeCreated: 1464264924 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 5b6c961691e6a7a46b9366ca4fa781ac |
|||
folderAsset: yes |
|||
timeCreated: 1464264924 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 2f67813c9628ef14a839d0c546f6ab25 |
|||
timeCreated: 1464264924 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ad5e6e2ab1165fb46bfc2296913d25a2 |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: b16d3bd20d4d2c644969258425ff071a |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c273d08d1dec8434583305f6cff41a08 |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a7b6f306850f6cc449bc71d8d2384146 |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ad1c022ae8278c34ba435f1ef3928952 |
|||
folderAsset: yes |
|||
timeCreated: 1464264921 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: e45006b8ac3b76f4aa0df05ea8514cbe |
|||
folderAsset: yes |
|||
timeCreated: 1464264920 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ffca76f71e6326344ad2ff5e823d02f9 |
|||
timeCreated: 1464264926 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 92dd684b5c787db4f9b11cec99be5d92 |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 4d0b60652dca71b49a137663137e38ea |
|||
folderAsset: yes |
|||
timeCreated: 1464264920 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 628a36608983fbe49bd5b01cc799f525 |
|||
folderAsset: yes |
|||
timeCreated: 1464264920 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 9847d86c4f5011c4284af07e94be19d0 |
|||
folderAsset: yes |
|||
timeCreated: 1464264921 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: fa6cfee2afcf9584b9e67fe405662d0e |
|||
folderAsset: yes |
|||
timeCreated: 1464264921 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 9558d2a8413064e40b02dc7e71a6925f |
|||
folderAsset: yes |
|||
timeCreated: 1464264921 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 2400e28d912db104797e8def686c6cdc |
|||
timeCreated: 1464264924 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 61bd7d04bf730474f9d9a0a32ef12cf4 |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 8f38eea901fa63d418361da2427f7699 |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 0082d52fe349b94449238a3d0db01df0 |
|||
folderAsset: yes |
|||
timeCreated: 1464264919 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ef84063adc43c204cb779ca0d9e31d4e |
|||
timeCreated: 1464264926 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 351a6b3ff7ef41c45938a78e94dd2a20 |
|||
timeCreated: 1464264924 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 0675182a7c3e7464e977d09524877e2c |
|||
timeCreated: 1464264924 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 5db8bb6be10ebf244acdc1faa2585ef2 |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 32e29ba6d98ba0140a774b7804b02a28 |
|||
folderAsset: yes |
|||
timeCreated: 1464264921 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
UnityProject/Assets/UnityShaderEditor/Graphs/TestGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 0c9dcadb1b558ae42a80c642bbd7add7 |
|||
timeCreated: 1454679931 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
UnityProject/Assets/UnityShaderEditor/Graphs/stine.ShaderGraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 754ba2dfba8dd3e40a130b6ecd09ec6b |
|||
timeCreated: 1455192604 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.IO; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.ProjectWindowCallback; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
public class CreateSerializableGraph : EndNameEditAction |
|||
{ |
|||
[MenuItem("Assets/Create/Serializable Graph", false, 207)] |
|||
public static void CreateMaterialGraph() |
|||
{ |
|||
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateSerializableGraph>(), |
|||
"New Shader Graph.ShaderGraph", null, null); |
|||
} |
|||
|
|||
public override void Action(int instanceId, string pathName, string resourceFile) |
|||
{ |
|||
var graph = CreateInstance<SerializableGraphAsset>(); |
|||
graph.name = Path.GetFileName(pathName); |
|||
AssetDatabase.CreateAsset(graph, pathName); |
|||
} |
|||
} |
|||
|
|||
public class SerializableGraphAsset : ScriptableObject |
|||
{ |
|||
[SerializeField] |
|||
private SerializableGraph m_Graph; |
|||
|
|||
public SerializableGraph graph |
|||
{ |
|||
get { return m_Graph; } |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d730ce8d1849fef439b593190f45eaec |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEditor.Experimental; |
|||
using UnityEditor.Experimental.Graph; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.Graphing.Drawing |
|||
{ |
|||
public sealed class DrawableNode : CanvasElement |
|||
{ |
|||
private readonly GraphDataSource m_Data; |
|||
public INode m_Node; |
|||
|
|||
private Rect m_PreviewArea; |
|||
private Rect m_NodeUIRect; |
|||
|
|||
public DrawableNode(INode node, float width, GraphDataSource data) |
|||
{ |
|||
translation = node.position.min; |
|||
scale = new Vector2(width, width); |
|||
|
|||
m_Node = node; |
|||
m_Data = data; |
|||
//m_Node.onNeedsRepaint += Invalidate;
|
|||
|
|||
const float yStart = 10.0f; |
|||
var vector3 = new Vector3(5.0f, yStart, 0.0f); |
|||
Vector3 pos = vector3; |
|||
|
|||
// input slots
|
|||
foreach (var slot in node.inputSlots) |
|||
{ |
|||
pos.y += 22; |
|||
AddChild(new NodeAnchor(pos, typeof(Vector4), node, slot, data, Direction.Input)); |
|||
} |
|||
var inputYMax = pos.y + 22; |
|||
|
|||
// output port
|
|||
pos.x = width; |
|||
pos.y = yStart; |
|||
foreach (var slot in node.outputSlots) |
|||
{ |
|||
var edges = node.owner.GetEdges(node.GetSlotReference(slot.name)); |
|||
// don't show empty output slots in collapsed mode
|
|||
//if (node.drawMode == DrawMode.Collapsed && !edges.Any())
|
|||
// continue;
|
|||
|
|||
pos.y += 22; |
|||
AddChild(new NodeAnchor(pos, typeof(Vector4), node, slot, data, Direction.Output)); |
|||
} |
|||
pos.y += 22; |
|||
|
|||
pos.y = Mathf.Max(pos.y, inputYMax); |
|||
|
|||
/* |
|||
var nodeUIHeight = m_Node.GetNodeUIHeight(width); |
|||
m_NodeUIRect = new Rect(10, pos.y, width - 20, nodeUIHeight); |
|||
pos.y += nodeUIHeight; |
|||
|
|||
if (node.hasPreview && node.drawMode != DrawMode.Collapsed) |
|||
{ |
|||
m_PreviewArea = new Rect(10, pos.y, width - 20, width - 20); |
|||
pos.y += m_PreviewArea.height; |
|||
}*/ |
|||
|
|||
scale = new Vector3(pos.x, pos.y + 10.0f, 0.0f); |
|||
//OnWidget += MarkDirtyIfNeedsTime;
|
|||
|
|||
AddManipulator(new ImguiContainer()); |
|||
AddManipulator(new Draggable()); |
|||
} |
|||
|
|||
/* |
|||
private bool MarkDirtyIfNeedsTime(CanvasElement element, Event e, Canvas2D parent) |
|||
{ |
|||
var childrenNodes = ListPool<INode>.Get(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(childrenNodes, m_Node); |
|||
if (childrenNodes.Any(x => x is IRequiresTime)) |
|||
Invalidate(); |
|||
ListPool<INode>.Release(childrenNodes); |
|||
return true; |
|||
}*/ |
|||
|
|||
public override void UpdateModel(UpdateType t) |
|||
{ |
|||
base.UpdateModel(t); |
|||
var pos = m_Node.position; |
|||
pos.min = translation; |
|||
m_Node.position = pos; |
|||
} |
|||
|
|||
public override void Render(Rect parentRect, Canvas2D canvas) |
|||
{ |
|||
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f); |
|||
Color selectedColor = new Color(1.0f, 0.7f, 0.0f, 0.7f); |
|||
EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), selected ? selectedColor : backgroundColor); |
|||
GUI.Label(new Rect(0, 0, scale.x, 26f), GUIContent.none, new GUIStyle("preToolbar")); |
|||
GUI.Label(new Rect(10, 2, scale.x - 20.0f, 16.0f), m_Node.name, EditorStyles.toolbarTextField); |
|||
/*if (GUI.Button(new Rect(scale.x - 20f, 3f, 14f, 14f), m_Node.drawMode == DrawMode.Full ? "-" : "+")) |
|||
{ |
|||
m_Node.drawMode = m_Node.drawMode == DrawMode.Full ? DrawMode.Collapsed : DrawMode.Full; |
|||
ParentCanvas().ReloadData(); |
|||
ParentCanvas().Repaint(); |
|||
return; |
|||
}*/ |
|||
|
|||
/*var modificationType = m_Node.NodeUI(m_NodeUIRect); |
|||
if (modificationType == GUIModificationType.Repaint) |
|||
{ |
|||
// if we were changed, we need to redraw all the
|
|||
// dependent nodes.
|
|||
RepaintDependentNodes(m_Node); |
|||
} |
|||
else if (modificationType == GUIModificationType.ModelChanged) |
|||
{ |
|||
ParentCanvas().ReloadData(); |
|||
ParentCanvas().Repaint(); |
|||
return; |
|||
} |
|||
|
|||
if (m_Node.hasPreview |
|||
&& m_Node.drawMode != DrawMode.Collapsed |
|||
&& m_PreviewArea.width > 0 |
|||
&& m_PreviewArea.height > 0) |
|||
{ |
|||
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear); |
|||
GUI.DrawTexture(m_PreviewArea, m_Node.RenderPreview(new Rect(0, 0, m_PreviewArea.width, m_PreviewArea.height)), ScaleMode.StretchToFill, false); |
|||
GL.sRGBWrite = false; |
|||
}*/ |
|||
|
|||
base.Render(parentRect, canvas); |
|||
} |
|||
|
|||
/* |
|||
public static void RepaintDependentNodes(AbstractMaterialNode bmn) |
|||
{ |
|||
var dependentNodes = new List<INode>(); |
|||
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, bmn); |
|||
foreach (var node in dependentNodes.OfType<SerializableNode>()) |
|||
node.onNeedsRepaint(); |
|||
} |
|||
|
|||
public static void OnGUI(List<CanvasElement> selection) |
|||
{ |
|||
var drawableMaterialNode = selection.OfType<DrawableMaterialNode>().FirstOrDefault(); |
|||
if (drawableMaterialNode != null && drawableMaterialNode.m_Node.OnGUI()) |
|||
{ |
|||
// if we were changed, we need to redraw all the
|
|||
// dependent nodes.
|
|||
RepaintDependentNodes(drawableMaterialNode.m_Node); |
|||
} |
|||
}*/ |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 52beeedec4c17cc4cad82cfe972c9b02 |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEditor.Experimental; |
|||
using UnityEditor.Experimental.Graph; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.Graphing.Drawing |
|||
{ |
|||
public class GraphDataSource : ICanvasDataSource |
|||
{ |
|||
readonly List<DrawableNode> m_DrawableNodes = new List<DrawableNode>(); |
|||
|
|||
public IGraph graph { get; set; } |
|||
|
|||
public ICollection<DrawableNode> lastGeneratedNodes |
|||
{ |
|||
get { return m_DrawableNodes; } |
|||
} |
|||
|
|||
public CanvasElement[] FetchElements() |
|||
{ |
|||
m_DrawableNodes.Clear(); |
|||
Debug.LogFormat("Trying to convert: {0}", graph); |
|||
foreach (var node in graph.nodes) |
|||
{ |
|||
// add the nodes
|
|||
m_DrawableNodes.Add(new DrawableNode(node, 200.0f, 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); |
|||
|
|||
var edges = baseNode.owner.GetEdges(new SlotReference(baseNode.guid, slot.name)); |
|||
foreach (var edge in edges) |
|||
{ |
|||
var toNode = baseNode.owner.GetNodeFromGuid(edge.inputSlot.nodeGuid); |
|||
var toSlot = toNode.FindInputSlot(edge.inputSlot.slotName); |
|||
var targetNode = m_DrawableNodes.FirstOrDefault(x => x.m_Node == toNode); |
|||
var targetAnchor = (NodeAnchor)targetNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == toSlot); |
|||
drawableEdges.Add(new Edge<NodeAnchor>(this, sourceAnchor, targetAnchor)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Add proxy inputs for when edges are not connect
|
|||
var nullInputSlots = new List<NullInputProxy>(); |
|||
foreach (var drawableMaterialNode in m_DrawableNodes) |
|||
{ |
|||
var baseNode = drawableMaterialNode.m_Node; |
|||
// grab the input slots where there are no edges
|
|||
foreach (var slot in baseNode.GetInputsWithNoConnection()) |
|||
{ |
|||
// if there is no anchor, continue
|
|||
// this can happen if we are in collapsed mode
|
|||
var sourceAnchor = (NodeAnchor)drawableMaterialNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor)x).m_Slot == slot); |
|||
if (sourceAnchor == null) |
|||
continue; |
|||
|
|||
nullInputSlots.Add(new NullInputProxy(baseNode, slot, sourceAnchor)); |
|||
} |
|||
} |
|||
var toReturn = new List<CanvasElement>(); |
|||
toReturn.AddRange(m_DrawableNodes.Select(x => (CanvasElement)x)); |
|||
toReturn.AddRange(drawableEdges.Select(x => (CanvasElement)x)); |
|||
toReturn.AddRange(nullInputSlots.Select(x => (CanvasElement)x)); |
|||
|
|||
//toReturn.Add(new FloatingPreview(new Rect(Screen.width - 300, Screen.height - 300, 300, 300), pixelGraph.nodes.FirstOrDefault(x => x is PixelShaderNode)));
|
|||
|
|||
Debug.LogFormat("Returning {0} nodes", m_DrawableNodes.Count); |
|||
Debug.LogFormat("Returning {0} drawableEdges", drawableEdges.Count); |
|||
Debug.LogFormat("Returning {0} nullInputSlots", nullInputSlots.Count); |
|||
return toReturn.ToArray(); |
|||
} |
|||
|
|||
public void DeleteElement(CanvasElement e) |
|||
{ |
|||
// do nothing here, we want to use delete elements.
|
|||
// delete elements ensures that edges are deleted before nodes.
|
|||
} |
|||
|
|||
public void DeleteElements(List<CanvasElement> elements) |
|||
{ |
|||
var toRemoveEdge = new List<IEdge>(); |
|||
// delete selected edges first
|
|||
foreach (var e in elements.OfType<Edge<NodeAnchor>>()) |
|||
{ |
|||
//find the edge
|
|||
var edge = graph.edges.FirstOrDefault(x => graph.GetNodeFromGuid(x.outputSlot.nodeGuid).FindOutputSlot(x.outputSlot.slotName) == e.Left.m_Slot |
|||
&& graph.GetNodeFromGuid(x.inputSlot.nodeGuid).FindInputSlot(x.inputSlot.slotName) == e.Right.m_Slot); |
|||
|
|||
toRemoveEdge.Add(edge); |
|||
} |
|||
|
|||
var toRemoveNode = new List<INode>(); |
|||
// now delete the nodes
|
|||
foreach (var e in elements.OfType<DrawableNode>()) |
|||
{ |
|||
if (!e.m_Node.canDeleteNode) |
|||
continue; |
|||
toRemoveNode.Add(e.m_Node); |
|||
} |
|||
graph.RemoveElements(toRemoveNode, toRemoveEdge); |
|||
} |
|||
|
|||
public void Connect(NodeAnchor a, NodeAnchor b) |
|||
{ |
|||
graph.Connect(a.m_Node.GetSlotReference(a.m_Slot.name), b.m_Node.GetSlotReference(b.m_Slot.name)); |
|||
} |
|||
|
|||
/* 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"); |
|||
} |
|||
} |
|||
|
|||
public class FloatingPreview : CanvasElement |
|||
{ |
|||
private AbstractMaterialNode m_Node; |
|||
|
|||
public FloatingPreview(Rect position, AbstractMaterialNode node) |
|||
{ |
|||
m_Node = node as AbstractMaterialNode; |
|||
m_Translation = new Vector2(position.x, position.y); |
|||
m_Scale = new Vector3(position.width, position.height, 1); |
|||
m_Caps |= Capabilities.Floating | Capabilities.Unselectable; |
|||
} |
|||
|
|||
public override void Render(Rect parentRect, Canvas2D canvas) |
|||
{ |
|||
var drawArea = new Rect(0, 0, scale.x, scale.y); |
|||
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f); |
|||
EditorGUI.DrawRect(drawArea, backgroundColor); |
|||
|
|||
drawArea.width -= 10; |
|||
drawArea.height -= 10; |
|||
drawArea.x += 5; |
|||
drawArea.y += 5; |
|||
|
|||
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear); |
|||
GUI.DrawTexture(drawArea, m_Node.RenderPreview(new Rect(0, 0, drawArea.width, drawArea.height)), ScaleMode.StretchToFill, false); |
|||
GL.sRGBWrite = false; |
|||
|
|||
Invalidate(); |
|||
canvas.Repaint(); |
|||
}*/ |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEditor.Experimental; |
|||
using UnityEditor.MaterialGraph; |
|||
using UnityEngine; |
|||
using Object = UnityEngine.Object; |
|||
|
|||
namespace UnityEditor.Graphing.Drawing |
|||
{ |
|||
class GraphEditWindow : EditorWindow |
|||
{ |
|||
[MenuItem("Window/Graph Editor")] |
|||
public static void OpenMenu() |
|||
{ |
|||
GetWindow<GraphEditWindow>(); |
|||
} |
|||
|
|||
[SerializeField] |
|||
private SerializableGraphAsset m_LastSelection; |
|||
|
|||
[NonSerialized] |
|||
private Canvas2D m_Canvas; |
|||
[NonSerialized] |
|||
private EditorWindow m_HostWindow; |
|||
[NonSerialized] |
|||
private GraphDataSource m_DataSource; |
|||
|
|||
private bool shouldRepaint |
|||
{ |
|||
get |
|||
{ |
|||
return m_LastSelection != null && m_LastSelection.graph != null; |
|||
} |
|||
} |
|||
|
|||
void Update() |
|||
{ |
|||
if (shouldRepaint) |
|||
Repaint(); |
|||
} |
|||
|
|||
void OnSelectionChange() |
|||
{ |
|||
if (Selection.activeObject == null || !EditorUtility.IsPersistent(Selection.activeObject)) |
|||
return; |
|||
|
|||
if (Selection.activeObject is SerializableGraphAsset) |
|||
{ |
|||
var selection = (SerializableGraphAsset) Selection.activeObject; |
|||
if (selection != m_LastSelection) |
|||
{ |
|||
m_LastSelection = selection; |
|||
Rebuild(); |
|||
Repaint(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void InitializeCanvas() |
|||
{ |
|||
if (m_Canvas == null) |
|||
{ |
|||
m_DataSource = new GraphDataSource(); |
|||
m_Canvas = new Canvas2D(this, m_HostWindow, m_DataSource); |
|||
|
|||
// draggable manipulator allows to move the canvas around. Note that individual elements can have the draggable manipulator on themselves
|
|||
m_Canvas.AddManipulator(new Draggable(2, EventModifiers.None)); |
|||
m_Canvas.AddManipulator(new Draggable(0, EventModifiers.Alt)); |
|||
|
|||
// make the canvas zoomable
|
|||
m_Canvas.AddManipulator(new Zoomable()); |
|||
|
|||
// allow framing the selection when hitting "F" (frame) or "A" (all). Basically shows how to trap a key and work with the canvas selection
|
|||
m_Canvas.AddManipulator(new Frame(Frame.FrameType.All)); |
|||
m_Canvas.AddManipulator(new Frame(Frame.FrameType.Selection)); |
|||
|
|||
// The following manipulator show how to work with canvas2d overlay and background rendering
|
|||
m_Canvas.AddManipulator(new RectangleSelect()); |
|||
m_Canvas.AddManipulator(new ScreenSpaceGrid()); |
|||
m_Canvas.AddManipulator(new ContextualMenu(DoAddNodeMenu)); |
|||
|
|||
m_Canvas.AddManipulator(new DeleteSelected(m_DataSource.DeleteElements, m_Canvas)); |
|||
} |
|||
|
|||
Rebuild(); |
|||
} |
|||
|
|||
private class AddNodeCreationObject : object |
|||
{ |
|||
public Vector2 m_Pos; |
|||
public readonly Type m_Type; |
|||
|
|||
public AddNodeCreationObject(Type t, Vector2 p) { m_Type = t; m_Pos = p; } |
|||
}; |
|||
|
|||
private void AddNode(object obj) |
|||
{ |
|||
var posObj = obj as AddNodeCreationObject; |
|||
if (posObj == null) |
|||
return; |
|||
|
|||
INode node; |
|||
try |
|||
{ |
|||
node = Activator.CreateInstance(posObj.m_Type, m_LastSelection.graph) as INode; |
|||
} |
|||
catch |
|||
{ |
|||
Debug.LogWarningFormat("Could not construct instance of: {0}", posObj.m_Type); |
|||
return; |
|||
} |
|||
|
|||
if (node == null) |
|||
return; |
|||
|
|||
node.position = new Rect(posObj.m_Pos.x, posObj.m_Pos.y, node.position.width, node.position.height); |
|||
m_LastSelection.graph.AddNode(node); |
|||
|
|||
Rebuild(); |
|||
Repaint(); |
|||
} |
|||
|
|||
public virtual bool CanAddToNodeMenu(Type type) { return true; } |
|||
protected bool DoAddNodeMenu(Event @event, Canvas2D parent, Object customData) |
|||
{ |
|||
var gm = new GenericMenu(); |
|||
foreach (Type type in Assembly.GetAssembly(typeof(AbstractMaterialNode)).GetTypes()) |
|||
{ |
|||
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(AbstractMaterialNode)))) |
|||
{ |
|||
var attrs = type.GetCustomAttributes(typeof(TitleAttribute), false) as TitleAttribute[]; |
|||
if (attrs != null && attrs.Length > 0 && CanAddToNodeMenu(type)) |
|||
{ |
|||
gm.AddItem(new GUIContent(attrs[0].m_Title), false, AddNode, new AddNodeCreationObject(type, parent.MouseToCanvas(@event.mousePosition))); |
|||
} |
|||
} |
|||
} |
|||
gm.ShowAsContext(); |
|||
return true; |
|||
} |
|||
|
|||
private void Rebuild() |
|||
{ |
|||
if (m_Canvas == null || m_LastSelection == null || m_LastSelection.graph == null) |
|||
return; |
|||
|
|||
m_DataSource.graph = m_LastSelection.graph; |
|||
m_Canvas.ReloadData(); |
|||
} |
|||
|
|||
void OnGUI() |
|||
{ |
|||
m_HostWindow = this; |
|||
if (m_Canvas == null) |
|||
{ |
|||
InitializeCanvas(); |
|||
} |
|||
|
|||
if (m_LastSelection == null || m_LastSelection.graph == null) |
|||
{ |
|||
GUILayout.Label("No Graph selected"); |
|||
return; |
|||
} |
|||
|
|||
m_Canvas.OnGUI(this, new Rect(0, 0, position.width - 250, position.height)); |
|||
} |
|||
|
|||
/*public void RenderOptions(MaterialGraph graph) |
|||
{ |
|||
EditorGUILayout.BeginHorizontal(); |
|||
GUILayout.FlexibleSpace(); |
|||
|
|||
EditorGUILayout.BeginVertical(); |
|||
m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos, EditorStyles.textArea, GUILayout.Width(250), GUILayout.ExpandHeight(true)); |
|||
graph.materialOptions.DoGUI(); |
|||
EditorGUILayout.Separator(); |
|||
|
|||
m_NodeExpanded = MaterialGraphStyles.Header("Selected", m_NodeExpanded); |
|||
if (m_NodeExpanded) |
|||
DrawableMaterialNode.OnGUI(m_Canvas.selection); |
|||
|
|||
GUILayout.EndScrollView(); |
|||
if (GUILayout.Button("Export")) |
|||
m_DataSource.Export(false); |
|||
|
|||
GUILayout.EndVertical(); |
|||
EditorGUILayout.EndHorizontal(); |
|||
}*/ |
|||
} |
|||
} |
|
|||
using UnityEditor.Experimental; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.Graphing.Drawing |
|||
{ |
|||
public class NullInputProxy : CanvasElement |
|||
{ |
|||
private ISlot m_InputSlot; |
|||
private INode m_Node; |
|||
private NodeAnchor m_NodeAnchor; |
|||
|
|||
private const int kWidth = 180; |
|||
|
|||
public NullInputProxy(INode node, ISlot inputSlot, NodeAnchor nodeAnchor) |
|||
{ |
|||
m_InputSlot = inputSlot; |
|||
m_Node = node; |
|||
m_NodeAnchor = nodeAnchor; |
|||
|
|||
var size = m_NodeAnchor.scale; |
|||
size.x = kWidth; |
|||
scale = size; |
|||
|
|||
nodeAnchor.AddDependency(this); |
|||
UpdateModel(UpdateType.Update); |
|||
|
|||
var position = m_NodeAnchor.canvasBoundingRect.min; |
|||
position.x -= kWidth; |
|||
translation = position; |
|||
AddManipulator(new ImguiContainer()); |
|||
} |
|||
|
|||
|
|||
public override void Render(Rect parentRect, Canvas2D canvas) |
|||
{ |
|||
base.Render(parentRect, canvas); |
|||
|
|||
var size = m_NodeAnchor.scale; |
|||
size.x = kWidth; |
|||
scale = size; |
|||
|
|||
var position = m_NodeAnchor.canvasBoundingRect.min; |
|||
position.x -= kWidth; |
|||
translation = position; |
|||
|
|||
var rect = new Rect(0, 0, scale.x, scale.y); |
|||
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f)); |
|||
|
|||
//TODO: FIX
|
|||
/*var changed = m_Node.DrawSlotDefaultInput(rect, m_InputSlot); |
|||
if (changed) |
|||
DrawableMaterialNode.RepaintDependentNodes(m_Node);*/ |
|||
} |
|||
|
|||
public override void UpdateModel(UpdateType t) |
|||
{ |
|||
var size = m_NodeAnchor.scale; |
|||
size.x = kWidth; |
|||
scale = size; |
|||
|
|||
var position = m_NodeAnchor.canvasBoundingRect.min; |
|||
position.x -= kWidth; |
|||
translation = position; |
|||
|
|||
base.UpdateModel(t); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d35a1ba1f2dabea42ab1fc3d040eec81 |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: b5721d495a5354c4a96da57b12f43adb |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 94b39bb81d63f9c4d99f87da537af3ef |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: bd99903e0e5626448a8518284feeb047 |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 236912145b2fff1409d2b69157f5de23 |
|||
timeCreated: 1464264924 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c465ac18d51260d41999717f8c47770f |
|||
timeCreated: 1464264925 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 6b610a05c25f54d4c90f7ebf82696481 |
|||
timeCreated: 1463576280 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c1bef593b05291f46b4bfd7a7192b881 |
|||
timeCreated: 1464079584 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 992a8f404953a8248b943cb6fb0b2c79 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
fileFormatVersion: 2 |
|||
guid: 212c20183bfb8be42a77c212a54af19e |
|||
timeCreated: 1464079584 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a9ce774f3d69dc241aff311e95b8ad19 |
|||
timeCreated: 1464081042 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 751467780a86a1044a8037840649efd0 |
|||
timeCreated: 1464081042 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a178e14960be0e944b4652535f2d12e4 |
|||
timeCreated: 1463576280 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 476f6813876d1d04387dfa9640d44324 |
|||
timeCreated: 1445419780 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#define DEBUG_MAT_GEN
|
|||
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEditor.Experimental; |
|||
using UnityEngine; |
|||
using Object = UnityEngine.Object; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
class MaterialWindow : EditorWindow |
|||
{ |
|||
[MenuItem("Window/Material")] |
|||
public static void OpenMenu() |
|||
{ |
|||
GetWindow<MaterialWindow>(); |
|||
} |
|||
|
|||
private MaterialGraph m_MaterialGraph; |
|||
private Canvas2D m_Canvas = null; |
|||
private EditorWindow m_HostWindow = null; |
|||
private MaterialGraphDataSource m_DataSource; |
|||
private Vector2 m_ScrollPos; |
|||
private bool m_NodeExpanded; |
|||
|
|||
private bool shouldRepaint |
|||
{ |
|||
get |
|||
{ |
|||
return m_MaterialGraph != null && m_MaterialGraph.currentGraph != null && m_MaterialGraph.currentGraph.requiresRepaint; |
|||
} |
|||
} |
|||
|
|||
void Update() |
|||
{ |
|||
if (shouldRepaint) |
|||
Repaint(); |
|||
} |
|||
|
|||
void OnSelectionChange() |
|||
{ |
|||
if (Selection.activeObject == null || !EditorUtility.IsPersistent(Selection.activeObject)) |
|||
return; |
|||
|
|||
if (Selection.activeObject is MaterialGraphAsset) |
|||
{ |
|||
var selection = Selection.activeObject as MaterialGraphAsset; |
|||
if (selection.graph != m_MaterialGraph) |
|||
{ |
|||
m_MaterialGraph = selection.graph; |
|||
} |
|||
} |
|||
|
|||
Rebuild(); |
|||
Repaint(); |
|||
} |
|||
|
|||
private void InitializeCanvas() |
|||
{ |
|||
if (m_Canvas == null) |
|||
{ |
|||
m_DataSource = new MaterialGraphDataSource(); |
|||
m_Canvas = new Canvas2D(this, m_HostWindow, m_DataSource); |
|||
|
|||
// draggable manipulator allows to move the canvas around. Note that individual elements can have the draggable manipulator on themselves
|
|||
m_Canvas.AddManipulator(new Draggable(2, EventModifiers.None)); |
|||
m_Canvas.AddManipulator(new Draggable(0, EventModifiers.Alt)); |
|||
|
|||
// make the canvas zoomable
|
|||
m_Canvas.AddManipulator(new Zoomable()); |
|||
|
|||
// allow framing the selection when hitting "F" (frame) or "A" (all). Basically shows how to trap a key and work with the canvas selection
|
|||
m_Canvas.AddManipulator(new Frame(Frame.FrameType.All)); |
|||
m_Canvas.AddManipulator(new Frame(Frame.FrameType.Selection)); |
|||
|
|||
// The following manipulator show how to work with canvas2d overlay and background rendering
|
|||
m_Canvas.AddManipulator(new RectangleSelect()); |
|||
m_Canvas.AddManipulator(new ScreenSpaceGrid()); |
|||
m_Canvas.AddManipulator(new ContextualMenu(DoAddNodeMenu)); |
|||
|
|||
m_Canvas.AddManipulator(new DeleteSelected(m_DataSource.DeleteElements, m_Canvas)); |
|||
} |
|||
|
|||
Rebuild(); |
|||
} |
|||
|
|||
private class AddNodeCreationObject : object |
|||
{ |
|||
public Vector2 m_Pos; |
|||
public readonly Type m_Type; |
|||
|
|||
public AddNodeCreationObject(Type t, Vector2 p) { m_Type = t; m_Pos = p; } |
|||
}; |
|||
|
|||
private void AddNode(object obj) |
|||
{ |
|||
var posObj = obj as AddNodeCreationObject; |
|||
if (posObj == null) |
|||
return; |
|||
|
|||
AbstractMaterialNode node = null; |
|||
try |
|||
{ |
|||
var constructorInfo = posObj.m_Type.GetConstructor(new[] {typeof(AbstractMaterialGraph)}); |
|||
node = (AbstractMaterialNode)constructorInfo.Invoke(new object[] { m_MaterialGraph.currentGraph }); |
|||
} |
|||
catch |
|||
{ |
|||
Debug.LogWarningFormat("Could not construct instance of: {0} as there is no single argument constuctor that takes a AbstractMaterialGraph", posObj.m_Type); |
|||
return; |
|||
} |
|||
|
|||
node.position = new Rect(posObj.m_Pos.x, posObj.m_Pos.y, node.position.width, node.position.height); |
|||
m_MaterialGraph.currentGraph.AddNode(node); |
|||
|
|||
Rebuild(); |
|||
Repaint(); |
|||
} |
|||
|
|||
public virtual bool CanAddToNodeMenu(Type type) { return true; } |
|||
protected bool DoAddNodeMenu(Event @event, Canvas2D parent, Object customData) |
|||
{ |
|||
var gm = new GenericMenu(); |
|||
foreach (Type type in Assembly.GetAssembly(typeof(AbstractMaterialNode)).GetTypes()) |
|||
{ |
|||
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(AbstractMaterialNode)))) |
|||
{ |
|||
var attrs = type.GetCustomAttributes(typeof(TitleAttribute), false) as TitleAttribute[]; |
|||
if (attrs != null && attrs.Length > 0 && CanAddToNodeMenu(type)) |
|||
{ |
|||
gm.AddItem(new GUIContent(attrs[0].m_Title), false, AddNode, new AddNodeCreationObject(type, parent.MouseToCanvas(@event.mousePosition))); |
|||
} |
|||
} |
|||
} |
|||
gm.ShowAsContext(); |
|||
return true; |
|||
} |
|||
|
|||
private void Rebuild() |
|||
{ |
|||
if (m_Canvas == null || m_MaterialGraph == null) |
|||
return; |
|||
|
|||
m_DataSource.graph = m_MaterialGraph; |
|||
m_Canvas.ReloadData(); |
|||
} |
|||
|
|||
void OnGUI() |
|||
{ |
|||
m_HostWindow = this; |
|||
if (m_Canvas == null) |
|||
{ |
|||
InitializeCanvas(); |
|||
} |
|||
|
|||
if (m_MaterialGraph == null) |
|||
{ |
|||
GUILayout.Label("No Graph selected"); |
|||
return; |
|||
} |
|||
|
|||
//m_Canvas.dataSource = m_ActiveGraph;
|
|||
m_Canvas.OnGUI(this, new Rect(0, 0, position.width - 250, position.height)); |
|||
RenderOptions(m_MaterialGraph); |
|||
} |
|||
|
|||
public void RenderOptions(MaterialGraph graph) |
|||
{ |
|||
EditorGUILayout.BeginHorizontal(); |
|||
GUILayout.FlexibleSpace(); |
|||
|
|||
EditorGUILayout.BeginVertical(); |
|||
m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos, EditorStyles.textArea, GUILayout.Width(250), GUILayout.ExpandHeight(true)); |
|||
graph.materialOptions.DoGUI(); |
|||
EditorGUILayout.Separator(); |
|||
|
|||
m_NodeExpanded = MaterialGraphStyles.Header("Selected", m_NodeExpanded); |
|||
if (m_NodeExpanded) |
|||
DrawableMaterialNode.OnGUI(m_Canvas.selection); |
|||
|
|||
GUILayout.EndScrollView(); |
|||
if (GUILayout.Button("Export")) |
|||
m_DataSource.Export(false); |
|||
|
|||
GUILayout.EndVertical(); |
|||
EditorGUILayout.EndHorizontal(); |
|||
} |
|||
|
|||
public static void DebugMaterialGraph(string s) |
|||
{ |
|||
#if DEBUG_MAT_GEN
|
|||
Debug.Log(s); |
|||
#endif
|
|||
} |
|||
} |
|||
} |
|
|||
using UnityEditor.Experimental; |
|||
using UnityEditor.Graphs; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
public class NullInputProxy : CanvasElement |
|||
{ |
|||
private MaterialSlot m_InputSlot; |
|||
private AbstractMaterialNode m_Node; |
|||
private NodeAnchor m_NodeAnchor; |
|||
|
|||
private const int kWidth = 180; |
|||
|
|||
public NullInputProxy(AbstractMaterialNode node, MaterialSlot inputSlot, NodeAnchor nodeAnchor) |
|||
{ |
|||
m_InputSlot = inputSlot; |
|||
m_Node = node; |
|||
m_NodeAnchor = nodeAnchor; |
|||
|
|||
var size = m_NodeAnchor.scale; |
|||
size.x = kWidth; |
|||
scale = size; |
|||
|
|||
nodeAnchor.AddDependency(this); |
|||
UpdateModel(UpdateType.Update); |
|||
|
|||
var position = m_NodeAnchor.canvasBoundingRect.min; |
|||
position.x -= kWidth; |
|||
translation = position; |
|||
AddManipulator(new ImguiContainer()); |
|||
} |
|||
|
|||
|
|||
public override void Render(Rect parentRect, Canvas2D canvas) |
|||
{ |
|||
base.Render(parentRect, canvas); |
|||
|
|||
var size = m_NodeAnchor.scale; |
|||
size.x = kWidth; |
|||
scale = size; |
|||
|
|||
var position = m_NodeAnchor.canvasBoundingRect.min; |
|||
position.x -= kWidth; |
|||
translation = position; |
|||
|
|||
var rect = new Rect(0, 0, scale.x, scale.y); |
|||
var changed = m_Node.DrawSlotDefaultInput(rect, m_InputSlot); |
|||
if (changed) |
|||
DrawableMaterialNode.RepaintDependentNodes(m_Node); |
|||
} |
|||
|
|||
public override void UpdateModel(UpdateType t) |
|||
{ |
|||
var size = m_NodeAnchor.scale; |
|||
size.x = kWidth; |
|||
scale = size; |
|||
|
|||
var position = m_NodeAnchor.canvasBoundingRect.min; |
|||
position.x -= kWidth; |
|||
translation = position; |
|||
|
|||
base.UpdateModel(t); |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEditor.Experimental; |
|||
using UnityEditor.Experimental.Graph; |
|||
using UnityEditor.Graphing; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
public sealed class DrawableMaterialNode : CanvasElement |
|||
{ |
|||
private readonly MaterialGraphDataSource m_Data; |
|||
public AbstractMaterialNode m_Node; |
|||
|
|||
private Rect m_PreviewArea; |
|||
private Rect m_NodeUIRect; |
|||
|
|||
public DrawableMaterialNode(AbstractMaterialNode node, float width, MaterialGraphDataSource data) |
|||
{ |
|||
translation = node.position.min; |
|||
scale = new Vector2(width, width); |
|||
|
|||
m_Node = node; |
|||
m_Data = data; |
|||
m_Node.onNeedsRepaint += Invalidate; |
|||
|
|||
const float yStart = 10.0f; |
|||
var vector3 = new Vector3(5.0f, yStart, 0.0f); |
|||
Vector3 pos = vector3; |
|||
|
|||
// input slots
|
|||
foreach (var slot in node.materialInputSlots) |
|||
{ |
|||
pos.y += 22; |
|||
AddChild(new NodeAnchor(pos, typeof (Vector4), node, slot, data, Direction.Input)); |
|||
} |
|||
var inputYMax = pos.y + 22; |
|||
|
|||
// output port
|
|||
pos.x = width; |
|||
pos.y = yStart; |
|||
foreach (var slot in node.materialOuputSlots) |
|||
{ |
|||
var edges = node.owner.GetEdges(new SlotReference(node.guid, slot.name)); |
|||
// don't show empty output slots in collapsed mode
|
|||
if (node.drawMode == DrawMode.Collapsed && !edges.Any()) |
|||
continue; |
|||
|
|||
pos.y += 22; |
|||
AddChild(new NodeAnchor(pos, typeof (Vector4), node, slot, data, Direction.Output)); |
|||
} |
|||
pos.y += 22; |
|||
|
|||
pos.y = Mathf.Max(pos.y, inputYMax); |
|||
|
|||
var nodeUIHeight = m_Node.GetNodeUIHeight(width); |
|||
m_NodeUIRect = new Rect(10, pos.y, width - 20, nodeUIHeight); |
|||
pos.y += nodeUIHeight; |
|||
|
|||
if (node.hasPreview && node.drawMode != DrawMode.Collapsed) |
|||
{ |
|||
m_PreviewArea = new Rect(10, pos.y, width - 20, width - 20); |
|||
pos.y += m_PreviewArea.height; |
|||
} |
|||
|
|||
scale = new Vector3(pos.x, pos.y + 10.0f, 0.0f); |
|||
OnWidget += MarkDirtyIfNeedsTime; |
|||
|
|||
AddManipulator(new ImguiContainer()); |
|||
AddManipulator(new Draggable()); |
|||
} |
|||
|
|||
private bool MarkDirtyIfNeedsTime(CanvasElement element, Event e, Canvas2D parent) |
|||
{ |
|||
var childrenNodes = ListPool<INode>.Get(); |
|||
NodeUtils.DepthFirstCollectNodesFromNode(childrenNodes, m_Node); |
|||
if (childrenNodes.Any(x => x is IRequiresTime)) |
|||
Invalidate(); |
|||
ListPool<INode>.Release(childrenNodes); |
|||
return true; |
|||
} |
|||
|
|||
public override void UpdateModel(UpdateType t) |
|||
{ |
|||
base.UpdateModel(t); |
|||
var pos = m_Node.position; |
|||
pos.min = translation; |
|||
m_Node.position = pos; |
|||
} |
|||
|
|||
public override void Render(Rect parentRect, Canvas2D canvas) |
|||
{ |
|||
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f); |
|||
Color selectedColor = new Color(1.0f, 0.7f, 0.0f, 0.7f); |
|||
EditorGUI.DrawRect(new Rect(0, 0, scale.x, scale.y), m_Node.hasError ? Color.red : selected ? selectedColor : backgroundColor); |
|||
GUI.Label(new Rect(0, 0, scale.x, 26f), GUIContent.none, new GUIStyle("preToolbar")); |
|||
GUI.Label(new Rect(10, 2, scale.x - 20.0f, 16.0f), m_Node.name, EditorStyles.toolbarTextField); |
|||
if (GUI.Button(new Rect(scale.x - 20f, 3f, 14f, 14f), m_Node.drawMode == DrawMode.Full ? "-" : "+")) |
|||
{ |
|||
m_Node.drawMode = m_Node.drawMode == DrawMode.Full ? DrawMode.Collapsed : DrawMode.Full; |
|||
ParentCanvas().ReloadData(); |
|||
ParentCanvas().Repaint(); |
|||
return; |
|||
} |
|||
|
|||
var modificationType = m_Node.NodeUI(m_NodeUIRect); |
|||
if (modificationType== GUIModificationType.Repaint) |
|||
{ |
|||
// if we were changed, we need to redraw all the
|
|||
// dependent nodes.
|
|||
RepaintDependentNodes(m_Node); |
|||
} |
|||
else if (modificationType == GUIModificationType.ModelChanged) |
|||
{ |
|||
ParentCanvas().ReloadData(); |
|||
ParentCanvas().Repaint(); |
|||
return; |
|||
} |
|||
|
|||
if (m_Node.hasPreview |
|||
&& m_Node.drawMode != DrawMode.Collapsed |
|||
&& m_PreviewArea.width > 0 |
|||
&& m_PreviewArea.height > 0) |
|||
{ |
|||
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear); |
|||
GUI.DrawTexture(m_PreviewArea, m_Node.RenderPreview(new Rect(0, 0, m_PreviewArea.width, m_PreviewArea.height)), ScaleMode.StretchToFill, false); |
|||
GL.sRGBWrite = false; |
|||
} |
|||
|
|||
base.Render(parentRect, canvas); |
|||
} |
|||
|
|||
public static void RepaintDependentNodes(AbstractMaterialNode bmn) |
|||
{ |
|||
var dependentNodes = new List<INode>(); |
|||
NodeUtils.CollectNodesNodeFeedsInto(dependentNodes, bmn); |
|||
foreach (var node in dependentNodes.OfType<SerializableNode>()) |
|||
node.onNeedsRepaint(); |
|||
} |
|||
|
|||
public static void OnGUI(List<CanvasElement> selection) |
|||
{ |
|||
var drawableMaterialNode = selection.OfType<DrawableMaterialNode>().FirstOrDefault(); |
|||
if (drawableMaterialNode != null && drawableMaterialNode.m_Node.OnGUI()) |
|||
{ |
|||
// if we were changed, we need to redraw all the
|
|||
// dependent nodes.
|
|||
RepaintDependentNodes(drawableMaterialNode.m_Node); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEditor.Experimental; |
|||
using UnityEditor.Experimental.Graph; |
|||
using UnityEditor.Graphing; |
|||
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 AbstractMaterialNode; |
|||
m_DrawableNodes.Add(new DrawableMaterialNode(bmn, (bmn is PixelShaderNode) ? 600.0f : 200.0f, 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); |
|||
|
|||
var edges = baseNode.owner.GetEdges(new SlotReference(baseNode.guid, slot.name)); |
|||
foreach (var edge in edges) |
|||
{ |
|||
var toNode = baseNode.owner.GetNodeFromGuid(edge.inputSlot.nodeGuid); |
|||
var toSlot = toNode.FindInputSlot(edge.inputSlot.slotName); |
|||
var targetNode = m_DrawableNodes.FirstOrDefault(x => x.m_Node == toNode); |
|||
var targetAnchor = (NodeAnchor)targetNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor) x).m_Slot == toSlot); |
|||
drawableEdges.Add(new Edge<NodeAnchor>(this, sourceAnchor, targetAnchor)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Add proxy inputs for when edges are not connect
|
|||
var nullInputSlots = new List<NullInputProxy>(); |
|||
foreach (var drawableMaterialNode in m_DrawableNodes) |
|||
{ |
|||
var baseNode = drawableMaterialNode.m_Node; |
|||
// grab the input slots where there are no edges
|
|||
foreach (var slot in baseNode.GetInputsWithNoConnection()) |
|||
{ |
|||
// if there is no anchor, continue
|
|||
// this can happen if we are in collapsed mode
|
|||
var sourceAnchor = (NodeAnchor)drawableMaterialNode.Children().FirstOrDefault(x => x is NodeAnchor && ((NodeAnchor)x).m_Slot == slot); |
|||
if (sourceAnchor == null) |
|||
continue; |
|||
|
|||
nullInputSlots.Add(new NullInputProxy(baseNode, slot, sourceAnchor)); |
|||
} |
|||
} |
|||
var toReturn = new List<CanvasElement>(); |
|||
toReturn.AddRange(m_DrawableNodes.Select(x => (CanvasElement)x)); |
|||
toReturn.AddRange(drawableEdges.Select(x => (CanvasElement)x)); |
|||
toReturn.AddRange(nullInputSlots.Select(x => (CanvasElement)x)); |
|||
|
|||
//toReturn.Add(new FloatingPreview(new Rect(Screen.width - 300, Screen.height - 300, 300, 300), pixelGraph.nodes.FirstOrDefault(x => x is PixelShaderNode)));
|
|||
|
|||
Debug.LogFormat("Returning {0} nodes", m_DrawableNodes.Count); |
|||
Debug.LogFormat("Returning {0} drawableEdges", drawableEdges.Count); |
|||
Debug.LogFormat("Returning {0} nullInputSlots", nullInputSlots.Count); |
|||
return toReturn.ToArray(); |
|||
} |
|||
|
|||
public void DeleteElement(CanvasElement e) |
|||
{ |
|||
// do nothing here, we want to use delete elements.
|
|||
// delete elements ensures that edges are deleted before nodes.
|
|||
} |
|||
|
|||
public void DeleteElements(List<CanvasElement> elements) |
|||
{ |
|||
var toRemoveEdge = new List<IEdge>(); |
|||
// delete selected edges first
|
|||
foreach (var e in elements.Where(x => x is Edge<NodeAnchor>)) |
|||
{ |
|||
//find the edge
|
|||
var localEdge = (Edge<NodeAnchor>) e; |
|||
var edge = graph.currentGraph.edges.FirstOrDefault(x => graph.currentGraph.GetNodeFromGuid(x.outputSlot.nodeGuid).FindOutputSlot(x.outputSlot.slotName) == localEdge.Left.m_Slot |
|||
&& graph.currentGraph.GetNodeFromGuid(x.inputSlot.nodeGuid).FindInputSlot(x.inputSlot.slotName) == localEdge.Right.m_Slot); |
|||
|
|||
toRemoveEdge.Add(edge); |
|||
} |
|||
|
|||
var toRemoveNode = new List<INode>(); |
|||
// now delete the nodes
|
|||
foreach (var e in elements.Where(x => x is DrawableMaterialNode)) |
|||
{ |
|||
var node = ((DrawableMaterialNode) e).m_Node; |
|||
if (!node.canDeleteNode) |
|||
continue; |
|||
toRemoveNode.Add(node); |
|||
} |
|||
graph.currentGraph.RemoveElements(toRemoveNode, toRemoveEdge); |
|||
} |
|||
|
|||
public void Connect(NodeAnchor a, NodeAnchor b) |
|||
{ |
|||
var pixelGraph = graph.currentGraph; |
|||
pixelGraph.Connect(a.m_Node.GetSlotReference(a.m_Slot.name), b.m_Node.GetSlotReference(b.m_Slot.name)); |
|||
} |
|||
|
|||
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"); |
|||
} |
|||
} |
|||
|
|||
public class FloatingPreview : CanvasElement |
|||
{ |
|||
private AbstractMaterialNode m_Node; |
|||
|
|||
public FloatingPreview(Rect position, AbstractMaterialNode node) |
|||
{ |
|||
m_Node = node as AbstractMaterialNode; |
|||
m_Translation = new Vector2(position.x, position.y); |
|||
m_Scale = new Vector3(position.width, position.height, 1); |
|||
m_Caps |= Capabilities.Floating | Capabilities.Unselectable; |
|||
} |
|||
|
|||
public override void Render(Rect parentRect, Canvas2D canvas) |
|||
{ |
|||
var drawArea = new Rect(0, 0, scale.x, scale.y); |
|||
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f); |
|||
EditorGUI.DrawRect(drawArea, backgroundColor); |
|||
|
|||
drawArea.width -= 10; |
|||
drawArea.height -= 10; |
|||
drawArea.x += 5; |
|||
drawArea.y += 5; |
|||
|
|||
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear); |
|||
GUI.DrawTexture(drawArea, m_Node.RenderPreview(new Rect(0, 0, drawArea.width, drawArea.height)), ScaleMode.StretchToFill, false); |
|||
GL.sRGBWrite = false; |
|||
|
|||
Invalidate(); |
|||
canvas.Repaint(); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue