浏览代码
Move slot compatibility check code into MaterialSlot
Move slot compatibility check code into MaterialSlot
Validate commands directly in window class, rather than through MaterialGraphPresenter Move a few things from MaterialGraphPresenter to GraphEditorView Create manipulator for node creation (NodeCreator), rather than manually doing it in MaterialGraph Move things from MaterialGraph constructor into GraphEditorView Completely remove GridBackground, as we were not using it Remove Clicker manipulator, as it was not used/main
Peter Bay Bastian
7 年前
当前提交
9dbfb5c3
共有 10 个文件被更改,包括 118 次插入 和 227 次删除
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
-
60MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
19MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
-
98MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
-
73MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/NodeCreator.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/NodeCreator.cs.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Clicker.cs.meta
-
47MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Clicker.cs
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing |
|||
{ |
|||
public class NodeCreator : MouseManipulator |
|||
{ |
|||
VisualElement m_ContentViewContainer; |
|||
IGraph m_Graph; |
|||
Vector2 m_MouseUpPosition; |
|||
GenericMenu m_Menu; |
|||
|
|||
public NodeCreator(IGraph graph) |
|||
{ |
|||
m_Graph = graph; |
|||
activators.Add(new ManipulatorActivationFilter { button = MouseButton.RightMouse }); |
|||
m_Menu = new GenericMenu(); |
|||
foreach (var 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) |
|||
m_Menu.AddItem(new GUIContent(attrs[0].m_Title), false, OnAddNode, type); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void OnAddNode(object userData) |
|||
{ |
|||
var type = userData as Type; |
|||
var node = Activator.CreateInstance(type) as INode; |
|||
if (node == null) |
|||
return; |
|||
|
|||
var drawState = node.drawState; |
|||
drawState.position = new Rect(m_MouseUpPosition.x, m_MouseUpPosition.y, 0, 0); |
|||
node.drawState = drawState; |
|||
|
|||
m_Graph.owner.RegisterCompleteObjectUndo("Add " + node.name); |
|||
m_Graph.AddNode(node); |
|||
} |
|||
|
|||
protected override void RegisterCallbacksOnTarget() |
|||
{ |
|||
var graphView = target as GraphView; |
|||
if (graphView == null) |
|||
return; |
|||
m_ContentViewContainer = graphView.contentViewContainer; |
|||
target.RegisterCallback<MouseUpEvent>(OnMouseUp); |
|||
} |
|||
|
|||
void OnMouseUp(MouseUpEvent evt) |
|||
{ |
|||
if (CanStartManipulation(evt)) |
|||
{ |
|||
m_MouseUpPosition = m_ContentViewContainer.transform.matrix.inverse.MultiplyPoint3x4(evt.localMousePosition); |
|||
m_Menu.ShowAsContext(); |
|||
evt.StopPropagation(); |
|||
} |
|||
} |
|||
|
|||
protected override void UnregisterCallbacksFromTarget() |
|||
{ |
|||
target.UnregisterCallback<MouseUpEvent>(OnMouseUp); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 48d2349cc7ed41d9bf77231b69efbc05 |
|||
timeCreated: 1508752297 |
|
|||
fileFormatVersion: 2 |
|||
guid: 8e1784667072e48fb8402ab89ecd3c68 |
|||
timeCreated: 1479838786 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Experimental.UIElements; |
|||
using MouseManipulator = UnityEngine.Experimental.UIElements.MouseManipulator; |
|||
|
|||
using ManipulatorActivationFilter = UnityEngine.Experimental.UIElements.ManipulatorActivationFilter; |
|||
using MouseButton = UnityEngine.Experimental.UIElements.MouseButton; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing |
|||
{ |
|||
public enum ClickerState |
|||
{ |
|||
Inactive, |
|||
Active |
|||
} |
|||
|
|||
// TODO JOCE: This is to mimic the behavior of a button. Remove and replace with actual button in TitleBar.
|
|||
public class Clicker : MouseManipulator |
|||
{ |
|||
public delegate void StateChangeCallback(ClickerState newState); |
|||
public delegate void ClickCallback(); |
|||
|
|||
public StateChangeCallback onStateChange { get; set; } |
|||
public ClickCallback onClick { get; set; } |
|||
|
|||
VisualElement initialTarget; |
|||
ClickerState state; |
|||
|
|||
public Clicker() |
|||
{ |
|||
activators.Add(new ManipulatorActivationFilter {button = MouseButton.LeftMouse}); |
|||
} |
|||
|
|||
protected override void RegisterCallbacksOnTarget() |
|||
{ |
|||
target.RegisterCallback<MouseUpEvent>(OnMouseUp, Capture.Capture); |
|||
} |
|||
|
|||
protected override void UnregisterCallbacksFromTarget() |
|||
{ |
|||
target.UnregisterCallback<MouseUpEvent>(OnMouseUp, Capture.Capture); |
|||
} |
|||
|
|||
void OnMouseUp(MouseUpEvent evt) |
|||
{ |
|||
onClick(); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue