Jumes
Topic Author
Posts: 16
Joined: 31 May 2017, 12:57

KeyBinding is not supported in Unity?

22 Jun 2017, 11:31

Hello,
I added some code below into the MainMenu.xaml under the sample Menu3D
<UserControl.InputBindings>
<KeyBinding Command="{Binding Start}" Key="A"></KeyBinding>
</UserControl.InputBindings>

It can work in WPF, but in Unity I got some errors:
NoesisException: Unable to convert 'A' to a valid value for property KeyBinding.Key (@10,8)
Noesis.Error.Check () (at Assets/NoesisGUI/Plugins/API/Core/NoesisError.cs:21)
Noesis.Extend.Noesis_InstantiateExtend_ (IntPtr nativeType) (at Assets/NoesisGUI/Plugins/API/Core/NoesisExtendImports.cs:26)
Noesis.Extend.NewCPtr (System.Type type, System.Object instance) (at Assets/NoesisGUI/Plugins/API/Core/NoesisExtend.cs:3829)
Noesis.Extend.GetInstanceHandle (System.Object instance) (at Assets/NoesisGUI/Plugins/API/Core/NoesisExtend.cs:4210)
Noesis.Extend.ProviderLoadXaml (IntPtr cPtr, System.String filename) (at Assets/NoesisGUI/Plugins/API/Core/NoesisExtend.cs:2598)
UnityEngine.Debug:LogException(Exception)
Noesis.Error:SetNativePendingError(Exception) (at Assets/NoesisGUI/Plugins/API/Core/NoesisError.cs:40)
Noesis.Extend:ProviderLoadXaml(IntPtr, String) (at Assets/NoesisGUI/Plugins/API/Core/NoesisExtend.cs:2605)
Noesis.GUI:Noesis_LoadComponent(HandleRef, String)
Noesis.GUI:Noesis_LoadComponent_(HandleRef, String) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:269)
Noesis.GUI:LoadComponent(Object, String) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:130)
Menu3D.MainMenu:InitializeComponent() (at Assets/MainMenu.xaml.cs:40)
Menu3D.MainMenu:.ctor() (at Assets/MainMenu.xaml.cs:24)
System.Runtime.CompilerServices.ExecutionScope:lambda_method(ExecutionScope)
Noesis.Extend:CreateInstance(IntPtr, IntPtr) (at Assets/NoesisGUI/Plugins/API/Core/NoesisExtend.cs:3866)
Noesis.GUI:Noesis_LoadComponent(HandleRef, String)
Noesis.GUI:Noesis_LoadComponent_(HandleRef, String) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:269)
Noesis.GUI:LoadComponent(Object, String) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:130)
Menu3D.MainWindow:InitializeComponent() (at Assets/MainWindow.xaml.cs:26)
Menu3D.MainWindow:.ctor() (at Assets/MainWindow.xaml.cs:20)
System.Runtime.CompilerServices.ExecutionScope:lambda_method(ExecutionScope)
Noesis.Extend:CreateInstance(IntPtr, IntPtr) (at Assets/NoesisGUI/Plugins/API/Core/NoesisExtend.cs:3866)
Noesis.GUI:Noesis_LoadXaml(String)
Noesis.GUI:Noesis_LoadXaml_(String) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:262)
Noesis.GUI:LoadXaml(String) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:120)
NoesisXaml:Load() (at Assets/NoesisGUI/Plugins/NoesisXaml.cs:31)
NoesisView:LoadXaml(Boolean) (at Assets/NoesisGUI/Plugins/NoesisView.cs:303)
NoesisView:OnEnable() (at Assets/NoesisGUI/Plugins/NoesisView.cs:365)

Unity 5.6.0f3
NoesisGUI-2.0.2f2

Edit:
I found the code below is not supported after switching from WPF to Unity
_start.InputBindings.Add(new KeyBinding(((MenuModel)this.DataContext).Start, Key.Enter, ModifierKeys.None));
I don't know why Noesis.KeyBinding's property Key and Modifiers is readonly, and can't set them from constructor?
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: KeyBinding is not supported in Unity?

23 Jun 2017, 18:32

Hi,

It is failing because we incorrectly implemented KeyBinding.Key and KeyBinding.Modifiers as read-only properties.
Please file a ticket in our bugtracker and we will fix it as soon as possible.

Meanwhile the workaround is using the Gesture property instead:
<UserControl.InputBindings>
    <KeyBinding Command="{Binding Start}" Gesture="A"></KeyBinding>
</UserControl.InputBindings>
_start.InputBindings.Add(new KeyBinding
{
  Command = ((MenuModel)this.DataContext).Start,
  Gesture = new KeyGesture(Key.A, ModifierKeys.None)
});

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 62 guests