// When a remote user joined, this delegate will be called. Typically // create a GameObject to render video on it protected virtual void OnUserJoined(uint uid, int elapsed) { Debug.Log("onUserJoined: uid = " + uid + " elapsed = " + elapsed); // find a game object to render video stream from 'uid' GameObject go = GameObject.Find(uid.ToString()); if (!ReferenceEquals(go, null)) { return; // reuse } // create a GameObject and assign to this new user VideoSurface videoSurface = makeImageSurface(uid.ToString()); if (!ReferenceEquals(videoSurface, null)) { // configure videoSurface videoSurface.SetForUser(uid); videoSurface.SetEnable(true); videoSurface.SetVideoSurfaceType(AgoraVideoSurfaceType.RawImage); videoSurface.SetGameFps(30); videoSurface.EnableFilpTextureApply(enableFlipHorizontal: true, enableFlipVertical: false); UserVideoDict[uid] = videoSurface; Vector2 pos = AgoraUIUtils.GetRandomPosition(100); videoSurface.transform.localPosition = new Vector3(pos.x, pos.y, 0); } }
protected virtual void OnVideoSizeChanged(uint uid, int width, int height, int rotation) { Debug.LogWarningFormat("OnVideoSizeChanged width = {0} height = {1} for rotation:{2}", width, height, rotation); if (UserVideoDict.ContainsKey(uid)) { GameObject go = UserVideoDict[uid].gameObject; Vector2 v2 = new Vector2(width, height); RawImage image = go.GetComponent <RawImage>(); if (_enforcing360p) { v2 = AgoraUIUtils.GetScaledDimension(width, height, 360f); } if (IsPortraitOrientation(rotation)) { v2 = new Vector2(v2.y, v2.x); } image.rectTransform.sizeDelta = v2; } }
protected VideoSurface makeImageSurface(string goName) { GameObject go = new GameObject(); if (go == null) { return(null); } go.name = goName; // to be renderered onto RawImage image = go.AddComponent <RawImage>(); image.rectTransform.sizeDelta = new Vector2(1, 1);// make it almost invisible // make the object draggable go.AddComponent <UIElementDragger>(); GameObject canvas = GameObject.Find("Canvas"); if (canvas != null) { go.transform.SetParent(canvas.transform); } // set up transform go.transform.Rotate(0f, 0.0f, 180.0f); Vector2 v2 = AgoraUIUtils.GetRandomPosition(100); go.transform.localPosition = new Vector3(v2.x, v2.y, 0); go.transform.localScale = Vector3.one; // configure videoSurface VideoSurface videoSurface = go.AddComponent <VideoSurface>(); return(videoSurface); }