InControl: Daikon Forge
It is possible to get InControl to feed input to the Daikon Forge GUI system by simulating keyboard events. The script below should get you started. Attach it to the root UI object (the one that has dfInputManager
attached) and make sure you have “Use Joystick” turned off on dfInputManager
.
using UnityEngine;
using System.Collections;
using InControl;
public class InControlInputAdapter : MonoBehaviour
{
void OnEnable()
{
TwoAxisInputControl.StateThreshold = 0.5f;
}
void Update()
{
var target = dfGUIManager.ActiveControl;
if (target == null || !target.transform.IsChildOf( this.transform ))
{
return;
}
var inputDevice = InputManager.ActiveDevice;
HandleControl( inputDevice.Direction.Up, target, KeyCode.UpArrow );
HandleControl( inputDevice.Direction.Down, target, KeyCode.DownArrow );
HandleControl( inputDevice.Direction.Left, target, KeyCode.LeftArrow );
HandleControl( inputDevice.Direction.Right, target, KeyCode.RightArrow );
HandleControl( inputDevice.Action1, target, KeyCode.Return );
HandleControl( inputDevice.Action2, target, KeyCode.Escape );
}
static void HandleControl( OneAxisInputControl control, dfControl target, KeyCode keyCode )
{
if (control.WasPressed)
{
target.OnKeyDown( new dfKeyEventArgs( target, keyCode, false, false, false ) );
}
else
if (control.WasReleased)
{
target.OnKeyUp( new dfKeyEventArgs( target, keyCode, false, false, false ) );
}
}
static void HandleControl( InputControl control, dfControl target, KeyCode keyCode )
{
if (control.WasPressed)
{
target.OnKeyDown( new dfKeyEventArgs( target, keyCode, false, false, false ) );
}
else
if (control.WasReleased)
{
target.OnKeyUp( new dfKeyEventArgs( target, keyCode, false, false, false ) );
}
}
}