コード例 #1
0
ファイル: DemoGame.cs プロジェクト: j-funk/InputSystem
    /// <summary>
    /// Called when a player that has joined the game indicates that he/she is ready to
    /// start the game. When all players have indicated readiness, the game starts.
    /// </summary>
    /// <param name="player"></param>
    /// <seealso cref="DemoPlayerController.State.Ready"/>
    public void OnPlayerIsReady(DemoPlayerController player)
    {
        Debug.Assert(m_ActivePlayerCount >= 1, "Must have at least one player");
        Debug.Assert(player != null);
        Debug.Assert(player.state == DemoPlayerController.State.Ready, "Player has not indicated readiness");
        Debug.Assert(state == State.InLobby, "Can only launch into the game from the lobby");

        // See if all players have indicated they're ready.
        for (var i = 0; i < m_ActivePlayerCount; ++i)
        {
            if (!m_Players[i].isReady)
            {
                // No, still some players that have joined but are not ready yet.
                return;
            }
        }

        // Yes, all players are ready. Start the game.
        if (m_ActivePlayerCount == 1)
        {
            ChangeState(State.InSinglePlayerGame);
        }
        else
        {
            ChangeState(State.InMultiPlayerGame);
        }
    }
コード例 #2
0
    public void TearDown()
    {
        // It looks like the test runner is stupidly reusing test fixture instances instead of
        // creating a new object for every run. So we really have to clean up well.

        game.players.Each(UnityEngine.Object.DestroyImmediate);
        UnityEngine.Object.DestroyImmediate(game.gameObject);

        DemoPlayerController.ClearUIHintsCache();

        input.TearDown();

        game  = null;
        input = null;

        mouse           = null;
        keyboard        = null;
        touchscreen     = null;
        gamepad         = null;
        ps4Gamepad      = null;
        xboxGamepad     = null;
        joystick        = null;
        pen             = null;
        gyro            = null;
        hmd             = null;
        leftHand        = null;
        rightHand       = null;
        steamController = null;
    }
コード例 #3
0
    void Initialize()
    {
        actions    = character.GetComponent <DemoActions> ();
        controller = character.GetComponent <DemoPlayerController> ();

        foreach (DemoPlayerController.Arsenal a in controller.arsenal)
        {
            CreateWeaponButton(a.name);
        }

        CreateActionButton("Stay");
        CreateActionButton("Walk");
        CreateActionButton("Run");
        CreateActionButton("Sitting");
        CreateActionButton("Jump");
        CreateActionButton("Aiming");
        CreateActionButton("Attack");
        CreateActionButton("Damage");
        CreateActionButton("Death Reset", "Death");

        cameras = GameObject.FindObjectsOfType <Camera> ();
        var sort = from s in cameras orderby s.name select s;

        foreach (Camera c in sort)
        {
            CreateCameraButton(c);
        }

        camerasPanel.GetChild(0).GetComponent <Button>().onClick.Invoke();
    }
コード例 #4
0
ファイル: DemoGame.cs プロジェクト: j-funk/InputSystem
 /// <summary>
 /// Called when a player selects the "Exit" menu item in the player's own menu.
 /// </summary>
 /// <param name="player">Player that chose to leave the game.</param>
 /// <remarks>
 /// If the last player that's in the game chooses to leave, the game ends without an end-game
 /// screen. Instead, it goes straight back to the main menu.
 /// </remarks>
 public void OnPlayerLeaves(DemoPlayerController player)
 {
     if (state == State.InLobby)
     {
         ////TODO
     }
     else
     {
         Debug.Assert(isInGame, "Must be in game or lobby for players to leave");
         ////TODO
     }
 }
コード例 #5
0
    public void Click(string button, DemoPlayerController player = null)
    {
        if (player != null)
        {
            throw new NotImplementedException();
        }

        ////TODO: drive this from a mouse input event so that we cover the whole UI action setup, too
        var buttonObject = GameObject.Find(button);

        Assert.That(buttonObject != null);
        buttonObject.GetComponent <Button>().onClick.Invoke();
    }
コード例 #6
0
    /// <summary>
    /// Create a new player GameObject.
    /// </summary>
    /// <returns></returns>
    private DemoPlayerController SpawnPlayer()
    {
        // If we still have inactive player objects, use those and bring an inactive
        // player back to life.
        DemoPlayerController player = null;

        if (m_Players != null && m_ActivePlayerCount < m_Players.Length && m_Players[m_ActivePlayerCount] != null)
        {
            // Reuse a player we've previously created. Just reactivate it and wipe its state.
            player = m_Players[m_ActivePlayerCount];
            player.gameObject.SetActive(true);
            player.Reset();
        }
        else
        {
            // Otherwise create a new player.
            var playerObject = Instantiate(playerPrefab);
            player = playerObject.GetComponent <DemoPlayerController>();
            if (player == null)
            {
                throw new Exception("Missing DemoPlayerController component on " + playerObject);
            }
            player.PerformOneTimeInitialization(m_ActivePlayerCount == 0);
            player.onLeaveGame = OnPlayerLeavesGame;

            // Add to list.
            if (m_Players == null || m_Players.Length == m_ActivePlayerCount)
            {
                Array.Resize(ref m_Players, m_ActivePlayerCount + 10);
            }
            m_Players[m_ActivePlayerCount] = player;
        }

        // Register as input user with input system.
        InputUser.Add(player);

        ++m_ActivePlayerCount;
        return(player);
    }
コード例 #7
0
ファイル: DemoGame.cs プロジェクト: xuanerbula/InputSystem
 /// <summary>
 /// Called when a player selects the "Exit" menu item in the player's own menu.
 /// </summary>
 /// <param name="player">Player that chose to leave the game.</param>
 /// <see cref="DemoPlayerController.onLeaveGame"/>
 private void OnPlayerLeavesGame(DemoPlayerController player)
 {
     throw new NotImplementedException();
 }