Last active
January 24, 2024 08:26
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} | |
} |
Hallo,
i would like to send or mirror via HDMI but in full hd without black boarders on the sides. i want to display a vuforia AR app on a large tv.
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
Hi Guys I have tried it for a protrait game with AirServer Trial version and iPod 5th Gen, this script work perfect. but I notice main camera should behave like landscape game in AirServer (MAC). any guess about that...? I cant find any property about rstrict aspect of Main Cam which show on Air Server (second display or so on...)
I also have some confusiona about this line....
A: Modify your Xcode project to layer a native AirPlay Cocoa control somewhere over your Unity content.