logo
On this page

Example Code Running Guide

Prepare Environment

Please ensure your development environment meets the following technical requirements:

Install Unity 2018.4.21f1 or above. If not installed, you can download Unity Hub from Unity Official Website, then install the Unity version you need (if you are not sure, it is recommended to install the latest LTS version). When downloading, it is recommended to check the corresponding Platforms modules according to the platform you need to run, taking installation on macOS as an example:

Choose the corresponding development environment or device according to the platform where the example code needs to run:

  • Requirements for running Android example source code: Android version is not lower than 4.4, and an Android device or emulator that supports audio and video (recommended to use a real device). If it is a real device, please enable the "Allow USB Debugging" option.

  • Requirements for running iOS example source code: Xcode 15.0 or above, iOS 12.0 or above, and an iOS device or emulator that supports audio and video (recommended to use a real device).

  • Requirements for running macOS example source code: macOS 10.13 or above, and a macOS device that supports audio and video.

  • Requirements for running Windows example source code: Windows 7 or above, a Windows device that supports audio and video, and Visual Studio 2015 or above installed.

  • Requirements for running Linux example source code: Any Linux distribution system with GLIBC 2.16 or above (currently only supports x86_64 architecture), libasound (ALSA), libv4l2 (v4l utils), CMake 3.7 or above.

  • Requirements for running WebGL example source code: Browser needs to support WebGL and WebAssembly (WebGL 2.0 is recommended), Chrome 57 or above, Firefox 56 or above, Safari 11 or above, not supported on mobile devices. It is recommended to use the latest browser for best performance and compatibility.

  • Ensure the network connection of the running device is normal.

  • Ensure Unity has installed the Platforms modules corresponding to the running platform. If Unity is already installed but the relevant Platforms modules are not installed, you need to download the corresponding modules. Taking installation on macOS as an example: Open Unity Hub, click the "Installs" option on the left, select the Unity version to be installed, click the icon in the upper right corner to select the "Add Modules" option, and check and download the corresponding modules according to your development requirements.

Prerequisites

You have created a project in ZEGOCLOUD Console and applied for valid AppID and AppSign.

Warning

The SDK also supports Token authentication. If you need to upgrade the authentication method, please refer to How to upgrade from AppSign authentication to Token authentication.

Get Example Source Code

Example Source Code Directory Structure

The following structure is the file structure of the project directory. The file paths involved below are all relative to this directory.

unity3d
 ├── Assets
 │ ├── Resources # Prefab resource files
 │ ├── Scenes # Example scenes
 │ ├── Scripts # SDK scripts
 │ │ ├── native # C interface import layer
 │ │ ├── videoRender # Custom video rendering module
 │ │ ├── ... # Interface wrapper
 │ ├── StreamingAssets # Resource files
 │ ├── ZegoExpressExample # Example scripts
 │ │ ├── Examples # Example scripts
 │ │ ├── Utils # Utility classes
 │ │ ├── KeyCenter.cs # Fill in the applied AppID, AppSign, user ID for logging in to the room, and Token
 │ │ ├── ZegoExpressExample.cs
 │ ├── WebGLTemplates # WebGL templates
 │ │ ├── zegoTemplates # ZEGO templates
 ├── Packages # Unity dependencies
 ├── ProjectSettings

Run Example Code

  1. The downloaded example source code lacks the SDK. You need to Download SDK Package first and unzip it.

    Refer to the Integrate SDK documentation, copy the unzipped SDK package to the "Assets" directory of the project, and perform additional processing according to the platform to run, otherwise the App build will fail. As shown below:

  2. Modify the "Assets/ZegoExpressExample/KeyCenter.cs" file and fill in the "appID" and "appSign" required for SDK initialization.

