// Start is called before the first frame update
 public override void Start()
 {
     try
     {
         dataHandler = GameObject.Find("NetworkDataHandler").GetComponent(typeof(NeonHeightsDataHandler)) as NeonHeightsDataHandler;
         dataHandler.SetNetworkManager(this);
     } catch (Exception e)
     {
         dataHandler = null;
     }
     print("dataHandler: " + dataHandler);
     base.Start(); // this starts the server on the NetworkManager base class
 }
Ejemplo n.º 2
0
    //Pregame Lobby

    // Start is called before the first frame update
    void Start()
    {
        DontDestroyOnLoad(this.gameObject);
        playerCursors = new List <PlayerLobbyCursor>();
        players       = new List <NeonHeightsPlayer>();
        numGamePads   = 0;
        numKeyboards  = 0;
        dataHandler   = GameObject.FindObjectOfType <NeonHeightsDataHandler>();
        SceneManager.activeSceneChanged += OnSceneChanged;
        gameStarted    = false;
        playersCanMove = false;
        if (!isLocalPlayer)
        {
            return;
        }

        deviceList = new Dictionary <int, InputDevice>();

        if (dataHandler.playerConnectionIDs.Count > 0)
        {
            connectionId = dataHandler.playerConnectionIDs[dataHandler.playerConnectionIDs.Count - 1];
        }
        else
        {
            connectionId = 0;
        }

        dataHandler.setConnectionId(connectionId);
        dataHandler.SetLocalClient(this);
        // This might create an issue if two clients are added at almost the same time, but it also might be fine, I think it depends on what order the Start methods are called by unity
        //compared to when the datahandler adds conn ids
        print("My connection ID is " + connectionId);

        // a good way to go would be to have like the data handler store which connection ID each player belongs to and then the client
        // could easily see which data belongs to it because it can see all the data in the datahandler and it knows its
        // own connection id
        // at the start of the game scene, if each client instantiates its own characters inside this script, they
        // will all have proper network authority no questions asked but a better way might be to instantiate
        //inside of the networkmanager and then assign client authority, depending on what we can get to work

        anyButtonPressedGamePad            = new InputAction(binding: "/<Gamepad>/buttonSouth");
        anyButtonPressedGamePad.performed += ctx => OnPlayerJoined(1);
        anyButtonPressedGamePad.Enable();

        anyButtonPressedKeyboard            = new InputAction(binding: "/<Keyboard>/Enter");
        anyButtonPressedKeyboard.performed += ctx => OnPlayerJoined(0);
        anyButtonPressedKeyboard.Enable();
    }
    public override void OnServerAddPlayer(NetworkConnection conn)
    {
        if (dataHandler == null)
        {
            print("looking for datahandler");
            dataHandler = GameObject.Find("NetworkDataHandler").GetComponent(typeof(NeonHeightsDataHandler)) as NeonHeightsDataHandler;
            dataHandler.SetNetworkManager(this);
        }

        Transform  startPos = base.GetStartPosition();
        GameObject player   = startPos != null
            ? Instantiate(playerPrefab, startPos.position, startPos.rotation)
            : Instantiate(playerPrefab);

        NetworkServer.AddPlayerForConnection(conn, player);
        player.GetComponent <NeonHeightsLobbyClient2>().connectionId = conn.connectionId;
        player.GetComponent <NeonHeightsLobbyClient2>().serverTest(conn.connectionId);

        print("connectionID's Updated on server");
        AddPlayerData(conn.connectionId);
    }