public async void LoadOngoingRooms()
    {
        List <GameRoom> roomResponse = await api.GetOngoingRooms();

        // Destroy all existing rooms.
        GameRoomButton[] existingButtons = FindObjectsOfType <GameRoomButton>();
        foreach (GameRoomButton gameRoomButton in existingButtons)
        {
            Destroy(gameRoomButton.gameObject);
        }

        foreach (GameRoom room in roomResponse)
        {
            // Create a new templated item
            GameRoomButton scrollItem = (GameRoomButton)Instantiate(scrollItemTemplate);
            scrollItem.gameObject.SetActive(true);
            scrollItem.room = room;
            scrollItem.GetComponent <Button>().onClick.AddListener(delegate { GoToGame(room); });

            // Set the text
            Text text = scrollItem.GetComponentInChildren <Text>();
            if (text != null)
            {
                text.text = "[ GameId: " + room.RoomId + " Title: " + room.Description + ", Seed: " + room.Seed + ", Players: " + room.Players.Count + "/" + room.MaxPlayers + ", Anonymous: " + room.Anonimity + ", Created By: " + room.CreatorId + "]";
            }
            else
            {
                Debug.Log("No Text.");
            }

            // Set the button's parent to the scroll item template.
            scrollItem.transform.SetParent(scrollItemTemplate.transform.parent, false);
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        MapConfiguration mapConfiguration = new MapConfiguration(players);

        mapConfiguration.Seed = 123123;
        mapConfiguration.DormantsPerPlayer       = 3;
        mapConfiguration.MaxiumumOutpostDistance = 130;
        mapConfiguration.MinimumOutpostDistance  = 30;
        mapConfiguration.OutpostsPerPlayer       = 3;


        GameConfiguration config = new GameConfiguration(players, DateTime.Now, mapConfiguration);

        Dictionary <String, GameConfiguration> puzzleList = new Dictionary <string, GameConfiguration>();

        puzzleList.Add("SampleGameNoNetwork", config);


        foreach (var puzzle in puzzleList)
        {
            // Create a new templated item
            GameRoomButton scrollItem = (GameRoomButton)Instantiate(scrollItemTemplate);
            scrollItem.gameObject.SetActive(true);
            scrollItem.GetComponent <Button>().onClick.AddListener(delegate { GoToGameLobby(puzzle.Value); });

            // Set the text
            Text text = scrollItem.GetComponentInChildren <Text>();
            text.text = puzzle.Key;

            // Set the button's parent to the scroll item template.
            scrollItem.transform.SetParent(scrollItemTemplate.transform.parent, false);
        }
    }
Exemple #3
0
    public async void LoadOpenRooms()
    {
        var roomResponse = client.GetOpenLobbies(new OpenLobbiesRequest());

        // Destroy all existing rooms.
        GameRoomButton[] existingButtons = FindObjectsOfType <GameRoomButton>();
        foreach (GameRoomButton gameRoomButton in existingButtons)
        {
            if (gameRoomButton.isActiveAndEnabled)
            {
                Destroy(gameRoomButton);
            }
        }

        if (roomResponse.Status.IsSuccess)
        {
            foreach (Room room in roomResponse.Rooms)
            {
                // Create a new templated item
                GameRoomButton scrollItem = (GameRoomButton)Instantiate(scrollItemTemplate);
                scrollItem.gameObject.SetActive(true);
                scrollItem.room = room;
                // scrollItem.GetComponent<Button>().onClick.AddListener(delegate { GoToGameLobby(room); });

                foreach (Transform child in scrollItem.transform)
                {
                    child.gameObject.SetActive(true); // or false
                }

                // Set the text
                Text text = scrollItem.GetComponentInChildren <Text>();
                text.gameObject.SetActive(true);
                if (text != null)
                {
                    text.text = "[ GameId: " + room.RoomId + " Title: " + room.RoomName + ", Seed: " + room.Seed +
                                ", Players: " + room.Players.Count + "/" + room.MaxPlayers + ", Anonymous: " +
                                room.Anonymous + ", Created By: " + room.Creator.Username + "]";
                }
                else
                {
                    Debug.Log("No Text.");
                }

                // Set the button's parent to the scroll item template.
                scrollItem.transform.SetParent(scrollItemTemplate.transform.parent, false);
            }

            // TODO: Add some text to notify user they are offline.
        }
    }
 public void GoToRoomPanel()
 {
     SwitchToPanel(RoomPanel);
     GameRoomButton.GetComponent <Button>().Select();
 }