protected override void OnGamepadPluggedIn(SocketGamepad gamepad)
        {
            if (!ActiveGamepads.ContainsKey(gamepad))
            {
                GameObject PlayerObj = Instantiate(PlayerPrefab, transform);
                Paddle     Player    = PlayerObj.GetComponent <Paddle>();
                Player.FyoApp   = this;
                Player.Gamepad  = gamepad;
                Player.PlayerId = ActiveGamepads.Count;
                ActiveGamepads.Add(gamepad, Player);

                if (Player.PlayerId < PlayerStart.Count)
                {
                    RectTransform t  = PlayerStart[Player.PlayerId];
                    RectTransform pt = Player.GetComponent <RectTransform>();

                    //Set Player Color
                    UnityEngine.UI.Image PlayerStartImg = PlayerStart[Player.PlayerId].GetComponent <UnityEngine.UI.Image>();
                    UnityEngine.UI.Image PlayerImg      = pt.GetComponent <UnityEngine.UI.Image>();
                    PlayerImg.color = PlayerStartImg.color;

                    pt.position   = t.position;
                    pt.rotation   = t.rotation;
                    pt.localScale = t.localScale;
                    pt.SetParent(transform);

                    SGUpdateMsg ControllerUpdate = new SGUpdateMsg(gamepad);
                    ControllerUpdate.Data = new JSONObject();
                    ControllerUpdate.Data.AddField("MessageType", JSONObject.CreateStringObject("PlayerColor"));
                    ControllerUpdate.Data.AddField("Color", JSONObject.CreateStringObject(PlayerImg.color.ToString()));

                    PlayerStart[Player.PlayerId].gameObject.SetActive(false);
                }
            }
        }
示例#2
0
 protected override void OnGamepadUnplugged(SocketGamepad gamepad)
 {
     if (ActiveGamepads.ContainsKey(gamepad))
     {
         FyoPlayer Player = ActiveGamepads[gamepad];
         ActiveGamepads.Remove(gamepad);
         Destroy(Player.gameObject);
     }
 }
示例#3
0
        protected override void OnUpdateGamepad(SocketGamepad gamepad)
        {
            switch (CurrentMode)
            {
            case CurrentModeType.WaitForPlayers:
                break;

            case CurrentModeType.WaitForReady:
                //Check if player is present
                if (ActiveGamepads.ContainsKey(gamepad))
                {
                    if (DateTime.Now.Ticks > ActiveGamepads[gamepad].InputWait)
                    {
                        if (!ActiveGamepads[gamepad].Ready)
                        {
                            ActiveGamepads[gamepad].Ready = true;
                        }
                    }
                }

                //Check if all players have readied
                if (ActiveGamepads.Values.Count(p => p.Ready) >= 2)
                {
                    StartGame();
                    ActiveGamepads[gamepad].InputWait = DateTime.Now.Ticks + (InputWaitMs * TimeSpan.TicksPerMillisecond);
                }
                break;

            case CurrentModeType.Playing:
                if (ActiveGamepads.ContainsKey(gamepad))
                {
                    TicTacToePlayer player = (TicTacToePlayer)ActiveGamepads[gamepad];
                    if (player.isMyTurn)
                    {
                        for (int b = 0; b < 9; b++)
                        {
                            if (gamepad.GetButton("button " + b.ToString()) && Grid[b].CurrentMark == 0)
                            {
                                ActiveGamepads[gamepad].InputWait = DateTime.Now.Ticks + (InputWaitMs * TimeSpan.TicksPerMillisecond);
                                SetCell(b, player.Xs ? 1 : 2);
                                break;
                            }
                        }
                    }
                }
                break;
            }
        }
示例#4
0
        protected override void OnGamepadUnplugged(SocketGamepad gamepad)
        {
            if (ActiveGamepads.ContainsKey(gamepad))
            {
                //Remove from players
                TicTacToePlayer player = (TicTacToePlayer)ActiveGamepads[gamepad];
                player.PlayerIcon.SetActive(false);
                ActiveGamepads.Remove(gamepad);
                LocalPlayers.Remove(player);
                player.Gamepad = null;

                if (XPlayer.Gamepad == null && OPlayer.Gamepad == null)
                {
                    CurrentMode = CurrentModeType.WaitForPlayers;
                }
            }
        }
示例#5
0
        protected override void OnGamepadPluggedIn(SocketGamepad gamepad)
        {
            if (!ActiveGamepads.ContainsKey(gamepad))
            {
                GameObject      PlayerObj = Instantiate(PlayerPrefab);
                InputTestPlayer Player    = PlayerObj.GetComponent <InputTestPlayer>();
                Player.FyoApp   = this;
                Player.Gamepad  = gamepad;
                Player.PlayerId = ActiveGamepads.Count;
                ActiveGamepads.Add(gamepad, Player);

                if (Player.PlayerId < PlayerStart.Count)
                {
                    Transform t = PlayerStart[Player.PlayerId];
                    Player.transform.position   = t.position;
                    Player.transform.rotation   = t.rotation;
                    Player.transform.localScale = t.localScale;
                }
            }
        }