Hello developers! In this tutorial you’ll see just how easy it is to switch from using Frozen Mountain to Agora for your video chat purposes in Unity.
First, some context is necessary as to why you’d want to migrate from Frozen Mountain. You are accomplishing the same functionality using ~200 lines of Agora SDK code, compared to the ~1500 lines required in the Frozen Mountain example. Agora puts the developers first, and we are continuously improving the developer experience and streamlining our products. When using Frozen Mountain, you have three standard WebRTC protocols to choose from. When you use Agora, we simplify this process by connecting your users to our own SD-RTN™ (software-defined real-time network), which is more scalable and reliable than standard WebRTC video chat.
I’ve inserted Agora SDK code in the locations where Frozen Mountain implements comparable functionality, so you’re able to compare how simple it is to use Agora vs. Frozen Mountain.
To get started, you need an Agora account. If you don’t have one, here is a guide to setting up an account.
This project implements the Agora SDK into the Frozen Mountain starter demo for Unity. You can find the example project here on our community GitHub.
You will reuse the assets provided in the Join level inside Assets > Scenes.
Inside of JoinBehaviour.cs:
You need a variable reference to the mRtcEngine and your AppID retrieved from the Agora Console.
Next, you initialize the Agora engine and make sure the JoinBehaviour object persists between scenes.
DontDestroyOnLoad is called to maintain the reference to the Agora engine when the scenes change. One initialization is necessary for the duration of the application.
When you either join a channel or leave a channel and return to the Join Screen, OnEnable() will fire and make sure your references are connected.
The updated JoinBehaviour.cs script demonstrates how simple it is to create a connection to the Agora network (SD-RTN™) and to set up a video chat by calling JoinChannel().
In the channel screen, implement the functionality for leaving the channel and returning to the Join screen, the callbacks for when users join and leave, and the code to create new video screens for joining users.
I’ve changed the Unity Start() function to OnEnable(), and left Frozen Mountain’s code intact yet commented out.
From Start Method to OnEnable()
Toggle Video Button
You now have everything you need to create a basic web chat app comparable to the Frozen Mountain demo. The power of Agora is the simplicity of use, coupled with the SD-RTN™ delivering world-class connection results that outperform WebRTC protocols.
I hope this guide was helpful. If you learned something, make sure to teach someone else!
Have fun making the migration from Frozen Mountain to Agora!
Want to build Real-Time Engagement apps?
If you have questions, please call us at 408-879-5885. We’d be happy to help you add voice or video chat, streaming and messaging into your apps.
Stay inspired by accessing all RTE2020 session recordings. Gain access to innovative Real-Time-Engagement content and start innovating today.