Example #1
0
    void Start()
    {
        if (this.AssignFirstPlayerOnStart)
        {
            SessionPlayer p1 = DynamicData.GetSessionPlayer(0);
            if (!p1.HasJoined)
            {
                // Find most recent active input and join p1 with it
                Player lastActive     = null;
                float  lastActiveTime = 0.0f;
                foreach (Player p in ReInput.players.Players)
                {
                    Controller c           = p.controllers.GetLastActiveController();
                    float      cActiveTime = c != null?c.GetLastTimeActive() : lastActiveTime;

                    if (cActiveTime > lastActiveTime || (lastActive == null && (p.controllers.hasMouse || p.controllers.joystickCount != 0)))
                    {
                        lastActiveTime = cActiveTime;
                        lastActive     = p;
                    }
                }

                // Only join if this input isn't already joined with another player
                if (DynamicData.GetSessionPlayerByRewiredId(lastActive.id) == null)
                {
                    joinPlayer(p1, lastActive);
                }
            }
        }

        if (this.DisableMenuInputForUnjoinedPlayers || this.EnableMenuInputForUnjoinedPlayers)
        {
            foreach (Player rewiredP in ReInput.players.Players)
            {
                if (DynamicData.GetSessionPlayerByRewiredId(rewiredP.id) == null)
                {
                    rewiredP.controllers.maps.SetMapsEnabled(this.EnableMenuInputForUnjoinedPlayers, MenuInput.MENU_CATEGORY);
                }
            }
        }
    }