void CreateLocalPlayer() { Participant myself = PlayGamesPlatform.Instance.RealTime.GetSelf(); string id = myself.ParticipantId; Transform spawn = GameObject.Find(Gateway).transform; Vector3 pos = spawn != null ? spawn.position : new Vector3(); GameObject go = Instantiate(playerPrefab, pos, Quaternion.identity); go.GetComponent <PlayerControl>().playerid = id; GPGSyncInstance gPG = go.GetComponent <GPGSyncInstance>(); pcs.Add(go); players[id] = Add(gPG); byte[] msg; byte[] mid = System.Text.Encoding.ASCII.GetBytes(id); msg = new byte[mid.Length + 3]; msg[0] = (byte)MessageType.AddPlayer; msg[1] = (byte)players[id]; msg[2] = (byte)mid.Length; i = 3; foreach (byte b in mid) { msg[i] = b; i++; } PlayGamesPlatform.Instance.RealTime.SendMessageToAll(true, msg); }
public int Add(GPGSyncInstance s, int id = 0) { if (id == 0) { int l = i; while (insts[l] != null) { l++; } insts[l] = s; s.id = l; i++; return(l); } else { if (insts[id] != null) { throw new ArgumentException("Id already taken!"); } insts[id] = s; insts[id].id = id; return(id); } }
void CreatePlayers() { Transform spawn = GameObject.Find(Gateway).transform; Vector3 pos = spawn != null ? spawn.position : new Vector3(); foreach (Participant participant in PlayGamesPlatform.Instance.RealTime.GetConnectedParticipants()) { Vector3 rand = UnityEngine.Random.insideUnitCircle; bool already = false; try { already = insts[players[participant.ParticipantId]] != null; } catch (KeyNotFoundException) { } if (already) { continue; } GameObject go = Instantiate(playerPrefab, pos + rand, Quaternion.identity); go.GetComponent <PlayerControl>().playerid = participant.ParticipantId; GPGSyncInstance gPG = go.GetComponent <GPGSyncInstance>(); players[participant.ParticipantId] = Add(gPG); } }