# Hello Video Agora for Unity
This tutorial enables you to quickly get started with using a sample app to develop requests to the Agora Gaming SDK in [Unity 3D](https://unity3d.com).
This sample app demonstrates the basic Agora SDK feature:
- [Join a Channel](#create-the-join-method)
- [Leave a Channel](#create-the-leave-method)
## Prerequisites
- Agora.io Developer Account
- Unity 3D 5.5+
## Quick Start
This section shows you how to prepare and build the Agora React Native wrapper for the sample app.
### Create an Account and Obtain an App ID
To build and run the sample application you must obtain an App ID:
1. Create a developer account at [agora.io](https://dashboard.agora.io/signin/). Once you finish the signup process, you will be redirected to the Dashboard.
2. Navigate in the Dashboard tree on the left to **Projects** > **Project List**.
3. Copy the App ID that you obtained from the Dashboard into a text file. You will use this when you launch the app.
### Update and Run the Sample Application
1. Edit the [`Assets/HelloUnityVideo.cs`](Assets/HelloUnityVideo.cs) file. In the `HelloUnityVideo` class declaration, update `#YOUR APP ID#` with your App ID.
`private static string appId = #YOUR APP ID#;`
2. Download the [Agora Gaming SDK](https://www.agora.io/en/download/) for Unity 3D.
![download.jpg](images/download.jpg)
3. Unzip the downloaded SDK package and copy the files from the following SDK folders into the associated sample application folders.
SDK Folder|Application Folder
---|---
`libs/Android/`|`Assets/Plugins/Android/`
`libs/iOS/`|`Assets/Plugins/iOS/`
`libs/Scripts/AgoraGamingSDK/`|`Assets/Scripts/AgoraGamingSDK/`
4. Open the project in Unity and run the sample application.
## Steps to Create the Sample
The sample application is comprised of two main classes, `HelloUnityVideo` and `Home`.
- [Create the Scenes](#create-the-scenes)
- [Create the HelloUnityVideo Class](#create-the-hellounityvideo-class)
- [Create the Home Class](#create-the-home-class)
### Create the Scenes
The sample application consists of two main Unity scenes.
#### Create SceneHelloVideo
When you load `SceneHelloVideo` in Unity, you'll see that the stage contains a cylindrical object and a cube object.
![SceneHelloVideo.jpg](images/SceneHelloVideo.jpg)
The scene also contains a **Leave** button.
**Note:** You may have to zoom out and adjust the camera view to see the **Leave** button in the stage.
![SceneHelloVideo2.jpg](images/SceneHelloVideo2.jpg)
#### Create SceneHome
When you load `SceneHome` in Unity, you will see the stage contains:
UI object|Description
---|---
Text object|Explanation text for the user to read
Text input box|Text input box for the user to enter the channel name
**Join** button|Button to join the channel
**Note:** You may have to zoom out and adjust the camera view to see the leave button in the stage.
![SceneHome.jpg](images/SceneHome.jpg)
### Create the HelloUnityVideo Class
The `HelloUnityVideo` class is a subclass of `MonoBehaviour`. The [`HelloUnityVideo.cs`](Assets/HelloUnityVideo.cs) file contains the relevant Agora SDK code for the Unity 3D sample application.
```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using agora_gaming_rtc;
using UnityEngine.UI;
public class HelloUnityVideo : MonoBehaviour {
...
}
```
The remaining code in this section is contained within the `HelloUnityVideo` class declaration.
- [Declare Global Variables](#declare-global-variables)
- [Load / Unload Engine Methods](#load-unload-engine-methods)
- [Join / Leave Channel Methods](#join-leave-channel-methods)
- [Create General Event Listeners](#create-general-event-listeners)
- [Create User Event Listeners](#create-user-event-listeners)
#### Declare Global Variables
The `HelloUnityVideo` class has three global variables and one method that acts as a declaration for the SDK version constant.
The `appId` variable is initialized with the Agora App ID from your Agora Dashboard.
**Note:** `#YOUR APP ID#` must be replaced with a valid Agora App ID.
```
// PLEASE KEEP THIS App ID IN SAFE PLACE
// Get your App ID at https://dashboard.agora.io/.
// After you entered the App ID, remove ## outside of Your App ID.
private static string appId = #YOUR APP ID#;
```
Declare the `mRtcEngine` variable, which represents the Agora RTC engine for the application.
Initialize `mRemotePeer` to `0` which will track the index of the current remove user for the application.
```
// instance of agora engine
public IRtcEngine mRtcEngine;
// implement engine callbacks
public uint mRemotePeer = 0; // insignificant. only record one peer
```
The `getSdkVersion()` method returns the SDK version from the Agora RTC engine using `IRtcEngine.GetSdkVersion()`.
```
public string getSdkVersion () {
return IRtcEngine.GetSdkVersion ();
}
```
#### Load / Unload Engine Methods
The `HelloUnityVideo` class has two methods for loading / unloading the Agora RTC engine.
##### Create the Load Engine Method
The `loadEngine()` method initializes the Agora RTC engine.
1. Set debugging logs for the method initialization and if `mRtcEngine` is not `null`. If `mRtcEngine` exists, execute a `return` as the RTC engine has already been initialized.
2. Initialize the engine with the `appId` using `IRtcEngine.getEngine()`.
3. Enable Agora logging by setting the following log filters using `mRtcEngine.SetLogFilter()`.
Filter|Description
---|---
`LOG_FILTER.DEBUG`|Sets the Agora debugging logs
`LOG_FILTER.INFO`|Sets the Agora information logs
`LOG_FILTER.WARNING`|Sets the Agora warning logs
`LOG_FILTER.ERROR`|Sets the Agora error logs
`LOG_FILTER.CRITICAL`|Sets the Agora critical error logs
```
// load agora engine
public void loadEngine()
{
// start sdk
Debug.Log ("initializeEngine");
if (mRtcEngine != null) {
Debug.Log ("Engine exists. Please unload it first!");
return;
}
// init engine
mRtcEngine = IRtcEngine.getEngine (appId);
// enable log
mRtcEngine.SetLogFilter (LOG_FILTER.DEBUG | LOG_FILTER.INFO | LOG_FILTER.WARNING | LOG_FILTER.ERROR | LOG_FILTER.CRITICAL);
}
```
##### Create the Unload Engine Method
The `unloadEngine()` method destroys the Agora RTC engine.
1. Set debugging logs for the method initialization.
2. Ensure `mRtcEngine` is not `null` before destroying the engine using `IRtcEngine.Destroy()` and setting `mRtcEngine` to `null`.
```
// unload agora engine
public void unloadEngine()
{
Debug.Log ("calling unloadEngine");
// delete
if (mRtcEngine != null) {
IRtcEngine.Destroy ();
mRtcEngine = null;
}
}
```
#### Join / Leave Channel Methods
The `HelloUnityVideo` class has two methods to manage joining and leaving a channel.
##### Create the Join Method
The `join()` method joins the user to the specified `channel`, sets event listeners, and configures the Agora RTC engine settings.
1. Set a debug log for the `channel` name using `Debug.Log()` and ensure `mRtcEngine` is not `null` before executing the remaining code for the method.
2. Set the following callbacks for `mRtcEngine`:
**Note:** These callbacks are optional for the sample application, but are useful for extending the functionality of the application.
Event Listener|Method Value|Description
---|---|---
`OnJoinChannelSuccess`|`onJoinChannelSuccess`|Detects when the channel is successfully joined.
`OnUserJoined`|`onUserJoined`|Detects when a user successfully joins the channel.
`OnUserOffline`|`onUserOffline`|Detects when a user goes offline.
3. Enable video and set its callback using `mRtcEngine.EnableVideo()` and `mRtcEngine.EnableVideoObserver()`.
4. Join the channel using `mRtcEngine.JoinChannel()`.
5. Set a debug log for the method completion using `De
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
接入视频通话案例.zip (604个子文件)
AgoraAIDenoiseExtension 1.09MB
AgoraAIDenoiseExtension 1.09MB
AgoraCore 438KB
AgoraCore 438KB
AgoraDav1dExtension 1.06MB
AgoraDav1dExtension 1.06MB
Agorafdkaac 903KB
Agorafdkaac 903KB
Agoraffmpeg 4.92MB
Agoraffmpeg 4.92MB
AgoraJNDExtension 1.1MB
AgoraJNDExtension 1.1MB
AgoraRtcKit 24.68MB
AgoraRtcKit 24.68MB
agoraSdkCWrapper 705KB
AgoraSoundTouch 117KB
AgoraSoundTouch 117KB
AgoraVideoSegmentationExtension 5.43MB
AgoraVideoSegmentationExtension 5.43MB
Vudiotest.apk 20.06MB
DefaultWsdlHelpGenerator.aspx 59KB
DefaultWsdlHelpGenerator.aspx 59KB
DefaultWsdlHelpGenerator.aspx 59KB
ProjectSettings.asset 67KB
InputManager.asset 5KB
QualitySettings.asset 5KB
NavMeshAreas.asset 4KB
GraphicsSettings.asset 4KB
Physics2DSettings.asset 4KB
UnityConnectSettings.asset 4KB
EditorBuildSettings.asset 4KB
TagManager.asset 4KB
DynamicsManager.asset 4KB
EditorSettings.asset 4KB
AudioManager.asset 4KB
TimeManager.asset 4KB
NetworkManager.asset 4KB
ClusterInputManager.asset 4KB
EditorUserSettings.asset 1KB
PackageManagerSettings.asset 1002B
VFXManager.asset 353B
VersionControlSettings.asset 188B
PresetManager.asset 146B
globalgamemanagers.assets 57KB
sharedassets1.assets 52KB
sharedassets0.assets 12KB
av1 3.07MB
av1 3.07MB
Compat.browser 2KB
Compat.browser 2KB
Compat.browser 2KB
Assembly-CSharp.csprojAssemblyReference.cache 419KB
Assembly-CSharp-Editor.csprojAssemblyReference.cache 359KB
DesignTimeResolveAssemblyReferencesInput.cache 32KB
Assembly-CSharp.csproj.CoreCompileInputs.cache 42B
Assembly-CSharp-Editor.csproj.CoreCompileInputs.cache 42B
machine.config 33KB
machine.config 33KB
machine.config 28KB
web.config 18KB
web.config 18KB
web.config 11KB
config 3KB
boot.config 69B
AgoraGamingRtcEngine.cs 316KB
AgoraBase.cs 145KB
AgoraChannel.cs 130KB
AgoraCallback.cs 67KB
IAgoraGamingRtcEngineNative.cs 66KB
AgoraChannelCallback.cs 30KB
AudioRawDataManager.cs 17KB
VideoDemo.cs 16KB
VideoSurface.cs 15KB
AudioEffectManager.cs 14KB
AudioPlaybackDeviceManager.cs 12KB
TestHelloUnityVideo.cs 12KB
AudioRecordingDeviceManager.cs 11KB
TestHome.cs 8KB
UIElementDragger.cs 8KB
ButtonHandler.cs 8KB
VideoDeviceManager.cs 8KB
VideoRawDataManager.cs 8KB
MetaDataObserver.cs 7KB
PacketObserver.cs 6KB
BL_BuildPostProcess.cs 6KB
VideoRender.cs 6KB
AgoraCallbackObject.cs 2KB
AgoraCallbackQueue.cs 1KB
AgoraLog.cs 378B
TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs 0B
TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs 0B
TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs 0B
Assembly-CSharp.csproj 48KB
Assembly-CSharp-Editor.csproj 47KB
UnityPlayer.dll 26.7MB
agora_rtc_sdk.dll 24.09MB
agora_rtc_sdk.dll 24.09MB
libagora_ai_denoise_extension.dll 5.3MB
libagora_ai_denoise_extension.dll 5.3MB
libagora_segmentation_extension.dll 4.86MB
共 604 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
呆呆敲代码的小Y
- 粉丝: 16w+
- 资源: 51
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功