private void AddPlayer(byte playerID) { MultiplayerPlayerController newController = new MultiplayerPlayerController(debugWriter); newController.ConstructFromPlayer(this.ourController); newController.playerID = playerID; otherControllers.Add(newController); }
public void LoadFromFileMainThread(MultiplayerPlayerController controller) { if (useTexture) { debugWriter.WriteLine("LOADING TEXTURE FROM MAIN THREAD"); byte[] data = File.ReadAllBytes(file); texture = new Texture2D((int)size.x, (int)size.y, TextureFormat.RGBA32, false); texture.LoadImage(data); controller.SetPlayerTexture(texture, textureType, useFull); loaded = true; } else if (textureType == MPTextureType.Shirt) { controller.SetPlayerTexture(null, MPTextureType.Shirt, useFull); } }
private void RemovePlayer(int playerID) { int index = -1; for (int i = 0; i < otherControllers.Count; i++) { if (otherControllers[i].playerID == playerID) { index = i; break; } } if (index != -1) { MultiplayerPlayerController controller = otherControllers[index]; otherControllers.RemoveAt(index); Destroy(controller.player); } }
public void ConnectToServer(string serverIP, int port, string user) { if (!this.runningClient) { int i = 0; while (this.debugWriter == null) { string filename = "Multiplayer Debug Client" + (i == 0 ? "" : " " + i.ToString()) + ".txt"; try { this.debugWriter = new StreamWriter(filename); } catch (Exception e) { this.debugWriter = null; i++; } } this.debugWriter.AutoFlush = true; this.debugWriter.WriteLine("Attempting to connect to server ip {0} on port {1}", serverIP, port.ToString()); this.ourController = new MultiplayerPlayerController(debugWriter); this.ourController.ConstructForPlayer(); this.ourController.username = user; this.runningClient = true; MultiplayerUtils.serverMapDictionary.Clear(); client = new NetworkClient(serverIP, port, this, this.debugWriter); FullBodyBipedIK biped = Traverse.Create(PlayerController.Instance.ikController).Field("_finalIk").GetValue <FullBodyBipedIK>(); debugWriter.WriteLine(biped.references.pelvis.name); Transform parent = biped.references.root.parent; while (parent != null) { debugWriter.WriteLine(parent.name); parent = parent.parent; } } }
public void ConstructFromPlayer(MultiplayerPlayerController source) { //Create a new root object for the player this.player = GameObject.Instantiate <GameObject>(ReplayEditor.ReplayEditorController.Instance.playbackController.gameObject); UnityEngine.Object.DontDestroyOnLoad(this.player); this.player.name = "New Player"; this.player.transform.SetParent(null); this.player.transform.position = PlayerController.Instance.transform.position; this.player.transform.rotation = PlayerController.Instance.transform.rotation; debugWriter.WriteLine("Created New Player"); this.replayController = this.player.GetComponentInChildren <ReplayPlaybackController>(); this.bones = replayController.playbackTransforms.ToArray(); //UnityEngine.Object.DestroyImmediate(this.player.GetComponentInChildren<ReplayEditor.ReplayPlaybackController>()); foreach (MonoBehaviour m in this.player.GetComponentsInChildren <MonoBehaviour>()) { if (m.GetType() == typeof(ReplayEditor.ReplayAudioEventPlayer)) { UnityEngine.Object.Destroy(m); } } this.player.SetActive(true); this.board = this.player.transform.Find("Skateboard").gameObject; this.board.transform.position = new Vector3(1111111, 111111111, 11111111); this.board.name = "New Player Board"; this.skater = this.player.transform.Find("NewSkater").gameObject; this.skater.transform.position = new Vector3(1111111, 111111111, 11111111); this.skater.name = "New Player Skater"; this.hips = this.skater.transform.Find("Skater_Joints").Find("Skater_root"); this.skaterMeshesObject = this.skater.transform.Find("Skater").gameObject; debugWriter.WriteLine("created everything"); characterCustomizer.enabled = true; characterCustomizer.RemoveAllGear(); foreach (Transform t in skaterMeshesObject.GetComponentsInChildren <Transform>()) { if (t.gameObject != null) { GameObject.Destroy(t.gameObject); } } debugWriter.WriteLine("Removed gear"); debugWriter.WriteLine(characterCustomizer.ClothingParent.name); debugWriter.WriteLine(characterCustomizer.RootBone.name); characterCustomizer.ClothingParent = this.hips.Find("Skater_pelvis"); characterCustomizer.RootBone = this.hips; Traverse.Create(characterCustomizer).Field("_bonesDict").SetValue(this.hips.GetComponentsInChildren <Transform>().ToDictionary((Transform t) => t.name)); characterCustomizer.LoadCustomizations(PlayerController.Instance.characterCustomizer.CurrentCustomizations); debugWriter.WriteLine("Added gear back"); bool foundHat = false, foundShirt = false, foundPants = false, foundShoes = false; foreach (Tuple <CharacterGear, GameObject> GearItem in gearList) { switch (GearItem.Item1.categoryName) { case "Hat": hatObject = GearItem.Item2; foundHat = true; break; case "Hoodie": shirtObject = GearItem.Item2; foundShirt = true; break; case "Shirt": shirtObject = GearItem.Item2; foundShirt = true; break; case "Pants": pantsObject = GearItem.Item2; foundPants = true; break; case "Shoes": shoesObject = GearItem.Item2; foundShoes = true; break; } } if (!foundHat) { CharacterGear newHat = CreateGear(GearCategory.Hat, "Hat", "PAX_1"); characterCustomizer.LoadGear(newHat); } if (!foundPants) { CharacterGear newPants = CreateGear(GearCategory.Pants, "Pants", "PAX_1"); characterCustomizer.LoadGear(newPants); } if (!foundShirt) { CharacterGear newShirt = CreateGear(GearCategory.Shirt, "Shirt", "PAX_1"); characterCustomizer.LoadGear(newShirt); } if (!foundShoes) { CharacterGear newShoes = CreateGear(GearCategory.Shoes, "Shoes", "PAX_1"); characterCustomizer.LoadGear(newShoes); } this.usernameObject = new GameObject("Username Object"); this.usernameObject.transform.SetParent(this.player.transform, false); this.usernameObject.transform.localScale = new Vector3(-0.01f, 0.01f, 1f); this.usernameObject.AddComponent <MeshRenderer>(); this.usernameObject.GetComponent <MeshRenderer>().material = Resources.FindObjectsOfTypeAll <Font>()[0].material; this.usernameText = this.usernameObject.AddComponent <TextMesh>(); this.usernameText.text = username; this.usernameText.fontSize = 256; this.usernameText.font = Resources.FindObjectsOfTypeAll <Font>()[0]; this.usernameText.color = Color.black; this.usernameText.alignment = TextAlignment.Center; this.shirtMP = new MultiplayerTexture(this.debugWriter, MPTextureType.Shirt); this.pantsMP = new MultiplayerTexture(this.debugWriter, MPTextureType.Pants); this.hatMP = new MultiplayerTexture(this.debugWriter, MPTextureType.Hat); this.shoesMP = new MultiplayerTexture(this.debugWriter, MPTextureType.Shoes); this.boardMP = new MultiplayerTexture(this.debugWriter, MPTextureType.Board); }