1

For years, Apple has offered the ability to display different content on a connected screen than the content on the iOS device that's driving it.

Is there a way to use this functionality with an app built in Unity? i.e., the iPad would display one camera view, and a TV connected over HDMI via the USB-C connector would display a different camera view?

The Apple documentation article is here, and a nice walkthrough is here.

This article explains how to send messages between Unity and Swift, but it seems rather limited in scope.

j0hnm4r5
  • 407
  • 3
  • 17
  • Support for a second screen has existed for many years. See [Display one thing on iPad and another on Apple Tv](https://stackoverflow.com/questions/17603611/display-one-thing-on-ipad-and-another-on-apple-tv) (the answer uses Objective-C code but it's the same APIs in Swift). There's nothing special about supporting it on the iPad Pro. – rmaddy May 08 '19 at 18:33
  • Maybe like this https://docs.unity3d.com/Manual/MultiDisplay.html? – derHugo May 08 '19 at 18:52

1 Answers1

1

Unfortunately, the normal Unity MultiDisplay workflow isn't supported by iOS, so the solution is a little trickier:

using UnityEngine;
using System.Collections;

public class MultiScreen : MonoBehaviour
{

    // set the two cameras via the inspector
    public Camera primaryCam;
    public Camera secondaryCam;

    void Start()
    {
        // render the primary camera to the main display
        primaryCam.SetTargetBuffers(Display.main.colorBuffer, Display.main.depthBuffer);

        secondaryCam.depth = primaryCam.depth - 1;
        secondaryCam.enabled = false;
    }

    void Update()
    {
        // only render the second display if it is attached
        if (Display.displays.Length > 1 && !secondaryCam.enabled)
        {
            // set the second display's resolution
            Display.displays[1].SetRenderingResolution(Display.displays[1].systemWidth, Display.displays[1].systemHeight);

            // render the secondary camera to the second display
            secondaryCam.SetTargetBuffers(Display.displays[1].colorBuffer, Display.displays[1].depthBuffer);
        }

        // activate the second camera and render pipeline if a second display is connected
        secondaryCam.enabled = Display.displays.Length > 1;
    }

}

Additionally, I had to make sure Auto Graphics API was deactivated in Project Settings > Player > Other Settings > Rendering, and that Metal was removed from the following list. Setting the Company Name, Product Name, and Bundle Identifier may have also helped.

j0hnm4r5
  • 407
  • 3
  • 17