Last active
August 8, 2020 19:42
-
-
Save icywind/2613943acec32da1951d15c5ca5d5e3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SerializeField] | |
private GameObject avatarVideoPrefab; | |
// Create new image plane to display users in party. | |
private void CreateUserVideoSurface(uint uid, bool isLocalUser, bool isAvatar) | |
{ | |
// 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(isAvatar ? avatarVideoPrefab : userVideoPrefab, spawnPosition, spawnPoint.rotation); | |
if (newUserVideo == null) | |
{ | |
Debug.LogError("CreateUserVideoSurface() - newUserVideoIsNull"); | |
return; | |
} | |
newUserVideo.name = uid.ToString(); | |
newUserVideo.transform.SetParent(spawnPoint, false); | |
playerVideoList.Add(newUserVideo); | |
if (isAvatar) | |
{ | |
// The AvatarViewController will encapsulate logic to assign user id | |
} | |
else | |
{ | |
newUserVideo.transform.rotation = Quaternion.Euler(Vector3.right * -180); | |
AssignAgoraSurface(newUserVideo, isLocalUser ? 0 : uid); | |
} | |
// Update our "Content" container that holds all the newUserVideo image planes | |
content.sizeDelta = new Vector2(0, playerVideoList.Count * spaceBetweenUserVideos + 140); | |
UpdatePlayerVideoPostions(); | |
UpdateLeavePartyButtonState(); | |
} | |
void AssignAgoraSurface(GameObject newUserVideo, uint uid) | |
{ | |
// Update our VideoSurface to reflect new users | |
VideoSurface newVideoSurface = newUserVideo.GetComponent<VideoSurface>(); | |
if (newVideoSurface == null) | |
{ | |
Debug.LogWarning("CreateUserVideoSurface() - VideoSurface component is null on newly joined user"); | |
newVideoSurface = newUserVideo.AddComponent<VideoSurface>(); | |
} | |
newVideoSurface.SetForUser(uid); | |
newVideoSurface.SetGameFps(30); | |
} | |
private void OnJoinChannelSuccessHandler(string channelName, uint uid, int elapsed) | |
{ | |
if (!photonView.isMine) | |
return; | |
myUID = uid; | |
CreateUserVideoSurface(uid, true, true); | |
} | |
// Remote Client Joins Channel. | |
private void OnUserJoinedHandler(uint uid, int elapsed) | |
{ | |
if (!photonView.isMine) | |
return; | |
CreateUserVideoSurface(uid, false, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment