Forgot password?
EasyAR Portal Tutorial View Content

EasyAR Beginners Guide(5)---Screen-Recording

AlbertLee 2017-9-7 14:15


Screen recording is essential for AR App. Indeed, we can record mobile phone’s current operation and see some intriguing pictures through screen recording (especially for AR). There are many collective projects for screen recoding in the market but EasyAR SDK2.0 is the best choice for AR development. SDK 2.O Pro harnesses screen-recording without writing script.

Development Preview:

1.Click on button and start will pop up (Start is only the text hint for users and it will disappear 2 secs later)

2.Drag the object which has been recognized (Rotate or zoo it, the previous course: EasyAR Developing Skills---Model Interactive Operation), mainly to display screen-recording effect.

3.Click on button and here is saved path for the video

The recorded video will be saved in/sdcard/Movies.Like that:

4.The most significant advantage of EasyAR SDK is that it will not record UI in screen-recording.

Developing Materials:

Button(commercial use is prohibited)Link: Password: 4qbs

Step 1:Prepare

We download samples of EasyAR 2.0 Pro in official website.

Ps: Our development will be in the basis of official sample, which can improve efficiency.

Open "HelloARRecording" in Unity after it is unzipped

Open "HelloARRecording" in Unity. Fill in Key first. Apply Key from the official website (You need to use Pro version)

We can pack all files into APK and see its effect in mobile device (Now screen-recording can be tested only in mobile device not PC)

Step2:Add Interaction for Models

We need to add gesture interaction for model. So it is intriguing in screen-recording. There are two image targets in default scene and we only choose one for testing.

Add script: This is the script for gesture interaction in mobile device. We talked about in the previous tutorial (EasyAR Developing Skills---Model Interactive Operation). You can use it as template and modify some variables to achieve desired effect.

Address for downloading scriptLink:  Password: 4g2n

using UnityEngine;

using System.Collections;

public class Gesture : MonoBehaviour {

    private Touch oldTouch1;  

    private Touch oldTouch2;  

    void Update()
        if (Input.touchCount <= 0)
        if (1 == Input.touchCount)
            Touch touch = Input.GetTouch(0);
            Vector2 deltaPos = touch.deltaPosition;
            transform.Rotate(Vector3.down * deltaPos.x, Space.World);
        Touch newTouch1 = Input.GetTouch(0);

        Touch newTouch2 = Input.GetTouch(1);

        if (newTouch2.phase == TouchPhase.Began)

            oldTouch2 = newTouch2;

            oldTouch1 = newTouch1;

        float oldDistance = Vector2.Distance(oldTouch1.position, oldTouch2.position);

        float newDistance = Vector2.Distance(newTouch1.position, newTouch2.position);

        float offset = newDistance - oldDistance;

        float scaleFactor = offset / 200f;

        Vector3 localScale = transform.localScale;

        Vector3 scale = new Vector3(localScale.x + scaleFactor,

            localScale.y + scaleFactor,

            localScale.z + scaleFactor);

        if (scale.x >= 0.05f && scale.y >=0.05f && scale.z >= 0.05f)
            transform.localScale = scale;
        oldTouch1 = newTouch1;
        oldTouch2 = newTouch2;



Put the script on the model

Step 3:UI

Analyze the script and component relating to screen-recording.

1.1. Script on "EasyAR_Startup"----"HelloARRecording.cs"  is the major script file that achieves screen-recording. Here are two important methods---StartRecord(),StopRecord(), control start and end of screen-recording respectively.


   public void StartRecord()
            string path_root = Application.persistentDataPath + "/";
            if (Application.platform == RuntimePlatform.Android)
                path_root = "/sdcard/Movies/";
            ARBuilder.Instance.RecorderBehaviour.OutputFile = path_root + "EasyAR_Recording_" + System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".mp4";

            isRecording = true;
            StartShowMessage = true;

Pay attention to default saving path"/sdcard/Movies/"+"yyyy-MM-dd_HH-mm-ss.mp4"

public void StopRecord()
            isRecording = false; }
2.Recorder and its RecorderBehaviour script

This script is to process video-saved quality after screen-recording.

Now let’s do UI. You can use UI in Unity and also use NGUI.

NGUI Plug-in resource: Link:  Password: py7u

We use NGUI in this tutorial. First create "2D Sprite" and name it Button。

Change 2D Sprite’s image target:

Put script on Button. Create Label to display text hints. Adjust Label to an appropriate size. Test is empty in Label. The effect is like that:

Step 4:Modify script

"HelloARRecording" is the key code of realizing screen-recording. "HelloARRecording" script uses OnGUI to provide button but it doesn’t have text hint. So we modify content like that

1.Use Button to replace OnGUI and put script on Button

2.Click on Button and text hint pops up

First delete OnGUI(), create two IEnumerator to control text- displaying time.


Define Label:

IEnumerator showMessage1()
            label.gameObject.SetActive (true);
            label.text = "Start";
            yield return new WaitForSeconds(2f);
            label.gameObject.SetActive (false);
IEnumerator showMessage2()
            label.gameObject.SetActive (true);
            label.text = "Recorded at " + ARBuilder.Instance.RecorderBehaviour.OutputFile;
            yield return new WaitForSeconds(2f);
            label.gameObject.SetActive (false);

Write a method Record(), realizing click of button through bool.

        public void Record()
            if (!isClick) {
                StartRecord ();