-
-
Save InitoryDad/5174907 to your computer and use it in GitHub Desktop.
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; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment