// Initialization code void Start() { gameLogic = new GameLogic(DemoGUI.ServerAddress, DemoGUI.AppId, DemoGUI.GameVersion); gameLogic.Start(); // Set the client color float scale = DemoGUI.playgroundScale / this.gameLogic.GridSize; renderer.material.color = DemoGUI.IntToColor(this.gameLogic.LocalPlayer.Color); new Vector3(this.gameLogic.LocalPlayer.PosX * transform.localScale.x + transform.localScale.x / 2, scale / 2, this.gameLogic.LocalPlayer.PosY * transform.localScale.y + transform.localScale.y / 2); }
/// <summary> /// Render cubes onto the scene /// </summary> void RenderPlayers() { float newscale = DemoGUI.playgroundScale / this.logic.localPlayer.GridSize; if (newscale != scaleRatio) { scaleRatio = newscale; SetPlaygroundTexture(); } Vector3 localScale = new Vector3(scaleRatio, scaleRatio, scaleRatio); lock (logic.localPlayer) { foreach (ParticlePlayer p in logic.localPlayer.LocalRoom.Players.Values) { foreach (GameObject cube in logic.cubes) { if (cube.name == p.NickName) { float alpha = 1.0f; if (!p.IsLocal && p.UpdateAge > 500) { cube.GetComponent <Renderer>().material.shader = Shader.Find("Transparent/Diffuse"); alpha = (p.UpdateAge > 1000) ? 0.3f : 0.8f; } cube.transform.localScale = localScale; Color cubeColor = DemoGUI.IntToColor(p.Color); cube.GetComponent <Renderer>().material.color = new Color(cubeColor.r, cubeColor.g, cubeColor.b, alpha); cube.transform.position = new Vector3(p.PosX * localScale.x + localScale.x / 2, scaleRatio / 2, p.PosY * localScale.y + localScale.y / 2); break; } } } } }
void OnGUI() { if (DemoGUI.ShowUserInfo && LocalPlayerJoined()) { // Get 2D coordinates from 3D coordinates of the client Vector3 posVector = Camera.main.WorldToScreenPoint(transform.position); GUIStyle labelStyle = new GUIStyle(); labelStyle.normal.textColor = Color.white; if (name == "Local Player") { labelStyle.fontStyle = FontStyle.Bold; labelStyle.normal.textColor = Color.white; renderer.material.color = DemoGUI.IntToColor(this.gameLogic.LocalPlayer.Color); } else { labelStyle.normal.textColor = Color.gray; } // Output the client's name GUI.Label(new Rect(posVector.x, Screen.height - posVector.y, 100, 20), this.gameLogic.PlayerName, labelStyle); } }