InControl: Noesis GUI
The integration of InControl and NoesisGUI can be done by manually injecting events in the NoesisGUI component. For example, given the following set of buttons:
<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>
You can control the navigation using InControl with this script:
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 );
}
}
}