tvOS Input Code?

I just updated to 5.3.1f1 Personal, and there is a tvOS Build option. However, I cannot find a Unity TVOS Documentation online on how to access the tvOS Remote’s touchpad and take it as an input. Like, for example,:

if(input.GetTouchscreen.Rightside) { //if the right side of the touchscreen of the tvos remote is touched     BallTurnsRight();
}

How do I do this?

I’d also like more support on this, as in, Documentation please! :slight_smile:

I know right!

I’d recommend a few things:

Use the ‘InControl’ plugin - it has configurations for the apple tv remote

You can query the raw position of the touchscreen using this (without the plugin):

UnityEngine.Apple.TV.Remote.reportAbsoluteDpadValues = true;

float m_PadLR = Input.GetAxisRaw("Horizontal");
float m_PadUD = Input.GetAxisRaw("Vertical");

This gives you values from -1 to +1 which maps across the touchscreen.

InControl lets you query button presses too, for example:

InputDevice CurDevice = InputManager.ActiveDevice;
float PlayPauseButton = CurDevice.GetControl( InControl.InputControlType.Action3 ).Value
float TouchScreenButton = CurDevice.GetControl( InControl.InputControlType.Action1 ).Value
float MenuBackButton = CurDevice.GetControl( InControl.InputControlType.Pause ).Value

You can do it without the plugin too, Action3 is Unity Button 15, Action 1 is Unity Button 14 and Pause is Unity Button 0

If you want to you can also use Input.touches like you would on iOS but it works differently. When you put your finger down that point becomes 0,0 and everything is relative to it which makes life more difficult. It also returns values in screen resolution rather than a normalised viewport.

Wow thanks! So could I do:

If(Input.GetAxisRaw("Horizontal")) > 0) {
//Go to the right
}
If(Input.GetAxisRaw("Horizontal")) < 0) {
//Go to the left
}

Also, is the InControl Plugin on the Unity Asset Store?

Rewired also supports the Apple TV Siri remote. It allows you to get the touchpad as a joystick and also allows you to map tilt and rotation to Actions. It also supports all MFI game controllers on tvOS and makes handling multiple players easy. You can try a free demo of Rewired and see if it works for you.

@ExbowFTW - your code looks fine to me, that should work ok. InControl is on the asset store as far as I remember, there’s also an older GitHub version but I don’t think it has the up to date profiles for all controllers (and apple tv)

O

Ok thanks.

Thanks. Once the trial runs out, does it no longer work?

The trial never runs out. The only limitation is a 2-minute time limit per-play session. Once you press stop in the editor and Play again, you have 2 more minutes.

Note: The download link to the trial is currently down because of unexpected server modifications by my webhost that I cannot fix. I’ve contacted support to get this resolved.

Okay, thanks for your help!

Sorry for being late to this thread. Rewired and Incontrol are both great options and if you are already using one I’m sure you are happy.

Since you originally asked about the “sides” of the controller @tonemcbride responses for the native Unity way of doing things without a plugin is also correct. You could set any threshold you wanted for “left/right/up/down side” like less than -.75 or greater than .75 if you only wanted it to be the edges.

There is one additional asset in my signature below called Easy Input Helper that might also be able to help. It’s specific to the Apple TV not general purpose like Rewired and Incontrol so if you are cross platform this might be a hindrance. However, if you are making a Apple TV specific title it will help with some of the common things with no coding required. Things like if you wanted a touch dpad or joystick, wanted a marble type game with the accelerometer, wanted first person controls with the siri remote with the touchpad and gyro, Unity GUI menu swipe navigation, etc. It essentially if you are targeting Apple TV only has coded most of the common things for you already so all you have to do is change a few sliders in the inspector for dead zones, swipe length, etc. and it will work. Naturally, if you want to do something custom you can use our API to extend functionality with coding, but many tasks are already done for you.

I couldn’t get a value different than 0 in

print(Input.GetAxisRaw("Vertical").ToString());

What am I doing wrong? I am sure touch is read, I press alt button when I move my mouse in simulator and touchCount is 1.

Also,

  if(Input.GetKeyDown(KeyCode.JoystickButton14))
{
SceneManager.LoadScene("Menu");
}

doesn’t work, neither.

When you aren’t using any plugins and are just using regular Unity Input you need to make sure to have the following line appear before your call to getaxis or getaxisraw if you want it to behave like a joystick and not be swipe based (default is swipe based so just touching won’t change from 0 only dragging will).

UnityEngine.Apple.TV.Remote.reportAbsoluteDpadValues = true;

As far as the button press goes that code should work. Where are you executing this, on a physical device? If by any chance you are using the simulator unity doesn’t support the Siri Remote in editor or the simulator.

Ah, I see. Yes, I was working on simulator. Thank you for the answer.

What is the “PAUSE/PLAY” Button on the tvOS in Unity?

@Gord10 @greggtwep16 @guavaman @tonemcbride @Mikea15

Button 15

Oh dang that was fast :wink:

Is there a Apple tvOS - Unity Documentation where you get this information?
Also, how would I code it? Just:

if(getbuttondown(Button15)) {
//PAUSE THE GAME
}

?

THANKS

Also, without using any special unity plugins, does Input.Acceleration work on the tvOS Remote (like, is there a gyrometer on it) ?

Some of it comes from the beta group. I don’t see where they have published any docs on AppleTV. Here are some docs on input in iOS.

No. This follows all the standard rules for using UnityEngine.Input. Documentation.

Assuming the Siri Remote is assigned to be Joystick 1 by Unity:

if(Input.GetButtonDown(KeyCode.Joystick1Button15)) {
    // Pause the game
}