浏览代码
#11 #43 Copy, paste & duplicate now works properly and is handled by the window rather than GraphView
/main
#11 #43 Copy, paste & duplicate now works properly and is handled by the window rather than GraphView
/main
Peter Bay Bastian
7 年前
当前提交
9dd4edeb
共有 5 个文件被更改,包括 49 次插入 和 150 次删除
-
24MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
-
33MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
35MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialGraphView.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Commandable.cs.meta
-
95MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Commandable.cs
|
|||
fileFormatVersion: 2 |
|||
guid: 370985c9b2ecbcb4e8e74b7932e51baa |
|||
timeCreated: 1483970657 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.UIElements; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing |
|||
{ |
|||
public class Commandable : Manipulator, IEnumerable<KeyValuePair<string, CommandHandler>> |
|||
{ |
|||
private readonly Dictionary<string, CommandHandler> m_Dictionary; |
|||
|
|||
public Commandable() |
|||
{ |
|||
m_Dictionary = new Dictionary<string, CommandHandler>(); |
|||
} |
|||
|
|||
public void HandleEvent(EventBase evt) |
|||
{ |
|||
var isValidation = evt.imguiEvent.type == EventType.ValidateCommand; |
|||
var isExecution = evt.imguiEvent.type == EventType.ExecuteCommand; |
|||
if (isValidation || isExecution) |
|||
Debug.Log(evt.imguiEvent.commandName); |
|||
CommandHandler handler; |
|||
if ((!isValidation && !isExecution) || !m_Dictionary.TryGetValue(evt.imguiEvent.commandName, out handler)) |
|||
{ |
|||
return; |
|||
} |
|||
if (isValidation && handler.Validate()) |
|||
{ |
|||
evt.StopPropagation(); |
|||
return; |
|||
} |
|||
if (!isExecution) |
|||
{ |
|||
return; |
|||
} |
|||
handler.Execute(); |
|||
evt.StopPropagation(); |
|||
} |
|||
|
|||
public void Add(string commandName, CommandValidator validator, CommandExecutor executor) |
|||
{ |
|||
m_Dictionary[commandName] = new CommandHandler(validator, executor); |
|||
} |
|||
|
|||
IEnumerator IEnumerable.GetEnumerator() |
|||
{ |
|||
return GetEnumerator(); |
|||
} |
|||
|
|||
public IEnumerator<KeyValuePair<string, CommandHandler>> GetEnumerator() |
|||
{ |
|||
return m_Dictionary.GetEnumerator(); |
|||
} |
|||
|
|||
protected override void RegisterCallbacksOnTarget() |
|||
{ |
|||
target.RegisterCallback<IMGUIEvent>(HandleEvent); |
|||
} |
|||
|
|||
protected override void UnregisterCallbacksFromTarget() |
|||
{ |
|||
target.UnregisterCallback<IMGUIEvent>(HandleEvent); |
|||
} |
|||
} |
|||
|
|||
public delegate bool CommandValidator(); |
|||
|
|||
public delegate void CommandExecutor(); |
|||
|
|||
public class CommandHandler |
|||
{ |
|||
private readonly CommandValidator m_Validator; |
|||
private readonly CommandExecutor m_Executor; |
|||
|
|||
public CommandHandler(CommandValidator validator, CommandExecutor executor) |
|||
{ |
|||
m_Validator = validator; |
|||
m_Executor = executor; |
|||
} |
|||
|
|||
public bool Validate() |
|||
{ |
|||
if (m_Validator != null) |
|||
return m_Validator(); |
|||
return false; |
|||
} |
|||
|
|||
public void Execute() |
|||
{ |
|||
if (m_Executor != null) |
|||
m_Executor(); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue