// when new listing is added, add it to the List of listings and set its info // when listing is removed, destroy it and remove it from the List public override void OnRoomListUpdate(List <RoomInfo> roomList) { foreach (RoomInfo info in roomList) { if (info.RemovedFromList) { // finds listing to remove and removes it from list of rooms and fromt he UI int index = listings.FindIndex(x => x.RoomInfo.Name == info.Name); if (index != -1) { Destroy(listings[index].gameObject); listings.RemoveAt(index); } } else { int index = listings.FindIndex(x => x.RoomInfo.Name == info.Name); if (index == -1) { // creates listing and adds to list of rooms RoomListing listing = Instantiate(roomListing, content); if (listing != null) { listing.SetRoomInfo(info); listings.Add(listing); } } } } }
/// <summary> /// funt to update list of rooms /// </summary> /// <param name="roomList">list of info abt rooms</param> public override void OnRoomListUpdate(List <RoomInfo> roomList) { foreach (RoomInfo info in roomList)//loop through list { //remove from the list if (info.RemovedFromList) { int index = roomListings.FindIndex(x => x.roomInfo.Name == info.Name); //get index if (index != -1) //check for index is not equal to -1 { Destroy(roomListings[index].gameObject); //if not destroy index from list of rooms roomListings.RemoveAt(index); //remove from list } } //add it to the list else { int index = roomListings.FindIndex(x => x.roomInfo.Name == info.Name); //get index if (index == -1) //check to -1 { RoomListing listing = Instantiate(prefabListing, content); //make listing and initialize with newly Instantiated list of prefabs and parent is content if (listing != null) //check listing to null { listing.SetRoom(info); //set room from listing roomListings.Add(listing); //add listing to list of rooms } } } } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { foreach (RoomInfo info in roomList) { //removed from list if (info.RemovedFromList) { int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name); if (index != -1) { Destroy(_listings[index].gameObject); _listings.RemoveAt(index); } } //added to rooms list else { int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name); if (index == -1) { RoomListing listing = Instantiate(_roomListing, _content); if (listing != null) { listing.SetRoomInfo(info); _listings.Add(listing); } } else { //modify listing here. //_listing[index].dowhatever. } } } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { _console.AddText("FIRED ROOM LIST" + X); X++; foreach (RoomInfo info in roomList) { if (info.RemovedFromList) { int index = listings.FindIndex(x => x.RoomInfo.Name == info.Name); Debug.Log("Removed room name " + info.Name); if (index != -1) { //Destroy(listings[index]); listings[index].gameObject.SetActive(false); //Clean up the inactive rooms. Destroy(listings[index].gameObject); listings.RemoveAt(index); } } else { RoomListing listing = Instantiate(_roomListingBtn, _content); if (listing != null) { listing.SetRoomInfo(info); } listings.Add(listing); } } }
void RoomReceived(RoomInfo room) { int index = m_roomListingButtons.FindIndex(x => x.m_roomName == room.Name); if (index == -1) { if (room.IsVisible && room.PlayerCount < room.MaxPlayers && room.PlayerCount > 0) { GameObject roomListingObj = Instantiate(m_roomListingPrefabs); roomListingObj.transform.SetParent(transform, false); RoomListing roomListing = roomListingObj.GetComponent <RoomListing>(); m_roomListingButtons.Add(roomListing); index = (m_roomListingButtons.Count - 1); } } else { if (!(room.IsVisible && room.PlayerCount < room.MaxPlayers && room.PlayerCount > 0)) { RoomListing roomListing = m_roomListingButtons[index]; roomListing.m_updated = false; } } if (index != -1 && room.PlayerCount > 0) { RoomListing roomListing = m_roomListingButtons[index]; roomListing.SetRoomNameText(room.Name); roomListing.SetNumPlayerText(room.PlayerCount.ToString() + "/" + room.MaxPlayers.ToString()); roomListing.SetNumKillText(room.CustomProperties["NumKill"].ToString()); roomListing.m_updated = true; } }
private void RoomReceived(RoomInfo room) { string roomName = (string)room.CustomProperties["Name"]; //find the room in PhotonNetwork //find the room index which the room.name(PhotonNetwork) matchs RoomListingButtons.RoomName int index = RoomListingButtons.FindIndex(x => x.RoomName == roomName); //if room could not be found(new room) if (index == -1) { if (room.IsVisible && room.PlayerCount < room.MaxPlayers) { GameObject roomListingObj = Instantiate(RoomListingPrefab); roomListingObj.transform.SetParent(transform, false); RoomListing roomListing = roomListingObj.GetComponent <RoomListing>(); //add the roomListing to the RoomListingButtons RoomListingButtons.Add(roomListing); index = (RoomListingButtons.Count - 1); } } //if room is created, set up the Room name and updated if (index != -1) { int round = (int)room.CustomProperties["Round"]; RoomListing roomListing = RoomListingButtons[index]; roomListing.SetRoomNameText(roomName, room.PlayerCount, room.MaxPlayers, room.Name, round); roomListing.Updated = true; } }
private void RoomReceived(RoomInfo room) { int index = RoomListingButtons.FindIndex(x => x.RoomName == room.Name); if (index == -1) { if (room.IsVisible && room.PlayerCount < room.MaxPlayers) { GameObject roomListingObj = Instantiate(RoomListingPrefab); //Spawns the room prefab, room prefab is the prefab with room name on it roomListingObj.transform.SetParent(transform, false); //Sets the parent of the room prefab RoomListing roomListing = roomListingObj.GetComponent <RoomListing>(); RoomListingButtons.Add(roomListing); // Attaches the room listing script to it index = (RoomListingButtons.Count - 1); //Sets index to room count -1 cause array start 0 } } if (index != -1) //If the room is spawned { RoomListing roomListing = RoomListingButtons[index]; roomListing.SetRoomNameText(room.Name); //Sets the name of the room roomListing.Updated = true; //Updates the room } }
//helper method for OnReceivedRoomListUpdate() //This method will check if the room already exist. If it does, it will just update necessary values // otherwise it will just ignore private void RoomReceived(RoomInfo room) { //takes all scripts in RoomListingButtons List and compare their RoomName and if they equal roon.Name int index = RoomListingButtons.FindIndex(x => x.RoomName == room.Name); //if not same, index returns -1 //if roombutton could not be found, create button for the room if (index == -1) { if (room.IsVisible && room.PlayerCount < room.MaxPlayers) { GameObject roomListingObj = Instantiate(RoomListingPrefab); roomListingObj.transform.SetParent(transform, false); RoomListing roomListing = roomListingObj.GetComponent <RoomListing> (); RoomListingButtons.Add(roomListing); index = (RoomListingButtons.Count - 1); //set index to the index of the added butto } } //if roombuttn already exists if (index != -1) { RoomListing roomListing = RoomListingButtons [index]; roomListing.SetRoomNameText(room.Name); //just changing the available roomname roomListing.Updated = true; } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { foreach (RoomInfo info in roomList) { if (info.RemovedFromList || info.MaxPlayers == info.PlayerCount) { DestroyRoomListing(info); } else { int index = listings.FindIndex(x => x.RoomInfo.Name == info.Name); if (index == -1) { RoomListing listing = Instantiate(roomListing, content); if (listing != null) { listing.SetRoomInfo(info); listings.Add(listing); } } else { listings[index].SetRoomInfo(info); } } } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { foreach (RoomInfo info in roomList) { // removed from room list if (info.RemovedFromList) { int index = _listings.FindIndex(i => i.RoomInfo.Name == info.Name); if (index != -1) { Destroy(_listings[index].gameObject); _listings.RemoveAt(index); } } else // added in the list { RoomListing listing = Instantiate(roomListing, container) as RoomListing; if (listing != null) { listing.SetRoomInfo(info); _listings.Add(listing); } } } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { if (hover != null) { hover.DetachChildren(); } listings.Clear(); for (int i = 0; i < roomList.Count; i++) { if (roomList[i].RemovedFromList) { int index = listings.FindIndex(x => x.RoomInfo.Name.Equals(roomList[i])); if (index != -1) { Destroy(listings[index].gameObject); listings.RemoveAt(index); } } else { RoomListing listing = Instantiate(roomListing, hover); if (listing != null) { listing.RoomInfo = roomList[i]; listings.Add(listing); } } } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { //for(int i = 0; i < roomList.Count;i++) //{ // if(roomList[i] == roomList[i+1]) // { // roomList.RemoveAt(i + 1); // } //} foreach (RoomInfo info in roomList) { //remove from room list int index = listings.FindIndex(x => x.RoomInfo.Name == info.Name); if (index != -1) { Destroy(listings[index].gameObject); listings.RemoveAt(index); } if (!info.RemovedFromList) { RoomListing listing = Instantiate(roomListing, content); if (listing != null) { //Debug.Log(info.ToStringFull()); listing.SetRoomInfo(info); listings.Add(listing); } } } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { foreach (RoomInfo roomInfo in roomList) { int index = listings.FindIndex(x => x.RoomInfo.Name == roomInfo.Name); if (roomInfo.RemovedFromList) { if (index != -1) { Destroy(listings[index].gameObject); listings.RemoveAt(index); } } else { if (index == -1 && NetworkManager.GetRoomType(roomInfo) == '%') { RoomListing listing = Instantiate(roomListing, content); if (listing != null) { listing.SetRoomInfo(roomInfo); listings.Add(listing); } } } } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { foreach (RoomInfo info in roomList) { //Removed from rooms list. if (info.RemovedFromList) { int index = _listing.FindIndex(x => x.RoomInfo.Name == info.Name); if (index != -1) { Destroy(_listing[index].gameObject); _listing.RemoveAt(index); } } //Added to rooms list. else { int index = _listing.FindIndex(x => x.RoomInfo.Name == info.Name); if (index == -1) { RoomListing listing = (RoomListing)Instantiate(_roomListPrefab, _content); if (listing != null) { listing.SetRoomInfo(info); _listing.Add(listing); } } else { } } } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { foreach (RoomInfo info in roomList) { //Salas Removidas da Lista if (info.RemovedFromList) { int index = _listing.FindIndex(x => x.RoomInfo.Name == info.Name); if (index != -1) { Destroy(_listing[index].gameObject); _listing.RemoveAt(index); } } //Salas adicionadas da lista else { RoomListing listing = Instantiate(roomListing, content); if (listing != null) { listing.SetRoom(info); _listing.Add(listing); } } } }
//Update any rooms listings, add room listings private void RoomReceived(RoomInfo room) { //does the button already exist? int index = RoomListingButtons.FindIndex(x => x.RoomName == room.Name); //it's going to look through all the room names and compare it. //if it finds a match, it will return a value other than -1 //if it returns -1 it could not be found if (index == -1) { //create button and add it to the list if (room.IsVisible && room.PlayerCount < room.MaxPlayers) //check for invisible rooms and full rooms { GameObject roomListingObj = Instantiate(RoomListingPrefab); roomListingObj.transform.SetParent(transform, false); //setting the parent of the object we just made to the transform of the owner of this script //so it aligns RoomListing roomListing = roomListingObj.GetComponent <RoomListing>(); RoomListingButtons.Add(roomListing); index = (RoomListingButtons.Count - 1); //updates the creation in the list } } if (index != -1) { RoomListing roomListing = RoomListingButtons[index]; //pull it from the index that it found earlier Debug.Log(room.Name); roomListing.SetRoomNameText(room.Name); //update the name, it may have changed roomListing.Updated = true; } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { foreach (RoomInfo info in roomList) { //Removed from room list if (info.RemovedFromList) { int index = listings.FindIndex(x => x.RoomInfo.Name == info.Name); if (index != -1) { Destroy(listings[index].gameObject); listings.RemoveAt(index); } } //Added to room list else { int index = listings.FindIndex(x => x.RoomInfo.Name == info.Name); if (index == -1) { RoomListing listing = Instantiate(roomListing, content); if (listing != null) { listing.SetRoomInfo(info); listings.Add(listing); } } else { //modify listing here //ex.. listings[index].doWhatever } } } }
private void RoomReceived(RoomInfo room) { int index = RoomListingButtons.FindIndex(x => x.RoomName == room.Name); if (index == -1) { if (room.IsVisible && room.PlayerCount < room.MaxPlayers) { GameObject roomListingObj = Instantiate(RoomListingPrefab); roomListingObj.transform.SetParent(transform, false); RoomListing roomListing = roomListingObj.GetComponent <RoomListing>(); RoomListingButtons.Add(roomListing); index = (RoomListingButtons.Count - 1); } } if (index != -1) { RoomListing roomListing = RoomListingButtons[index]; roomListing.SetRoomNameText(room.Name); roomListing.Updated = true; } }
private void RemoveOldRooms() { print("RemoveOldRooms Called"); List <RoomListing> removeRooms = new List <RoomListing>(); foreach (RoomListing rl in RoomListings) { if (!rl.Updated) { removeRooms.Add(rl); } else { rl.Updated = false; } } int roomCount = removeRooms.Count; while (removeRooms.Count > 0 || roomCount > 0) { roomCount--; RoomListing temp = removeRooms[removeRooms.Count - 1]; if (temp != null) { removeRooms.Remove(temp); Destroy(temp.gameObject, 0.1f); } } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { foreach (RoomInfo info in roomList) { // Removed from rooms list if (info.RemovedFromList || !info.IsOpen) { int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name); if (index != -1) { Destroy(_listings[index].gameObject); _listings.RemoveAt(index); } } // Added to roooms list else { int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name); if (index == -1) { RoomListing listing = Instantiate(_roomListing, _content); if (listing != null) { listing.SetRoomInfo(info); _listings.Add(listing); } } else { // we can modify a listing here (a listed room) // _listings[index].whatever so .modify or whatever } } } }
private void RoomReceived(RoomInfo room) { int index = RoomListingButtons.FindIndex(x => x.RoomName == room.Name); //room不存在 index=-1 if (index == -1) { if (room.IsVisible && room.PlayerCount < room.MaxPlayers) { GameObject roomItem = create(); RoomListing rlScripts = roomItem.GetComponent <RoomListing>(); RoomListingButtons.Add(rlScripts);//把新房间上的脚本 index = RoomListingButtons.Count - 1;//更新新创建房间的index为最后一个 } } if (index != -1) { //获取已存在的房间脚本 RoomListing roomListing = RoomListingButtons[index]; roomListing.SetRoomNameText(room.Name); roomListing.Updated = true; } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { foreach (RoomInfo info in roomList) { if (info.RemovedFromList) { int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name); if (index != -1) { Destroy(_listings[index].gameObject); _listings.RemoveAt(index); } } else { int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name); if (index == -1) { RoomListing listing = Instantiate(_roomListing, _content); if (listing != null) { listing.SetRoomInfo(info); _listings.Add(listing); } } else { } } } }
private void RoomReceived(RoomInfo room) { // searches RoomListingButtons to see if any existing rooms match the room received's Name // returns -1 if no existing rooms match, returns another number if they do match int index = RoomListingButtons.FindIndex(x => x.RoomName == room.Name); // if the room received does not yet exist if (index == -1) { if (room.IsVisible && room.PlayerCount < room.MaxPlayers) { GameObject roomListingObj = Instantiate(RoomListingPrefab); roomListingObj.transform.SetParent(transform, false); RoomListing roomListing = roomListingObj.GetComponent <RoomListing>(); RoomListingButtons.Add(roomListing); index = (RoomListingButtons.Count - 1); } } // if the room received does exist if (index != -1) { // update the name RoomListing roomListing = RoomListingButtons[index]; roomListing.SetRoomNameText(room.Name); roomListing.Updated = true; } }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { for (int i = 0; i < roomList.Count; i++) { RoomInfo info = roomList[i]; RoomListing listing = Instantiate(_roomListing, _content); if (listing) { listing.SetRoomInfo(info); } } }
private void RoomReceived(RoomInfo room) { // ตรวจสอบindex ของชื่อห้องที่สร้าง กับ ชื่อของห้องในListตัวปัจจุบันที่รับค่ามาจากPhoton ที่ตรงกัน แล้วนำมาเก็บไว้ยังตัวแปร index ที่สร้างขึ้น(ค้นหาห้องในlist) int index = RoomListingButtons.FindIndex(x => x.RoomName == room.Name); // หากindex ที่ได้มีค่าเป็น -1 หมายความว่า ห้องนั้นอาจสร้างขึ้นมาแล้ว แต่ยังไม่มีตัวแสดงผลห้องบนหน้าListingRoomLayout จึงต้องทำการดึงprefabที่เราได้สร้างไว้มาเป็นตัวแทนหรือ // ส่วนแสดงผลที่ทำให้ตามนุษย์มองเห็นและ เข้าใจตรงกันว่ามีห้องนั้นถูกสร้างขึ้น // (ส่วนAdd) if (index == -1) { // หากห้องสามารถมองเห็นได้ และ ผู้เล่นปัจจุบันในห้องนั้นๆ ไม่เกินจำนวนผู้เล่นสูงสุดต่อห้อง ให้เข้าไปทำงานคำสั่งด้านล่าง if (room.IsVisible && room.PlayerCount < room.MaxPlayers) { // ทำการสร้าง GameObj ที่เป็นRoomListingPrefab เผื่อไว้ใช้สำหรับการSetParent หรือปรับค่าอื่นๆเท่าที่GameObjectสามารถทำได้ GameObject roomListingObj = Instantiate(RoomListingPrefab); roomListingObj.transform.SetParent(transform, false); // ทำการสร้าง RoomListing แล้วเข้าถึงComponent RoomListing เพื่อใช้ในการเพิ่ม เข้าList สำหรับนำListตัวนั้นๆมาดำเนินการต่อไป RoomListing roomListing = roomListingObj.GetComponent <RoomListing>(); RoomListingButtons.Add(roomListing); // index คือตัวบ่งชี้ .count คือตัวบ่งบอกจำนวนที่มี ดังนั้นจำนวนที่บ่งบอกว่ามีอยู่จึงถูกกำหนดไว้ที่ 1 ตัวบ่งชี้จึงเริ่มที่ค่า 1 โดยมีindex 0 บ่งบอกถึงตัวเริ่มต้น index = (RoomListingButtons.Count - 1); print("RoomReceived[" + index + "] : " + "Add"); } } // หากindex ที่ได้มีค่าที่ไม่ใช่ -1 หมายความว่าเป็นได้ทั้ง มีค่ามากกว่า หรือน้อยกว่า แต่ในกรณีที่ไม่มีค่าที่ตรงกันในunityจะถูกมองเป็น -1 เสมอ // ดังนั้น index ในกรณีนี้จึงต้องเป็นค่าที่มากกว่า -1 ซึ่งมีความหมายว่า อาจมีห้องนั้นอยู่แล้ว และยังคงอยู่จนกระทั่งเงื่อนไขนี้ตรวจสอบมันเจอ ก็ให้มันเข้าไปทำงานคำสั่งด้านล่างต่อไป // (ส่วนUpdated) if (index != -1) { // ทำการสร้าง RoomListing โดยให้ตัวมันมีค่าเท่ากับ index // ดังนั้นจึงกำหนดให้ชื่อของห้องที่สร้างขึ้นแล้ว ตรงกับชื่อที่photonตรวจสอบ เนื่องจากในอนาคตอาจมีการเปลี่ยนแปลงชื่อทำให้ชื่อห้องที่สร้างไม่ตรงกับชื่อห้องที่photonตรวจพบ // จึงให้ระบบอัพเดต การเปลี่ยนชื่อ หรือ จำนวนผู้เล่นตลอดเวลา หากผู้เล่นภายในห้อง หรือชื่อของห้องมีการเปลี่ยนแปลงในภายหลัง RoomListing roomListing = RoomListingButtons[index]; roomListing.SetRoomNameText(room.Name); GameObject roomListingObj = roomListing.gameObject; roomListingObj.transform.GetChild(3).GetComponent <TextMeshProUGUI>().text = "Players in Room : " + room.PlayerCount + " / " + room.MaxPlayers; for (int i = 0; i < room.PlayerCount; i++) { roomListingObj.transform.GetChild(4).transform.GetChild(i).GetComponent <Image>().color = Color.white; if (room.PlayerCount < room.MaxPlayers) { for (int j = room.PlayerCount; j < room.MaxPlayers; j++) { roomListingObj.transform.GetChild(4).transform.GetChild(j).GetComponent <Image>().color = Color.black; } } } roomListing.Updated = true; print("RoomReceived[" + index + "] : " + "Updated"); } }
private void RoomReceived(RoomInfo room) { GameObject roomListingObj = Instantiate(_roomListingPrefab); roomListingObj.transform.SetParent(transform, false); RoomListing roomListing = roomListingObj.GetComponent <RoomListing>(); roomListing.SetRoomNameText(room.Name); roomListing.SetNumberOfOccupants(room); _roomListingPanel.Add(roomListing); ClearRoomListingPanel(); }
private void AddRoomListing(RoomInfo info) { int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name);//x is some element in the _listings list. if (index == -1) { RoomListing listing = Instantiate(_roomListing, _content); if (listing != null) { listing.SetRoomInfo(info);//Update the text on the Room Listing _listings.Add(listing); } } }
private void Start() { if (_fakeRooms) { for (int x = 0; x < _numFakeRooms; x++) { RoomListing listing = Instantiate(_roomListingBtn, _content); if (listing != null) { listing.SetFakeRoomInfo("Room " + x.ToString(), Random.Range(2, 10)); } listings.Add(listing); } } }
private void CreateRoomListing(RoomInfo roomInfo) { GameObject roomListing = Instantiate(roomListingTemplate.gameObject) as GameObject; roomListing.transform.SetParent(roomListingContainer, false); roomListing.gameObject.SetActive(true); RoomListing roomScript = roomListing.GetComponent <RoomListing>(); roomScript.Initialize(roomInfo.Name, this); roomScript.ShowOccupants(roomInfo.PlayerCount); allRooms.Add(roomScript); }
public override void OnRoomListUpdate(List <RoomInfo> roomList) { foreach (RoomInfo roomInfo in roomList) { if (roomListings.FirstOrDefault(x => x.roomInfo.Equals(roomInfo)) == null) { if (!roomInfo.RemovedFromList && roomInfo.PlayerCount != roomInfo.MaxPlayers) { RoomListing rL = basePool.TakeObject().GetComponent <RoomListing>(); rL.Init(roomInfo, this, basePool, mainMenuController); roomListings.Add(rL); } } } roomListings.RemoveAll(x => x.roomInfo.RemovedFromList); roomListings.RemoveAll(x => x.roomInfo.PlayerCount == x.roomInfo.MaxPlayers); roomListings.ForEach((roomListing) => { roomListing.Refresh(); }); }