internal static ShortcutEntry CreateFromAttribute(MethodInfo methodInfo, ShortcutAttribute attribute) { var keyEvent = Event.KeyboardEvent(attribute.defaultKeyCombination); var defaultCombination = new List <KeyCombination>(); var keyCombination = new KeyCombination(keyEvent); defaultCombination.Add(keyCombination); var identifier = new Identifier(methodInfo, attribute); var type = attribute is ClutchShortcutAttribute ? ShortcutType.Clutch : ShortcutType.Action; var methodParams = methodInfo.GetParameters(); Action <ShortcutArguments> action; if (methodParams.Length == 0) { action = shortcutArgs => { methodInfo.Invoke(null, k_EmptyReusableShortcutArgs); }; } else { action = shortcutArgs => { k_ReusableShortcutArgs[0] = shortcutArgs; methodInfo.Invoke(null, k_ReusableShortcutArgs); }; } return(new ShortcutEntry(identifier, defaultCombination, action, attribute.context, type)); }
internal static ShortcutEntry CreateFromAttribute(MethodInfo methodInfo, ShortcutAttribute attribute) { var keyEvent = Event.KeyboardEvent(attribute.defaultKeyCombination); var defaultCombination = new List <KeyCombination>(); var keyCombination = new KeyCombination(keyEvent); defaultCombination.Add(keyCombination); var identifier = new Identifier(methodInfo, attribute); var type = attribute is ClutchShortcutAttribute ? ShortcutType.Clutch : ShortcutType.Action; var methodParams = methodInfo.GetParameters(); Action <ShortcutArguments> action; if (methodParams.Length == 0) { action = shortcutArgs => { methodInfo.Invoke(null, k_EmptyReusableShortcutArgs); }; } else { action = shortcutArgs => { k_ReusableShortcutArgs[0] = shortcutArgs; methodInfo.Invoke(null, k_ReusableShortcutArgs); }; } KeyCombination?prefKeyMigratedValue = null; var prefKeyAttr = methodInfo.GetCustomAttributes( typeof(FormerlyPrefKeyAsAttribute), false ).FirstOrDefault() as FormerlyPrefKeyAsAttribute; if (prefKeyAttr != null) { var prefKeyDefaultValue = new KeyCombination(Event.KeyboardEvent(prefKeyAttr.defaultValue)); string name; Event keyboardEvent; if ( PrefKey.TryParseUniquePrefString(EditorPrefs.GetString(prefKeyAttr.name, prefKeyAttr.defaultValue), out name, out keyboardEvent) ) { var prefKeyCurrentValue = new KeyCombination(keyboardEvent); if (!prefKeyCurrentValue.Equals(prefKeyDefaultValue)) { prefKeyMigratedValue = prefKeyCurrentValue; } } } return(new ShortcutEntry(identifier, defaultCombination, action, attribute.context, type, prefKeyMigratedValue)); }
public Identifier(MethodInfo methodInfo, ShortcutAttribute attribute) { path = attribute.identifier; }