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; | |
} | |
} | |
} | |
} |
Added runtime use description.
it can only find one display with an ipad 2 with ios 6.1.2, i tried with airserver and reflector on osx 10.8.2, both the same, just one display and just the main camera shows up, is there anything extra to set up?
This has been my experience as well, with an iPhone 5 and Apple TV or Airserver, or plugged directly in via lightening to HDMI. Display.displays.Length always returns 1. For now I print out Display.displays.Length to an NGUI label in my Update method, and I've checked to make sure it is actually updating. Unity just never detects the extra display. Am I missing something? And yes, I've enabled airplay mirroring and can see everything on both screens.
I'm trying to do this with my iPAD 2, mirroring is on. i have a debug string on the screen showing "Display.displays.Length" which always returns 1. any ideas why or what should i do?
Thanks for this example.
Do you know how to display a camera on both the device AND the external screen?
Thanks!
Thanks for this example. For those that have Display.displays.Length == 1, it's because AirPlay is only for Unity Pro.
I'm working on apple tv v3 and iPad mini retina, the mirroring doesn't work at full quality , it seem streamed to a lower quality, i added the Display.displays[1].SetRenderingResolution(1920,1080) to force the full resolution to the secondary display without success, any suggestion?
I am experiencing bad quality in dual display as well. Antialisasing seems to not be working on the second display. Tried on AirServer and AppleTV2. Was this something anyone else experiences?
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.
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
Initial version was using old API names. Sorry about that. Now updated.