ReplayKit is only available on iPhone/iPad/iPod Touch running iOS 9.0 or later.
ReplayKit allows you to record the audio and video of your game, along with user commentary through the microphone. You start a recording with the StartRecording() method, and stop it with StopRecording(). You can preview the recording with the Preview() method, which launches a separate video viewer.
#pragma strict using UnityEngine.iOS; using UnityEngine.Apple.ReplayKit;
public class Replay : MonoBehaviour { string lastError = ""; void OnGUI() { if (!ReplayKit.APIAvailable) { return; } var recording = ReplayKit.isRecording; string caption = recording ? "Stop Recording" : "Start Recording"; if (GUI.Button(new Rect(10, 10, 500, 200), caption)) { try { recording = !recording; if (recording) { ReplayKit.StartRecording(); } else { ReplayKit.StopRecording(); } } catch (Exception e) { lastError = e.ToString(); } }
GUI.Label(new Rect(10, 220, 500, 50), "Last error: " + ReplayKit.lastError); GUI.Label(new Rect(10, 280, 500, 50), "Last exception: " + lastError);
if (ReplayKit.recordingAvailable) { if (GUI.Button(new Rect(10, 350, 500, 200), "Preview")) { ReplayKit.Preview(); } if (GUI.Button(new Rect(10, 560, 500, 200), "Discard")) { ReplayKit.Discard(); } } } }
using System; using UnityEngine; #if UNITY_IOS using UnityEngine.iOS; using UnityEngine.Apple.ReplayKit;
public class Replay : MonoBehaviour { string lastError = ""; void OnGUI() { if (!ReplayKit.APIAvailable) { return; } var recording = ReplayKit.isRecording; string caption = recording ? "Stop Recording" : "Start Recording"; if (GUI.Button(new Rect(10, 10, 500, 200), caption)) { try { recording = !recording; if (recording) { ReplayKit.StartRecording(); } else { ReplayKit.StopRecording(); } } catch (Exception e) { lastError = e.ToString(); } }
GUI.Label(new Rect(10, 220, 500, 50), "Last error: " + ReplayKit.lastError); GUI.Label(new Rect(10, 280, 500, 50), "Last exception: " + lastError);
if (ReplayKit.recordingAvailable) { if (GUI.Button(new Rect(10, 350, 500, 200), "Preview")) { ReplayKit.Preview(); } if (GUI.Button(new Rect(10, 560, 500, 200), "Discard")) { ReplayKit.Discard(); } } } } #endif
APIAvailable | A boolean that indicates whether the ReplayKit API is available (where True means available). (Read Only) |
isRecording | A boolean that indicates whether ReplayKit is making a recording (where True means a recording is in progress). (Read Only) |
lastError | A string value of the last error incurred by the ReplayKit: Either 'Failed to get Screen Recorder' or 'No recording available'. (Read Only) |
recordingAvailable | A boolean value that indicates that a new recording is available for preview (where True means available). (Read Only) |
Discard | Discard the current recording. |
Preview | Preview the current recording |
StartRecording | Start a new recording. |
StopRecording | Stop the current recording. |