Input
You will notice how each demo scene has it’s own input component. They all support both the Old and new Unity input system:
- Penguin Tracks - Rhythm Input Manager : This input component works triggering input events to the current “active” note of a track. Each track has a key assigned to it.
It is recommended to use 3D Touch Collider as it works both in perspective and orthogonal camera modes.
- OSU - OSU Rhythm Input Manager : This input component uses a single key (mouse0 by default) and triggers the input event on the note that is bellow the mouse cursor by using a raycast
- OpenXR_VR - VR Rhythm Input Manager : This component takes in a list of “VR Input Triggers” which detect when objects collide/trigger note colliders
All these Input Manager components transforms player input in an “InputEventData” which is sent to the RhythmProcessor
This means it is quite straight forward to replace those component for another one that uses the Input system you like. Simply call the Trigger Input function on the Rhythm Processor to process your input.
var inputEventData = new InputEventData();
inputEventData.Note = note;
inputEventData.InputID = inputID;
inputEventData.TrackID = trackID;
inputEventData.Direction = direction;
m_RhythmProcessor.TriggerInput(inputEventData)
You can inherit InputEventData with your own custom class and add more data to it.
public class YourInputEventData : InputEventData
{
public int extraData;
// Add more data you need
}
For example, the OSU and VR demos use their own custom input manager and inputEventData allowing you to pass in more relevant information about the input to the note. The note of course need to be custom to take the extra information and deal with it accordingly.
/// <summary>
/// An input was triggered on this note.
/// The input event data has the information about what type of input was triggered.
/// </summary>
/// <param name="inputEventData">The input event data.</param>
public override void OnTriggerInput(InputEventData inputEventData)
{
var yourInputEventData = inputEventData as YourInputEventData;
if (yourInputEventData == null) {
Debug.LogError("The input event used is not compatible with Your Notes");
return;
}
//Use your extra data here...
}