Warning
  • Please use the AppID and AppSign obtained in Prerequisites of this article to fill in correctly.
  • userID can be filled in as you define.
  • If you use WebGL to run the source code, you need to obtain the corresponding Token according to the filled userID and fill it in correctly, otherwise the example source code cannot run normally.
  1. In Unity Hub, click the "Projects" tab, and click "Open" in the upper right corner to select the directory where the example source code is located.

  2. After opening, a prompt may appear: "Editor version not installed", and the Unity Editor version used by the example source code project cannot be found. At this time, select another Unity Editor version and specify the Unity version you are using.

  3. After opening the project, select "HomePage" under "Project > Assets > Scenes" in the lower left corner and double-click, then click the "Game" tab to see the scene of the example source code homepage.

  4. In the top menu bar, select "File > Build Settings".

  5. In "Platform", select the platform, and click "Switch Platform" in the lower right corner to switch to the platform to run.

  6. Start running.

  1. Refer to step 7, switch "Platform" to "Android" platform, click "Player Settings" to set package name and other configurations.
  1. After completing the settings, connect the Android device and click "Build And Run".
  1. Refer to step 7, switch "Platform" to "iOS" platform, click "Build" to save the iOS project locally, and open the local project through Xcode.
  2. In the opened Xcode project, open the "Signing & Capabilities" tab of the "Unity-iPhone" Target. First ensure that "Automatically manage signing" is checked, then switch "Team" to your own Team, and modify "Bundle Identifier" to a custom Bundle ID.
  1. Select the "Info.plist" file and add camera and microphone permissions.
  1. If you need to run on a real device, in the "General" tab of the "Unity-iPhone" Target, find "Frameworks, Libraries, and Embedded Content", click "+" -> "add other" -> "add files" to add ZegoExpressEngine.framework under ios-arm64/ZegoExpressEngine.framework in ZegoExpressEngine.xcframework.
  1. Click the Run button to run the example Demo. Please note that when running on an iOS device, if the following error occurs, please refer to Integrate SDK for handling the error about integrating ZegoExpressEngine.framework when exporting iOS Xcode project.
    no suitable image found.  Did find:
    /private/var/containers/Bundle/Application/3CC0EE65-89C9-45F5-8E22-A4AC194DF260/hello.app/Frameworks/UnityFramework.framework/Frameworks/ZegoExpressEngine.framework/ZegoExpressEngine: code signature in (/private/var/containers/Bundle/Application/3CC0EE65-89C9-45F5-8E22-A4AC194DF260/hello.app/Frameworks/UnityFramework.framework/Frameworks/ZegoExpressEngine.framework/ZegoExpressEngine) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
  1. Refer to step 7, switch "Platform" to "macOS" platform, select the architecture to build, such as Intel + Apple silicon, then click "Build" to generate the App locally.
  1. After generating an application on macOS, double-click to run.
  1. Refer to step 7, switch "Platform" to "Windows" platform, select the architecture to build, note that the architecture selected here must be consistent with the SDK architecture retained in step 1, then click "Build" to generate the App locally.
  1. On the Windows device, click the .exe file in the project to run.
  1. Refer to step 7, switch "Platform" to "Linux" platform, then click "Build" to generate the App locally.
  1. Open the terminal in the App directory on the Linux device, enter ./<App Name>, and it will run. For example, if the Build generated App name is "zegoExpressExample", enter the following command to run:
    $ ./zegoExpressExample
  1. Bind event component to the scene, the component name must be: "ZegoWebGLEventHandler", and add a script named "ZegoWebGLEventHandler.cs".
Warning

If the API used contains a callback function, it is necessary to bind the event component "ZegoWebGLEventHandler".

  1. Refer to step 7, switch "Platform" to "WebGL" platform, select the architecture to build, note that the architecture selected here must be consistent with the SDK architecture retained in step 1. Then click "Switch Platform" to switch to WebGL configuration, then click "Player Setting", select "WebGL Template" as "zegoTemplates".

  2. Click "Build And Run" to generate local files.

Experience Real-time Audio and Video Functions

Run the project on a real device. After successful operation, you can see the local video screen.

For convenience of experience, ZEGO provides a Web platform for debugging. On this page, enter the same AppID and RoomID, enter different UserID, and the corresponding Token, you can join the same room and communicate with the real device. When the audio and video call starts successfully, you can hear the remote audio and see the remote video screen.

FAQ

  1. When the example source code runs on an Android device, an error Gradle build failed. occurs during build. How to solve it?

    Generally, due to network problems, Gradle fails to download dependencies. Please check whether your local network can normally access Google resources; if not, you may need to enable a proxy.

Previous

Common Error Codes

Next

Integrating SDK

On this page

Back to top