Last active
February 19, 2020 18:52
-
-
Save icywind/f813eafea9a653cd6db2b35a2eed90d2 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
// 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); | |
// 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 assigne to this new user | |
go = GameObject.CreatePrimitive (PrimitiveType.Cube); | |
if (!ReferenceEquals (go, null)) { | |
go.name = uid.ToString (); | |
// configure videoSurface | |
VideoSurface o = go.AddComponent<VideoSurface> (); | |
o.SetForUser (uid); | |
o.SetEnable (true); | |
o.transform.Rotate (-90.0f, 0.0f, 0.0f); | |
o.transform.position = getNextCubePosition(); | |
o.transform.localScale = Vector3.one; | |
} | |
} | |
private static int totalUsers = 0; | |
// Generate a new position to place the new cube in. | |
Vector3 getNextCubePosition() | |
{ | |
totalUsers += 1; | |
GameObject go = GameObject.Find("Sphere"); | |
float x = 0; | |
if (go != null) | |
{ | |
x = go.transform.position.x + totalUsers * 1.5f; | |
} | |
else | |
{ | |
x = Random.Range (-2.0f, 2.0f); | |
} | |
return new Vector3(x, 0, 8.17f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment