Ejemplo n.º 1
0
    // [Server] enforced with inline code check
    public GameObject SpawnPlayer(NetworkConnection conn, string nick)
    {
        if (!IsServerOrDemo())
        {
            return(null);
        }

        //Debug.LogFormat("Spawning Player with connectionID {0} and nick {1}", conn.connectionId, nick);

        var playerPos = worldBuilder.GetNextPlayerPosition();

        GameObject playerGO = Instantiate(playerPrefab, new Vector3(playerPos.x, 0, playerPos.z), Quaternion.identity);

        if (worldParent != null)
        {
            playerGO.transform.parent = worldParent;
        }

        PlayerController player = playerGO.GetComponent <PlayerController>();

        player.Initialize(conn.connectionId.ToString(), nick, playerColorManager.GetNextColor());

        if (Settings.Debug_PlayerAsAI)
        {
            playerGO.AddComponent <AndreAI>();
        }

        /* NOTE: Always set properties before spawning object, if not there will be a delay before all clients get the values. */
        if (NetworkServer.active)
        {
            NetworkServer.AddPlayerForConnection(conn, playerGO, 0); // playerControllerId is used if multiple players is using one connection
        }
        else
        {
            Debug.LogWarning("NetworkServer not active, it should be when spawning player");
        }

        SpawnObject(cityPrefab, playerPos.x, playerPos.z, player, conn);

        ScenarioSetup.Run(NetworkPanel.instance.GetSelectedScenarioChoice(), conn, player);

        return(playerGO);
    }
Ejemplo n.º 2
0
    public GameObject SpawnAI(string nick)
    {
        Debug.Log("Spawning AI: " + nick);

        var aiPos = worldBuilder.GetNextPlayerPosition();

        GameObject aiPlayerGO = SpawnObject(playerPrefab, aiPos.x, aiPos.z);

        PlayerController player = aiPlayerGO.GetComponent <PlayerController>();

        player.Initialize(nick.Replace(" ", "_"), nick, playerColorManager.GetNextColor());

        SpawnObject(cityPrefab, aiPos.x, aiPos.z, player);

        ScenarioSetup.Run(NetworkPanel.instance.GetSelectedScenarioChoice(), null, player); // A bit dirty atm, sending in the hosting players connection for AIs for spawning.

        aiPlayerGO.AddComponent <AndreAI>();

        return(aiPlayerGO);
    }