浏览代码

[shader graph] Add context menu for adding nodes.

/main
Tim Cooper 9 年前
当前提交
5090feee
共有 2 个文件被更改,包括 166 次插入16 次删除
  1. 46
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialWindow.cs
  2. 136
      UnityProject/Assets/UnityShaderEditor/Graphs/GlowMud.ShaderGraph

46
UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialWindow.cs


#define DEBUG_MAT_GEN
using System;
using System.Reflection;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph
{

// 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));
}
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;
var node = (BaseMaterialNode)CreateInstance(posObj.m_Type);
node.Init();
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(BaseMaterialNode)).GetTypes())
{
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(BaseMaterialNode)) || type.IsSubclassOf(typeof(PropertyNode))))
{
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, m_Canvas.MouseToCanvas(@event.mousePosition)));
}
}
}
gm.ShowAsContext();
return true;
}
private void Rebuild()

136
UnityProject/Assets/UnityShaderEditor/Graphs/GlowMud.ShaderGraph


style: node
position:
serializedVersion: 2
x: 1056
y: -24
width: 310
height: 445
x: 1053.9392
y: -22.969591
width: 312.0608
height: 443.9696
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}

style: node
position:
serializedVersion: 2
x: -2742.6306
y: -1199.2351
width: 1940.6306
height: 1184.2351
x: -2476.4543
y: -376.32608
width: 1674.4543
height: 361.32608
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}

m_PrecisionNames:
- half
m_SwizzleChannel: 3
--- !u!114 &11428364
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f80af444cd4235c419b356216d784b57, type: 3}
m_Name: Sin Time
m_EditorClassIdentifier:
m_Slots:
- type: 1
m_Title: Sin Time
m_Name: SinTime
m_DataTypeString:
m_Properties: []
m_GenericTypeString:
color: 0
style: node
position:
serializedVersion: 2
x: -44.66852
y: -848.0728
width: 397.73764
height: 263.7843
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: SinTime
m_Node: {fileID: 11428364}
m_PrecisionNames:
- half
--- !u!114 &11434830
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 088fb5bde3ece0f4190136b3ab43f7c4, type: 3}
m_Name: MultiplyNode
m_EditorClassIdentifier:
m_Slots:
- type: 1
m_Title: Output
m_Name: Output
m_DataTypeString:
- type: 0
m_Title: Input 0
m_Name: Input0
m_DataTypeString:
- type: 0
m_Title: Input 1
m_Name: Input1
m_DataTypeString:
- type: 0
m_Title: Input 2
m_Name: Input2
m_DataTypeString:
m_Properties: []
m_GenericTypeString:
color: 0
style: node
position:
serializedVersion: 2
x: 425.1977
y: -656.4171
width: 0
height: 0
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Output
m_Node: {fileID: 11434830}
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Input0
m_Node: {fileID: 11434830}
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Input1
m_Node: {fileID: 11434830}
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}
m_Editable: 1
m_SlotName: Input2
m_Node: {fileID: 11434830}
m_PrecisionNames:
- half
--- !u!114 &11441414
MonoBehaviour:
m_ObjectHideFlags: 1

- {fileID: 11451638}
- {fileID: 11422894}
- {fileID: 11459506}
- {fileID: 11428364}
- {fileID: 11434830}
edges:
- m_FromNode: {fileID: 11498308}
m_ToNode: {fileID: 11406334}

m_FromSlotName: Output
m_ToSlotName: UV
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11428364}
m_ToNode: {fileID: 11434830}
m_FromSlotName: SinTime
m_ToSlotName: Input0
color: {r: 1, g: 1, b: 1, a: 1}
m_ToNode: {fileID: 11434830}
m_FromSlotName: Output
m_ToSlotName: Input1
color: {r: 1, g: 1, b: 1, a: 1}
- m_FromNode: {fileID: 11434830}
m_ToNode: {fileID: 11400400}
m_FromSlotName: Output
m_ToSlotName: Albedo

style: node
position:
serializedVersion: 2
x: -2537.4495
y: -1141.3364
width: 1731.4495
height: 1221.3364
x: -2271.2732
y: -318.42752
width: 1465.2732
height: 398.42755
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}

style: node
position:
serializedVersion: 2
x: -2128.9863
y: -1195.1257
width: 1458.9863
height: 1276.1259
x: -1862.811
y: -372.2167
width: 1192.811
height: 453.2167
showEmptySlots: 1
m_SlotDefaultValues:
- m_DefaultVector: {x: 1, y: 1, z: 1, w: 1}

正在加载...
取消
保存