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;
        }
    }
Exemplo n.º 2
0
    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;
        }
    }
Exemplo n.º 3
0
    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;
        }
    }
Exemplo n.º 4
0
    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
        }
    }
Exemplo n.º 5
0
    //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;
        }
    }
Exemplo n.º 6
0
    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)
    {
        // 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;
        }
    }
Exemplo n.º 8
0
    //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;
        }
    }
Exemplo n.º 9
0
    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");
        }
    }
Exemplo n.º 10
0
    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();
    }
Exemplo n.º 11
0
    // RoomReceived is called for every room in every updated room list. Parameter room is the room info of the received room.
    private void RoomReceived(Photon.Realtime.RoomInfo room)
    {
        // Find the index of the received room. This will be -1 if the room is not found.
        int index = RoomListingButtons.FindIndex(x => x.m_RoomName == room.Name);

        // Update the local list of room listings and the room listing UI if the room has not yet been received.
        if (index == -1)
        {
            if (room.IsVisible && room.PlayerCount < room.MaxPlayers)
            {
                GameObject roomListingObject = Instantiate(RoomListingPrefab);
                roomListingObject.transform.SetParent(transform, false);

                RoomListing roomListing = roomListingObject.GetComponent <RoomListing>();
                RoomListingButtons.Add(roomListing);

                index = (RoomListingButtons.Count - 1);
            }
        }

        // If the room is already in the local list of room listings, detect if the room has been removed. If the room
        // has been removed, set the updated flag to false, otherwise the room name has been updated so store the new
        // room name and set the updated flag to true.
        if (index != -1)
        {
            RoomListing roomListing = RoomListingButtons[index];
            if (room.RemovedFromList)
            {
                roomListing.m_Updated = false;
            }
            else
            {
                roomListing.SetRoomNameText(room.Name);
                roomListing.m_Updated = true;
            }
        }
    }