// 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); } }
// When a remote user joined, this delegate will be called. Typically // create a GameObject to render video on it private void onUserJoined(uint uid, int elapsed) { Debug.Log("onUserJoined: uid = " + uid + " elapsed = " + elapsed); // this is called in main thread // 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); } }
void OnUserJoinedHandler(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 (go != null) { return; } // create a GameObject and assign to this new user VideoSurface videoSurface = makeImageSurface(uid.ToString()); if (videoSurface != null) { // configure videoSurface videoSurface.SetForUser(uid); videoSurface.SetEnable(true); videoSurface.SetVideoSurfaceType(AgoraVideoSurfaceType.RawImage); videoSurface.SetGameFps(30); } usersInChannel++; }
private void OnUserJoined(uint uid, int elapsed) { print("user joined"); remoteVideo.name = uid.ToString(); VideoSurface videoSurface = makeImageSurface(uid.ToString()); if (!ReferenceEquals(videoSurface, null)) { videoSurface.SetForUser(uid); videoSurface.SetEnable(true); videoSurface.SetVideoSurfaceType(AgoraVideoSurfaceType.RawImage); videoSurface.SetGameFps(30); } }
void OnUserJoined(uint uid, int elapsed) { GameObject go = GameObject.Find("RemoteView"); if (remoteView == null) { remoteView = go.AddComponent <VideoSurface>(); } remoteView.SetForUser(uid); remoteView.SetEnable(true); remoteView.SetVideoSurfaceType(AgoraVideoSurfaceType.RawImage); remoteView.SetGameFps(30); }
// Create new image plane to display users in party. private void CreateUserVideoSurface(uint uid, bool isLocalUser) { // Avoid duplicating Local player VideoSurface image plane. for (int i = 0; i < playerVideoList.Count; i++) { if (playerVideoList[i].name == uid.ToString()) { return; } } // Get the next position for newly created VideoSurface to place inside UI Container. float spawnY = playerVideoList.Count * spaceBetweenUserVideos; Vector3 spawnPosition = new Vector3(0, -spawnY, 0); // Create Gameobject that will serve as our VideoSurface. GameObject newUserVideo = Instantiate(userVideoPrefab, spawnPosition, spawnPoint.rotation); if (newUserVideo == null) { Debug.LogError("CreateUserVideoSurface() - newUserVideoIsNull"); return; } newUserVideo.name = uid.ToString(); newUserVideo.transform.SetParent(spawnPoint, false); newUserVideo.transform.rotation = Quaternion.Euler(Vector3.right * -180); playerVideoList.Add(newUserVideo); // Update our VideoSurface to reflect new users VideoSurface newVideoSurface = newUserVideo.GetComponent <VideoSurface>(); if (newVideoSurface == null) { Debug.LogError("CreateUserVideoSurface() - VideoSurface component is null on newly joined user"); return; } if (isLocalUser == false) { newVideoSurface.SetForUser(uid); } newVideoSurface.SetGameFps(30); // Update our "Content" container that holds all the newUserVideo image planes content.sizeDelta = new Vector2(0, playerVideoList.Count * spaceBetweenUserVideos + 140); UpdatePlayerVideoPostions(); UpdateLeavePartyButtonState(); }
// Create new image plane to display users in party. private void CreateUserVideoSurface(uint uid, bool isLocalUser) { // Avoid duplicating Local player VideoSurface image plane. for (int i = 0; i < playerVideoList.Count; i++) { if (playerVideoList[i].name == uid.ToString()) { return; } } // Create Gameobject that will serve as our VideoSurface. GameObject newUserVideo = GameObject.CreatePrimitive(PrimitiveType.Cube); if (newUserVideo == null) { Debug.LogError("CreateUserVideoSurface() - newUserVideoIsNull"); return; } newUserVideo.transform.localScale = Vector3.one * 3; newUserVideo.name = uid.ToString(); playerVideoList.Add(newUserVideo); // this is because we are using 4 spawn points per room if (playerVideoList.Count < 5) { newUserVideo.transform.position = spawnPointLocations[playerVideoList.Count - 1].position; } // Update our VideoSurface to reflect new users VideoSurface newVideoSurface = newUserVideo.AddComponent <VideoSurface>(); if (newVideoSurface == null) { Debug.LogError("CreateUserVideoSurface() - VideoSurface component is null on newly joined user"); return; } if (isLocalUser == false) { newVideoSurface.SetForUser(uid); } newVideoSurface.SetGameFps(30); }
void VideoImageClicked(string name) { if (bigPicTemp != null) { if (bigPicTemp.name == name) { removeObserver(uint.Parse(name)); AddObserver(uint.Parse(name)); } RemoveBig(); } else { GameObject go = null; for (int i = 0; i < allObserver.Count; i++) { if (allObserver[i].name == name) { go = allObserver[i]; break; } Debug.Log(name); } if (go != null) { VideoSurface video1 = go.GetComponent <VideoSurface>(); DestroyImmediate(video1); } bigPicTemp = Instantiate(bigPic); bigPicTemp.name = name; bigPicTemp.transform.parent = bkaVideoParent; bigPicTemp.GetComponent <RectTransform>().SetAsFirstSibling(); bigPicTemp.transform.localScale = new Vector3(1, -1, 1); bigPicTemp.SetActive(true); VideoSurface videoSurface = bigPicTemp.AddComponent <VideoSurface>(); videoSurface.resize = true; videoSurface.expert = isExpert; // configure videoSurface videoSurface.SetForUser(uint.Parse(name)); videoSurface.SetEnable(true); videoSurface.SetVideoSurfaceType(AgoraVideoSurfaceType.RawImage); videoSurface.SetGameFps(25); } }
VideoSurface CreateUserVideoSurface(uint uid, Vector3 spawnPosition, bool isLocalUser) { if (!pView.isMine) { print("Photon view isn't mine: " + gameObject.name); return(null); } GameObject newUserVideo = new GameObject(uid.ToString(), typeof(RawImage), typeof(VideoSurface)); if (newUserVideo == null) { print("new user video <GAMEOBJECT> couldn't be created: " + gameObject.name); return(null); } newUserVideo.transform.parent = transform.GetChild(0); newUserVideo.GetComponent <RectTransform>().anchoredPosition = spawnPosition + (Vector3.right * currentUsers * newVideoFrameOffsetAmount); newUserVideo.GetComponent <RectTransform>().sizeDelta = new Vector2(120, 120); newUserVideo.transform.rotation = Quaternion.Euler(Vector3.right * -180); newUserVideo.transform.localScale = Vector3.one; VideoSurface newVideoSurface = newUserVideo.GetComponent <VideoSurface>(); if (newVideoSurface == null) { print("new user video <VIDEOSURFACE> couldn't be created: " + gameObject.name); return(null); } if (isLocalUser == false) { newVideoSurface.SetForUser(uid); } print(gameObject.name + " creating new video surface for: " + uid); newVideoSurface.SetGameFps(30); currentUsers++; return(newVideoSurface); }
private void makeVideoView(uint 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); } }
private void makeVideoView(string channelId, uint uid) { string objName = channelId + "_" + uid.ToString(); GameObject go = GameObject.Find(objName); if (!ReferenceEquals(go, null)) { return; // reuse } // create a GameObject and assign to this new user VideoSurface videoSurface = makeImageSurface(objName); if (!ReferenceEquals(videoSurface, null)) { // configure videoSurface videoSurface.SetForMultiChannelUser(channelId, uid); videoSurface.SetEnable(true); videoSurface.SetVideoSurfaceType(AgoraVideoSurfaceType.RawImage); videoSurface.SetGameFps(30); } }
public void AddObserver(uint uid) { GameObject go = Instantiate(prefab); go.name = uid.ToString(); go.transform.parent = transform; go.transform.localScale = new Vector3(1, -1, 1);// Vector3.one; go.GetComponent <Button>().onClick.AddListener(delegate { VideoImageClicked(go.name); }); // set up transform VideoSurface videoSurface = go.AddComponent <VideoSurface>(); // configure videoSurface videoSurface.SetForUser(uid); videoSurface.SetEnable(true); videoSurface.SetVideoSurfaceType(AgoraVideoSurfaceType.RawImage); videoSurface.SetGameFps(25); allObserver.Add(go); //更新大小 UpdateSelfSize(allObserver.Count); }
// 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); // this is called in main thread // find a game object to render video stream from 'uid' GameObject go = GameObject.Find(RemoteStreamTargetImage); if (go == null) { return; } VideoSurface videoSurface = go.GetComponent <VideoSurface>(); if (videoSurface != null) { videoSurface.enabled = true; // configure videoSurface videoSurface.SetForUser(uid); videoSurface.SetEnable(true); videoSurface.SetGameFps(30); } }