using UnityEngine; using UnityEngine.UI; using agora_gaming_rtc; using agora_utilities; // this is an example of using Agora Unity SDK // It demonstrates: // How to enable video // How to join/leave channel // public class TestHelloUnityVideo { // instance of agora engine private IRtcEngine mRtcEngine; private Text MessageText; // a token is a channel key that works with a AppID that requires it. // Generate one by your token server or get a temporary token from the developer console private string token = ""; // load agora engine public void loadEngine(string appId) { // 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); } public void join(string channel) { Debug.Log("calling join (channel = " + channel + ")"); if (mRtcEngine == null) return; // set callbacks (optional) mRtcEngine.OnJoinChannelSuccess = onJoinChannelSuccess; mRtcEngine.OnUserJoined = onUserJoined; mRtcEngine.OnUserOffline = onUserOffline; mRtcEngine.OnWarning = (int warn, string msg) => { Debug.LogWarningFormat("Warning code:{0} msg:{1}", warn, IRtcEngine.GetErrorDescription(warn)); }; mRtcEngine.OnError = HandleError; // enable video mRtcEngine.EnableVideo(); // allow camera output callback mRtcEngine.EnableVideoObserver(); // join channel /* This API Assumes the use of a test-mode AppID mRtcEngine.JoinChannel(channel, null, 0); */ /* This API Accepts AppID with token; by default omiting info and use 0 as the local user id */ mRtcEngine.JoinChannelByKey(channelKey: token, channelName: channel); } public string getSdkVersion() { string ver = IRtcEngine.GetSdkVersion(); return ver; } public void leave() { Debug.Log("calling leave"); if (mRtcEngine == null) return; // leave channel mRtcEngine.LeaveChannel(); // deregister video frame observers in native-c code mRtcEngine.DisableVideoObserver(); } // unload agora engine public void unloadEngine() { Debug.Log("calling unloadEngine"); // delete if (mRtcEngine != null) { IRtcEngine.Destroy(); // Place this call in ApplicationQuit mRtcEngine = null; } } public void EnableVideo(bool pauseVideo) { if (mRtcEngine != null) { if (!pauseVideo) { mRtcEngine.EnableVideo(); } else { mRtcEngine.DisableVideo(); } } } // accessing GameObject in Scnene1 // set video transform delegate for statically created GameObject public void onSceneHelloVideoLoaded() { // Attach the SDK Script VideoSurface for video rendering GameObject quad = GameObject.Find("Quad"); if (ReferenceEquals(quad, null)) { Debug.Log("failed to find Quad"); return; } else { quad.AddComponent(); } GameObject cube = GameObject.Find("Cube"); if (ReferenceEquals(cube, null)) { Debug.Log("failed to find Cube"); return; } else { cube.AddComponent(); } GameObject text = GameObject.Find("MessageText"); if (!ReferenceEquals(text, null)) { MessageText = text.GetComponent(); } GameObject bobj = GameObject.Find("HelpButton"); if (bobj != null) { Button button = bobj.GetComponent