Repository navigation
Everyplay integration to Unity3d game
Everyplay is a tool that allows players of your game to easily record game replays, directly within your game, and share them with friends on the Everyplay network and to other social networks. This document shows you how to integrate the Everyplay recording to your Unity3D game.
To integrate Everyplay, you need to complete the following steps:
- Include the Everyplay Unity3D package in your Unity project
- Configure the required information (such as your game's client id and secret) to the Everyplay package
- Add hooks to the Everyplay package to start and stop the recording in the correct positions in your game
- Design and implement an integration point to your game to prompt users to share created videos
Note: While building for iOS works with Unity 3.5 and up, to build projects for Android with Everyplay, you need to have Unity 4.2 or newer, Unity 4.3 is recommended.
If you have not yet done so, download the Everyplay SDK. Depending on the platform you will be building for, you need different files.
If you are building for Android (or both platforms), start by downloading the Everyplay.unitypackage from:
https://github.com/Everyplay/everyplay-android-sdk
If you are also building for iOS, you need to grab the files from:
https://github.com/Everyplay/everyplay-ios-sdk
From this repository, you need:
- The Everyplay SDK .framework file
- The Everyplay SDK .bundle file
The last two files are required in the build process by Xcode. In normal circumstances it is sufficient that the files are located somewhere on your computer, but refer to the section "Project Build Issues" if you are unable to build your Unity3D project with Everyplay.
To use the Everyplay package, you must first import the package to your project. To accomplish this, do the following:
- Click on the "Assets" menu in the Unity3D menus
- Select "Import Package" > "Custom package…"
- Browse for the Everyplay Unity3D package, select it and click "Open"
- You are now presented with a dialog, titled "Importing Package" displaying the contents of the Unity package. Make sure all the files are selected, and click the "Import" button in the lower right hand corner of the dialog
Once you've imported the package, you can now use the Everyplay prefab in your project.
Once the Unity package has been successfully added to your project, you can find the Everyplay prefab in the Plugins/Everyplay folder in the Project window.
Drag the Everyplay prefab from the folder to the root of your Scene hierarchy.
There is no need to add the prefab to other scenes of your project, aside from the first one; the Everyplay prefab will automatically retain itself to any possible scenes in your project.
When the prefab has been added to the correct scene, you need to configure it. Click the prefab name (Everyplay) in the Hierarchy window to bring up the inspector for it. The inspector will allow you to configure the following values:
- Client Id - The Everyplay client ID you received from the Everyplay Admin when you registered your game
- Client Secret - The client secret for this game, also available from the Everyplay Admin
- Redirect URI - The OAuth2 redirect URI used to authenticate users to Everyplay inside your game. If are unsure of what to put in here, or are not using any API features of Everyplay, you can put in https://m.everyplay.com/auth
When the Everyplay prefab has been configured, you can now use it in your code to record your play sessions! How to accomplish this is described in the next section.
After you have added the prefab and configured it properly, you can quickly test Everyplay in your game and enable screen recording. To accomplish this, check the Everyplay test (script) section in the prefab inspector. This will automatically add buttons to your game to start and stop the recording of Everyplay, and review the latest recording.
When you have properly included and configured Everyplay, you can access the recording features in your C# scripts using the Everyplay.SharedInstance object. All control of the video recording is done using the methods this object provides. The methods provide the following functionalities: controlling (and monitoring) the recording of a game play session, displaying a previously recorded gameplay session, and interacting with the Everyplay service.
Everyplay also provides events that your code can receive about certain key actions in the code.
The gameplay recording starts with calling the method Everyplay.SharedInstance.StartRecording() and can be stopped with the method Everyplay.SharedInstance.EndRecording(). You can pause (and resume) the recording as well, or check if the recording is running or paused. You should use the Everyplay.SharedInstance.IsSupported() to verify that the current device supports Everyplay recording. All the methods are described below:
| Method | Description | Parameters | Return value(s) |
|---|---|---|---|
| StartRecording() | Starts the recording process in your game | None | None |
| StopRecording() | Stops the currently running session recording | None | None |
| PauseRecording() | Pauses the currently running recording session in your game | None | None |
| ResumeRecording() | Resumes a paused recording session in your game | None | None |
| TakeThumbnail() | Takes a thumbnail from the current frame. Thumbnail may be rendered to a texture or a file but only while recording | None | None |
| IsRecording() | Check whether Everyplay is currently recording | None |
bool - true if the current session is being recorded, false otherwise |
| IsPaused() | Check whether there is a recording process in Everyplay, that is currently in a paused state | None |
bool - true if there is a paused recording session, false otherwise |
| IsSupported() | Check if Everyplay is supported on the current device / iOS version. For iOS 4.3 and older, Everyplay is disabled so this could be used for hiding Everyplay specific UI functionality | None |
bool - true if Everyplay is supported on this device, false otherwise |
| IsRecordingSupported() | Check if the actual recording feature is supported on the current device / iOS version. The return value also takes into account if the user has called SetDisableSingleCoreDevices(true)
|
None |
bool - true if the recording is supported on this device, false otherwise |
| SetDisableSingleCoreDevices(bool) | Disables recording for single core devices. Depending on a game and the device, recording a gameplay may be too heavy on CPU/memory resources left |
bool - true if recording should be disabled on single core devices, false otherwise |
None |
| SetLowMemoryDevice(bool) | Optimize for low memory devices. Disabled by default |
bool - true if optimizations should be enabled on current device, false otherwise |
None |
| SetMaxRecordingMinutesLength(int) | Sets the maximum time for the recording | int - Maximum minutes to record | None |
Once a gameplay session has been recorded, you can instruct the Everyplay prefab to let the user share it with the Everyplay.SharedInstance.ShowSharingModal() method. For the purpose of showing a video thumbnail about the recording, you can get a video thumbnail by calling the Everyplay.SharedInstance.LoadThumbnailFromFilePath method. The methods are described below:
| Method | Description | Parameters | Return value(s) |
|---|---|---|---|
| ShowSharingModal() | Shows the Everyplay sharing modal for viral sharing of the previously recorded play session | None | None |
| PlayLastRecording() | Opens the video editor for playback of the previously recorded play session | None | None |
| LoadThumbnailFromFilePath(string, ThumbnailLoadReadyDelegate, ThumbnailLoadFailedDelegate) | Asynchronously loads a thumbnail to a Texture2D object from the given file path. The file path is accessible via the ThumbnailReadyAtFilePath event (more in "Receiving Events from Everyplay") |
string - The filepath where the thumbnail should be read from delegate - ThumbnailLoadReadyDelegate(Texture2D) delegate - ThumbnailLoadFailedDelegate(string) |
None |
Everyplay always creates one file based thumbnail from some random point of the video. Incase the user triggers the TakeThumbnail method before Everyplay has taken the shot the random shot will be cancelled.
To load a video thumbnail, you need to use the Everyplay.SharedInstance.LoadThumbnailFromFilePath(string path, ThumbnailLoadReadyDelegate, ThumbnailLoadFailedDelegate) method. The method works asynchronously, and takes the path as a string parameter, and two delegate functions as a that are invoked when the thumbnails are loaded.
The ThumbnailLoadReadyDelegate function takes a Texture2D object as a parameter, which provides the thumbnail from the video. In case of an error, the ThumbnailLoadFailedDelegate is called, and the error message is passed as a string. When you no longer need the texture you should release it with Destroy.
Example:
// The filepath we're getting from the thumbnail event
string thumbnailPath;
/* Delegate for event (see section on getting events) */
public void ThumbnailReadyAtFilePathDelegate(string filePath) {
this.thumbnailPath = filePath;
}
/* Define delegate methods */
// Success delegate
public void ThumbnailSuccess(Texture2D texture) {
// Yay, we have a video thumbnail, now we present it to the user
}
// Error delegate
public void ThumbnailError(string error) {
// Oh noes, something went wrong
Debug.Log("Thumbnail loading failed: " + error);
}
// Our own method that is used when the game is in a proper session to load and show the thumbnail
public void ShowThumbnailToTheUserInTheUI() {
// Load the thumbnail, using our delegates as parameter
Everyplay.SharedInstance.LoadThumbnailFromFilePath(this.thumbnailPath, ThumbnailSuccess, ThumbnailError);
}You may change the size of the file based thumbnail with SetThumbnailWidth method before you start the recording.
| Method | Description | Parameters | Return value(s) |
|---|---|---|---|
| SetThumbnailWidth(int) | Sets the file based thumbnail maximum side width | int - maximum side width of the texture | None |
Instead of using a file based target for the thumbnail you may render the thumbnail directly to an OpenGL texture. Using a texture is a lot better for performance and the thumbnail may be shown even during the recording without significant performance hit. When rendering the thumbnail to a texture Everyplay does not take any thumbnails automatically but you may request a thumbnail at any time during the recording by calling the TakeThumbnail method. To make the memory management a bit easier for games which support multiple orientations (landscape and portrait) the thumbnails are always rendered in landscape.
| Method | Description | Parameters | Return value(s) |
|---|---|---|---|
| SetThumbnailTargetTextureId(int) | Sets the thumbnail target texture | int - OpenGL texture handle id | None |
| SetThumbnailTargetTextureWidth(int) | Sets the target texture width | int - width of the texture | None |
| SetThumbnailTargetTextureHeight(int) | Sets the target texture width | int - height of the texture | None |
You could easily create an animated thumbnail from the recording by rendering thumbnails to multiple textures from selected highlight points (or random). To make this even easier Everyplay Unity package includes a couple of helper files to achieve this. See the following documentation for more information on this:
You can start the Everyplay service in your code by calling the Everyplay.SharedInstance.Show().
| Method | Description | Parameters | Return value(s) |
|---|---|---|---|
| Show() | Shows the Everyplay service. | None | None |
| ShowWithPath(string) | Shows the Everyplay service with a certain path. For now, the following paths are supported besides the default without parameters: /feed/game - Loads the latest feed of the current game |
string - The path key | None |
Everyplay provides the following events that your code can receive to be notified of key actions in the recording process. These are:
| Event | Required delegate | Description |
|---|---|---|
| RecordingStarted | RecordingStartedDelegate() | The RecordingStarted event is dispatched to any receiving delegates when the Everyplay recording service starts recording the gameplay |
| RecordingStopped | RecordingStoppedDelegate() | The RecordingStopped event is dispatched to any receiving delegates when the Everyplay recording service stops recording the gameplay |
| UploadDidStart | UploadDidStartDelegate(int videoId) | The UploadDidStart event is dispatched to any receiving delegates when an upload is started |
| UploadDidProgress | UploadDidProgressDelegate(int videoId, float progress) | The UploadDidProgress event is dispatched to any receiving delegates in regular intervals during the upload process |
| UploadDidComplete | UploadDidCompleteDelegate(int videoId) | The UploadDidComplete event is dispatched to any receiving delegates when an upload is completed |
| ThumbnailReadyAtFilePath | ThumbnailReadyAtFilePathDelegate(string filePath) | The ThumbnailReadyAtFilePath event is dispatched to any receiving delegates when the Everyplay recording has generated a video thumbnail to a file from the previous or current recording. Please note that this event may be dispatched while the recording is still running. It is recommended that your code not attempt thumbnail loading when a game session is still in progress, just store the given file path, as thumbnail loading may cause a performance hit in your game |
| ThumbnailReadyAtTextureId | ThumbnailReadyAtTextureIdDelegate(int textureId, bool portrait) | The ThumbnailReadyAtTextureId event is dispatched to any receiving delegates when the Everyplay recording has rendered a video thumbnail to a texture from the previous or current recording |
| WasClosed | WasClosedDelegate() | The WasClosed event is dispatched to any receiving delegates when the Everyplay service/videoeditor is closed |
Remember to remove your listeners when your objects are destroyed.
Example of using events:
/* Helper class for handling Everyplay */
public class MyEveryplayHelperClass : MonoBehaviour {
string thumbnailPath;
void Awake() {
/* Get events from Everyplay */
Everyplay.SharedInstance.RecordingStarted += RecordingStartedDelegate;
Everyplay.SharedInstance.RecordingStopped += RecordingStoppedDelegate;
Everyplay.SharedInstance.ThumbnailReadyAtFilePath += ThumbnailReadyAtFilePathDelegate;
}
void OnDestroy() {
/* Remove event receivers */
if (Everyplay.SharedInstance) { // might already be null if app is closing
Everyplay.SharedInstance.ThumbnailReadyAtFilePath -= ThumbnailReadyAtFilePathDelegate;
Everyplay.SharedInstance.RecordingStarted -= RecordingStartedDelegate;
Everyplay.SharedInstance.RecordingStopped -= RecordingStoppedDelegate;
}
}
public void RecordingStartedDelegate() {
Debug.Log("Recording was started");
/* The recording is now started, show the red "REC" in the upper hand corner */
MyGameEngine.ShowRecordingIndicator();
}
public void RecordingStoppedDelegate() {
Debug.Log("Recording ended");
/* Remove visual indicator from the user */
MyGameEngine.RemoveRecordingIndicator();
}
public void ThumbnailReadyAtFilePathDelegate(string path) {
Debug.Log("Thumbnail ready: " path);
this.thumbnailPath = path;
}
}You can also add metadata to uploaded videos that can provide additional information about the video, such as the score the user achieved, the level they were playing, etc. The metadata is set using the Everyplay.SharedInstance.SetMetadata() method. You can call it while or after the recording (affects the last known session).
| Method | Description | Parameters | Return value(s) |
|---|---|---|---|
| SetMetadata(string,object) | Adds a single metadata item to the video with the given key, and the given value |
string - The metadata key object - The metadata value |
None |
| SetMetadata(Dictionary<string,object> values) | Add multiple metadata values from the provided Dictionary | Dictionary<string,object> - The key-value pairs of metadata to add to this video | None |
Example of adding metadata
Everyplay.SharedInstance.SetMetadata("level", levelNumber);
Everyplay.SharedInstance.SetMetadata("level_name", levelName);
Everyplay.SharedInstance.SetMetadata("score", score)-
Add a new layer for the HUD game objects, call it EveryplayHudCamera for example
-
Remove EveryplayHudCamera layer from your Main Camera's culling mask. Do the same for other cameras you might have
-
Drag the EveryplayHudCamera prefab to the root of your hierarchy (position 0, 0, 0, rotation 0, 0, 0)
-
Set layer to EveryplayHudCamera on game objects you wish not to be recorded on video
-
You are done! :)
Note When building a project with Everyplay for the first time, make sure to do a clean build by selecting File > Build Settings > Build and Run.
Note When building for Android and running Unity 4.2, you need to disable Version Control support during the build process. You can do this via Edit > Project Settings -> Editor.
In most cases, building your Unity3D project with Everyplay enabled for iOS should succeed without any configuration changes necessary to your Xcode project. In some cases, however, some manual configuration may be required. These can be caused by:
- Multiple version of the Everyplay SDK on your computer
- Spotlight being disabled on your computer
There are a few alternatives to correcting the build process problems caused by Everyplay:
-
If your computer has Spotlight disabled, the easiest way is to enable Spotlight
-
If you have multiple versions of the Everyplay SDK on your computer, you can create an empty file named
ACTIVE_EVERYPLAY_SDK_DIRin the directory of the desired Everyplay SDK version that contains the .framework and .bundle files. -
If you don't have Spotlight, and don't want to enable it, you can create a symbolic link called
.active_everyplay_sdk_dirthat points to the directory that contains the .framework and .bundle files. The symlink should reside in your home directory. Example of creating a symlink:ln -sf /home/dev/downloads/everyplay-ios-sdk-1.x/ ~/.active_everyplay_sdk_dir -
Instead of relying to Spotlight or use of symlinks, you can also add Everyplay.framework and Everyplay.bundle into your Unity project directory, optimal case being outside the Assets directory
Should build errors related to Everyplay still persist, you can contact us directly via email (support@everyplay.com) or use Github Issues at https://github.com/Everyplay/everyplay-ios-sdk/issues, thanks!
Everyplay SDK supports Japanese and Korean in addition to English. For you to see these languages in Everyplay, please follow the below steps.
-
After the integration of
Everyplay.unitypackage, export your unity project to an iOS project. -
Under the iOS project root directory, create directories and files as follows.
mkdir {en,ja,ko}.lproj touch {en,ja,ko}.lproj/Localizable.strings -
In Xcode, add all the Localizable.strings files to your project to enable the Japanese and Korean languages (Right click the project and select "Add Files to YOUR_PROJECT").
- Live FaceCam integration to Unity3d game (currently supported for iOS)







