Gamepad Support?
I'm considering buying NoesisGUI from the asset store for my game which currently uses inControl for gamepad input, how does NoesisGUI handle gamepad input in Unity? Can I have a C# script in Unity hooked up to the NoesisGUI that handles input?
-
-
sfernandez
Site Admin
- Posts: 3240
- Joined:
Re: Gamepad Support?
We want to provide better input integration in NoesisGUI in a following release, by addding the possibility to inject input events directly into the NoesisGUIPanel component.
While this is publicly released, you can patch our scripts like this:
Assets/Plugins/NoesisGUI/Scripts/NoesisGUIPanel.cs
Assets/Plugins/NoesisGUI/Scripts/Core/NoesisUIRenderer.cs
You can simulate a mouse pointer with the axis info of your gamepad. Or maybe you will prefer to simulate Tab, Shift+Tab, and Arrow keys to manage Keyboard focus.
While this is publicly released, you can patch our scripts like this:
Assets/Plugins/NoesisGUI/Scripts/NoesisGUIPanel.cs
Code: Select all
using UnityEngine;
using Noesis;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
[AddComponentMenu("NoesisGUI/NoesisGUI Panel")]
public class NoesisGUIPanel : MonoBehaviour
{
// ...
////////////////////////////////////////////////////////////////////////////////////////////////
private Noesis.UIRenderer _uiRenderer;
////////////////////////////////////////////////////////////////////////////////////////////////
public T GetRoot<T>() where T : BaseComponent
{
if (_uiRenderer != null)
{
return _uiRenderer.GetRoot<T>();
}
else
{
return null;
}
}
// ADD THE FOLLOWING FUNCTIONS FOR INPUT HANDLING
//@{
////////////////////////////////////////////////////////////////////////////////////////////////
public void KeyDown(Noesis.Key key)
{
if (_uiRenderer != null)
{
_uiRenderer.KeyDown(key);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
public void KeyUp(Noesis.Key key)
{
if (_uiRenderer != null)
{
_uiRenderer.KeyUp(key);
}
}
/////////////////////////////////////////////////////////////////////////////////
public void MouseDown(float x, float y, Noesis.MouseButton button)
{
if (_uiRenderer != null)
{
_uiRenderer.MouseDown(x, y, button);
}
}
/////////////////////////////////////////////////////////////////////////////////
public void MouseUp(float x, float y, Noesis.MouseButton button)
{
if (_uiRenderer != null)
{
_uiRenderer.MouseUp(x, y, button);
}
}
/////////////////////////////////////////////////////////////////////////////////
public void MouseDoubleClick(float x, float y, Noesis.MouseButton button)
{
if (_uiRenderer != null)
{
_uiRenderer.MouseDoubleClick(x, y, button);
}
}
/////////////////////////////////////////////////////////////////////////////////
public void MouseWheel(float x, float y, int wheelRotation)
{
if (_uiRenderer != null)
{
_uiRenderer.MouseWheel(x, y, wheelRotation);
}
}
/////////////////////////////////////////////////////////////////////////////////
public void MouseMove(float x, float y)
{
if (_uiRenderer != null)
{
_uiRenderer.MouseMove(x, y);
}
}
//@}
// ...
}
Code: Select all
using UnityEngine;
using System;
using System.Runtime.InteropServices;
namespace Noesis
{
// ...
/////////////////////////////////////////////////////////////////////////////////////
/// Manages updates, render and input events of a Noesis UI panel
/////////////////////////////////////////////////////////////////////////////////////
internal partial class UIRenderer
{
// ...
/////////////////////////////////////////////////////////////////////////////////
public T GetRoot<T>() where T : BaseComponent
{
return _root.As<T>();
}
// ADD THE FOLLOWING FUNCTIONS FOR INPUT HANDLING
//@{
/////////////////////////////////////////////////////////////////////////////////
public void KeyDown(Noesis.Key key)
{
Noesis_KeyDown(_rendererId, (int)key);
}
/////////////////////////////////////////////////////////////////////////////////
public void KeyUp(Noesis.Key key)
{
Noesis_KeyUp(_rendererId, (int)key);
}
/////////////////////////////////////////////////////////////////////////////////
public void MouseDown(float x, float y, Noesis.MouseButton button)
{
Noesis_MouseButtonDown(_rendererId, x, y, (int)button);
}
/////////////////////////////////////////////////////////////////////////////////
public void MouseUp(float x, float y, Noesis.MouseButton button)
{
Noesis_MouseButtonUp(_rendererId, x, y, (int)button);
}
/////////////////////////////////////////////////////////////////////////////////
public void MouseDoubleClick(float x, float y, Noesis.MouseButton button)
{
Noesis_MouseDoubleClick(_rendererId, x, y, (int)button);
}
/////////////////////////////////////////////////////////////////////////////////
public void MouseWheel(float x, float y, int wheelRotation)
{
Noesis_MouseWheel(_rendererId, x, y, wheelRotation);
}
/////////////////////////////////////////////////////////////////////////////////
public void MouseMove(float x, float y)
{
Noesis_MouseMove(_rendererId, x, y);
}
//@}
// ...
}
}
Re: Gamepad Support?
Let me clarify how to use this. NoesisGUI only understands the events that are listed in the file Assets\Plugins\NoesisGUI\Scripts\Core\InputEnums.cs. With the patch given by Sergio we have exposed a way to manually inject key codes.
For example, to translate from InControl you would have to do something like this (pseudocode):
This way, you are translating the event Direction.Left from InControl to Noesis. The same for the rest of events.
For example, to translate from InControl you would have to do something like this (pseudocode):
Code: Select all
if (InputManager.ActiveDevice.Direction.Left.IsPressed)
{
noesisGUIPanel.KeyDown(Noesis.Key.Left);
}
else if (InputManager.ActiveDevice.Direction.Left.WasReleased)
{
noesisGUIPanel.KeyUp(Noesis.Key.Left);
}
Re: Gamepad Support?
I'm still not sure exactly where the code should be added? I followed the tutorial where a script was created in the camera to attach a button.click event, is this where
should be added? I am trying to setup a horizontal stack panel that can be navigated left and right.
Code: Select all
if (InputManager.ActiveDevice.Direction.Left.IsPressed)
{
noesisGUIPanel.KeyDown(Noesis.Key.Left);
}
else if (InputManager.ActiveDevice.Direction.Left.WasReleased)
{
noesisGUIPanel.KeyUp(Noesis.Key.Left);
}
Re: Gamepad Support?
Yes, you can do it from a script:
Code: Select all
using UnityEngine;
using Noesis;
public class Test: MonoBehaviour
{
void Start()
{
// Access to the NoesisGUI component
NoesisGUIPanel noesisGUI = GetComponent<NoesisGUIPanel>();
// This simulates a press of the left key
noesisGUI.KeyDown(Noesis.Key.Left);
noesisGUI.KeyUp(Noesis.Key.Left);
}
}
Re: Gamepad Support?
It says noesisGuiPanel does not exist? Not sure what to do since I added the Noesis namespace.
http://media-cache-ec0.pinimg.com/origi ... 8b3171.jpg
http://media-cache-ec0.pinimg.com/origi ... 8b3171.jpg
Re: Gamepad Support?
Sorry, my code was not correct. I have fixed it.
Re: Gamepad Support?
That worked, but it seems the patch to inject key codes manually does not seem to be working as Noesis.UIRenderer is not recognizing KeyDown?
http://media-cache-ec0.pinimg.com/origi ... 5322dd.jpg
http://media-cache-ak0.pinimg.com/origi ... bf4ff2.jpg
It is also unable to add the noesisguipanel script to the camera:
http://media-cache-ec0.pinimg.com/origi ... da47ae.jpg
P.S. I sent you a message on Unity forum that may be more help with getting this setup
http://media-cache-ec0.pinimg.com/origi ... 5322dd.jpg
http://media-cache-ak0.pinimg.com/origi ... bf4ff2.jpg
It is also unable to add the noesisguipanel script to the camera:
http://media-cache-ec0.pinimg.com/origi ... da47ae.jpg
P.S. I sent you a message on Unity forum that may be more help with getting this setup

Re: Gamepad Support?
Ok, I did the following. First, you need to apply the patches commented above. They will be included in the next version of noesisGUI. You can download the patches from here:
Then I created a simple navigation script:
I have tested it with a XBOX360 controller and it is working fine. I can select the desired button with the left stick or DPad and click each element with the A button.
You can download this sample scene here: https://drive.google.com/file/d/0Bwxw0R ... sp=sharing
- NoesisGUIPanel.cs (https://drive.google.com/file/d/0Bwxw0R ... sp=sharing)
- NoesisGUIRenderer.cs (https://drive.google.com/file/d/0Bwxw0R ... sp=sharing)
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" KeyboardNavigation.DirectionalNavigation="Cycle">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Button Content="Button" Padding="20" FontSize="20" Grid.Row="0" Grid.Column="0" />
<Button Content="Button" Padding="20" FontSize="20" Grid.Row="0" Grid.Column="1" />
<Button Content="Button" Padding="20" FontSize="20" Grid.Row="0" Grid.Column="2" />
<Button Content="Button" Padding="20" FontSize="20" Grid.Row="1" Grid.Column="0" />
<Button Content="Button" x:Name="start" Padding="20" FontSize="20" Grid.Row="1" Grid.Column="1" />
<Button Content="Button" Padding="20" FontSize="20" Grid.Row="1" Grid.Column="2" />
<Button Content="Button" Padding="20" FontSize="20" Grid.Row="2" Grid.Column="0" />
<Button Content="Button" Padding="20" FontSize="20" Grid.Row="2" Grid.Column="1" />
<Button Content="Button" Padding="20" FontSize="20" Grid.Row="2" Grid.Column="2" />
</Grid>
</Grid>
Code: Select all
using System;
using UnityEngine;
using InControl;
using Noesis;
namespace BasicExample
{
public class Controller : MonoBehaviour
{
NoesisGUIPanel noesisGUI_;
void Start()
{
noesisGUI_ = GetComponent<NoesisGUIPanel>();
var root = noesisGUI_.GetRoot<Grid>();
var start = root.FindName<Button>("start");
start.Focus();
}
private void Handle(OneAxisInputControl input, Noesis.Key key)
{
if (input.WasPressed)
{
noesisGUI_.KeyDown(key);
}
if (input.WasReleased)
{
noesisGUI_.KeyUp(key);
}
}
private void Handle(InputControl input, Noesis.Key key)
{
if (input.WasPressed)
{
noesisGUI_.KeyDown(key);
}
if (input.WasReleased)
{
noesisGUI_.KeyUp(key);
}
}
void Update()
{
// Use last device which provided input.
var inputDevice = InputManager.ActiveDevice;
Handle(inputDevice.Direction.Left, Key.Left);
Handle(inputDevice.Direction.Right, Key.Right);
Handle(inputDevice.Direction.Up, Key.Up);
Handle(inputDevice.Direction.Down, Key.Down);
Handle(inputDevice.Action1, Key.Space);
}
}
}
You can download this sample scene here: https://drive.google.com/file/d/0Bwxw0R ... sp=sharing
Re: Gamepad Support?
Works Great Now! Thank You!
Though I have a question about the xaml grid, how is it that only one of the buttons has X:Name="start"?

Though I have a question about the xaml grid, how is it that only one of the buttons has X:Name="start"?
Who is online
Users browsing this forum: Ahrefs [Bot] and 39 guests