2nd Jul 2020

Enhance your Game Engagement using Agora.io

Game Development

Written By, Bhavesh Savaliya


Playing games together is the best thing ever. Agora provides an easy to use SDK for unity games. People used to have a static profile picture but, nowadays, it would be more fun if there is a video rendering instead of a static image. Agora is a scalable and reliable solution to enhance the gaming experience.


Agora account setup

You need an App ID to start working with agora.io SDK.
Create an account with Agora.io.
Create a new project (e.g. “Test”)
Open the project from the dashboard and you will find the App ID hidden, copy it for future usage.


Project setup with Agora SDK

Open unity hub and create a new project.

Agora supports unity 2017.4.35 or higher, I’m using 2019.2.0.

Download and Import “agora video chat sdk for unity” from the Asset Store into the project

For this tutorial, I’m assuming that you are not a noob to unity editor, C# and mobile development.

Scripting Agora functionality extended

Now that you have set up the SDK. Either you can use default test scripts available with SDK or you can extend the functionality the way you want.

You can refer to the basic implementation from Github Link or refer the documentation.

Basic method setup in order to connect with Agora.

Create AgoraEngineHandler.cs to manage agora engine functionalities in a sort of decoupled way.

// instance of agora engine
private IRtcEngine mRtcEngine;

Load/Unload Engine are same function as available with the package script TestHelloUnityVideo.cs

// load agora engine
public void loadEngine(string appId){ … }

// unload agora engine
public void unloadEngine(){ … }

Join and Leave channel functions are also similar as defined in TestHelloUnityVideo. But here, there are changes to the event callback function because we are managing user functionality separately.

AppEvents class has defined all the events that are going to be used across the application.

Here we are managing user callbacks from agora engine.

Subscribe all the AppEvents to manage user callbacks.

Callbacks / Event Listeners

OnJoinChannelSuccess : When channel is successfully joined.
OnUserJoined : When a user Joins the channel successfully.
OnUserOffline : When user goes offline.
OnRemoteAudioStateChanged : When remote user changes audio settings.
OnRemoteVideoStateChanged : When remote user changes video settings.
onLocalUserJoined : When local user joins the channel successfully

Callback methods.

GameManager.cs : This is to manage the overall functionality of the game or an application.

AppId : you can find the application ID from the agora developer dashboard.

SessionData is shared across UI and managing scripts. That can be used to reflect any changes without any dependencies.

User.cs : This class is having user’s data.

Reference UI

User UI : Below is just a reference hierarchy of a user which is attached with User.cs. You can create a prefab out of it and manage the same for all the users.


Example of an prototype UI for a Card Game (Rummy,Poker, etc.).

Example of a Video chat application in a Grid View.



Hence, Audio and Video chat are one of the essential features which are helpful in increasing the engagement among players and hence it will play a vital role for a successful game.

This was just a basic setup to start working with agora.io in unity. There are many more features available by Agora for user interactive gaming. Audio and Video chat is an example for an engaging gaming experience.

This tutorial can be used to work with any existing game or application. Just grab the package and extend as per your flexibility and experience the Agora in action.

Written By,

Unity Developer at Yudiz Solutions Pvt. Ltd