public void                                    AddToServerList(string strServerName, NetworkID networkID, bool blnPrivate, int intMax, int intCur)
    {
        int c = ListContainer.transform.childCount;

        // CREATE THE NEW SERVER INFORMATION UI PREFAB.  POPULATE IT WITH THE SERVER INFORMATION
        GameObject   go  = (GameObject)Instantiate(ServerInformationUIprefab);
        ServerInfoUI sui = go.GetComponent <ServerInfoUI>();

        sui.ServerName       = strServerName;
        sui.ServerNetworkID  = (ulong)networkID;
        sui.PasswordRequired = blnPrivate;
        sui.MaxPlayers       = intMax;
        sui.CurPlayers       = intCur;

        // ADD THE UI ELEMENT TO THE LIST CONTAINER. PLACE IT IN THE RIGHT Y-POSITION PLACE.
        go.name = strServerName;
        go.transform.SetParent(ListContainer.transform);
        Vector3 v3 = Vector3.zero;

        v3.x = 0;
        v3.y = (c * 83) + 3;
        go.GetComponent <RectTransform>().localPosition = v3;

        // RESCALE THE LISTCONTAINER TO ENCOMPASS ALL THE SERVER ELEMENTS
        v3   = ListContainer.transform.GetComponent <RectTransform>().sizeDelta;
        v3.y = ((c + 1) * 86) + 3;
        ListContainer.transform.GetComponent <RectTransform>().sizeDelta = v3;
    }
Exemplo n.º 2
0
    public void PurchaseServer()
    {
        // If we can't afford this server, back out. Also give a warning/error message
        if (!GameManager.gameManager.MakePurchase(UpfrontCost))
        {
            GameManager.gameManager.ShowDialogueBox("You do not have enough money to make this purchase!", "Error");
            return;
        }

        // We're purchasing the server! Here, we're going to instantiate the server from the prefab and make it a child
        // of the "Servers" parent to keep things tidy.
        var newServer       = Instantiate(serverPrefab, Vector2.zero, Quaternion.identity, serverParent.transform) as GameObject;
        var serverComponent = newServer.GetComponent <Server>();

        serverComponent.hostname      = hostname.text;
        serverComponent.serverChassis = GameManager.gameManager.allServerChassis[serverEnclosureDropdown.value];
        serverComponent.processor     = GameManager.gameManager.allCpus[cpuDropdown.value];
        serverComponent.software      = GameManager.gameManager.allSoftware[softwareDropdown.value];

        serverComponent.originalServerCost = UpfrontCost;
        serverComponent.originalBuildDate  = GameManager.gameManager.GetCurrentGameDate();
        serverComponent.serverType         = GameManager.gameManager.allServerTypes[serverTypeDropdown.value];

        serverComponent.acceptCustomers = true;

        for (int i = 1; i <= (hardDriveCapacityDropdown.value + 1); i++)
        {
            serverComponent.hardDrives.Add(GameManager.gameManager.allStorageDrives[hardDriveDropdown.value]);
        }

        // Adding it to our GameManager.gameManager (Or is this necessary?)
        GameManager.gameManager.servers.Add(serverComponent);
        CloseForm();

        ServerInfoUI sui = FindObjectOfType <ServerInfoUI>();

        sui.UpdateServerInfoDisplay();
    }