Skip to content

Instantly share code, notes, and snippets.

@drawcode
Forked from AngryAnt/DualDisplay.cs
Created March 14, 2013 22:41
Show Gist options
  • Save drawcode/5165889 to your computer and use it in GitHub Desktop.
Save drawcode/5165889 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
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