Skip to content

Instantly share code, notes, and snippets.

@AngryAnt
Last active January 24, 2024 08:26
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save AngryAnt/5160204 to your computer and use it in GitHub Desktop.
Save AngryAnt/5160204 to your computer and use it in GitHub Desktop.
Example use of the Unity 4.1 AirPlay API - gives a setup with the iOS device as controller of the remote display.
using UnityEngine;
using System.Collections;
/*
Runtime use:
To be available, AirPlay needs to be switched on for the device either via a native AirPlay UI component or
via the global AirPlay mirroring setting. Your options are:
A: Modify your Xcode project to layer a native AirPlay Cocoa control somewhere over your Unity content.
B: Enable global AirPlay mirroring on the device.
- You will find this next to the global volume control - available when you slide the multi-task bar
(accessible from double-home-button-click) to the right.
- If AirPlay receivers are available on the network, you should see an AirPlay button next to the volume
control.
- Tapping it pops a target selector up and with a display capable target selected, toggle on "mirroring".
- Returning to your application, AirPlay should now be available.
Though it is a more cumbersome user experience, I would recommend going with option B as long as it makes
sense, with an in-game description - to keep app simplicity.
If you want to test AirPlay, but do not have an AppleTV, I have successfully used AirServer for testing:
http://www.airserverapp.com
*/
namespace UnityAssets
{
public class DualDisplay : MonoBehaviour
{
public Camera mainCamera, controlsCamera;
public bool autoEnable = true;
public bool Available
{
get
{
return enabled && Display.displays.Length > 1;
}
}
public bool Active
{
get
{
return enabled && controlsCamera.enabled;
}
set
{
if (!value || !Available)
{
controlsCamera.enabled = false;
controlsCamera.SetTargetBuffers (Display.main.colorBuffer, Display.main.depthBuffer);
mainCamera.SetTargetBuffers (Display.main.colorBuffer, Display.main.depthBuffer);
}
else
{
Display secondDisplay = Display.displays[1];
mainCamera.SetTargetBuffers (secondDisplay.colorBuffer, secondDisplay.depthBuffer);
controlsCamera.SetTargetBuffers (Display.main.colorBuffer, Display.main.depthBuffer);
controlsCamera.enabled = true;
}
}
}
void Reset ()
{
mainCamera = Camera.main;
}
void Start ()
{
if (mainCamera == null || controlsCamera == null)
{
Debug.LogError ("DualDisplay missing a camera reference");
Destroy (this);
return;
}
controlsCamera.enabled = false;
}
void Update()
{
if (Available)
{
if (autoEnable)
{
Active = true;
}
}
else
{
Active = false;
}
}
}
}
@zcwaa22
Copy link

zcwaa22 commented Oct 13, 2018

Has anyone managed to get this working with Image Effects on the Airplay screen, they refuse to work for me on Unity 2018.2.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment