Peter Bay Bastian
8 年前
当前提交
36c08357
共有 3 个文件被更改,包括 99 次插入 和 0 次删除
-
6MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs
-
81MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/Commandable.cs
-
12MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/Commandable.cs.meta
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using UnityEngine; |
|||
using UnityEngine.RMGUI; |
|||
|
|||
namespace UnityEditor.Graphing.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 override EventPropagation HandleEvent(Event evt, VisualElement finalTarget) |
|||
{ |
|||
var isValidation = evt.type == EventType.ValidateCommand; |
|||
var isExecution = evt.type == EventType.ExecuteCommand; |
|||
if (isValidation || isExecution) |
|||
Debug.Log(evt.commandName); |
|||
CommandHandler handler; |
|||
if ((!isValidation && !isExecution) || !m_Dictionary.TryGetValue(evt.commandName, out handler)) |
|||
return EventPropagation.Continue; |
|||
if (isValidation && handler.Validate()) |
|||
return EventPropagation.Stop; |
|||
if (!isExecution) |
|||
return EventPropagation.Continue; |
|||
handler.Execute(); |
|||
return EventPropagation.Stop; |
|||
} |
|||
|
|||
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(); |
|||
} |
|||
} |
|||
|
|||
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(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 370985c9b2ecbcb4e8e74b7932e51baa |
|||
timeCreated: 1483970657 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue