示例#1
0
        protected override void OnGamepadPluggedIn(SocketGamepad gamepad)
        {
            //Temporary until Acquire Caleb's menu system to select player


            if (PlayerSpawn.Count > 0)
            {
                //Debug.Log("Next Player: " + NextSpawn.ToString());
                if (NextSpawn < PlayerSpawn.Count)
                {
                    GameObject PlayerObj = PlayerSpawn[NextSpawn].Spawn(PlayerSpawn[NextSpawn].transform.position, PlayerSpawn[NextSpawn].transform.rotation);

                    SurvivorPlayer Player = PlayerObj.AddComponent <SurvivorPlayer>();
                    Player.Gamepad  = gamepad;
                    Player.FyoApp   = this;
                    Player.PlayerId = LocalPlayers.Count;

                    LocalPlayers.Add(Player);
                    ActiveGamepads.Add(gamepad, Player);

                    Framing.TrackedObjects.Add(Player.gameObject);
                }

                //Advance Spawn Point
                if (++NextSpawn >= PlayerSpawn.Count)
                {
                    NextSpawn = 0;
                }
            }
            else
            {
                Debug.LogError("Negative Spawn Index");
            }
        }
        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);
                }
            }
        }
        public override bool ShouldActivateModule()
        {
            if (Gamepad == null)
            {
                Gamepad = GameObject.FindObjectOfType <SocketGamepad>();
            }

            return(base.ShouldActivateModule() || Gamepad != null);
        }
示例#4
0
 protected override void OnGamepadUnplugged(SocketGamepad gamepad)
 {
     if (ActiveGamepads.ContainsKey(gamepad))
     {
         FyoPlayer Player = ActiveGamepads[gamepad];
         ActiveGamepads.Remove(gamepad);
         Destroy(Player.gameObject);
     }
 }
示例#5
0
        protected override void OnGamepadUnplugged(SocketGamepad gamepad)
        {
            SurvivorPlayer Player = (SurvivorPlayer)ActiveGamepads[gamepad];

            Debug.Log("Removing Player " + Player.PlayerId + "(" + gamepad.SGID + ")");
            LocalPlayers.Remove(Player);
            Framing.TrackedObjects.Remove(Player.gameObject);
            ActiveGamepads.Remove(gamepad);

            Destroy(Player.gameObject);
        }
示例#6
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;
            }
        }
示例#7
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;
                }
            }
        }
示例#8
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;
                }
            }
        }
示例#9
0
        protected void SendGameState(SocketGamepad gamepad)
        {
            SGUpdateMsg     GameStateMsg = new SGUpdateMsg();
            TicTacToePlayer tttPlayer    = (TicTacToePlayer)ActiveGamepads[gamepad];

            GameStateMsg.SGID        = tttPlayer.PlayerId;
            GameStateMsg.MessageType = "gamestate";
            GameStateMsg.Data        = new JSONObject();
            JSONObject CellJSON = new JSONObject(JSONObject.Type.ARRAY);

            GameStateMsg.Data.AddField("mark", tttPlayer.Xs ? 1 : 2);
            for (int m = 0; m < 9; m++)
            {
                CellJSON.list.Add(new JSONObject(Grid[m].CurrentMark));
            }
            GameStateMsg.Data.AddField("cells", CellJSON);
            GameStateMsg.Serialize();

            Debug.Log("Sending Game State: " + GameStateMsg.ToString());

            socket.Emit("SGUpdateMsg", GameStateMsg);
        }
示例#10
0
        protected override void OnGamepadPluggedIn(SocketGamepad gamepad)
        {
            if (XPlayer.Gamepad == null)
            {
                XPlayer.Xs      = true;
                XPlayer.FyoApp  = this;
                XPlayer.Gamepad = gamepad;
                XPlayer.PlayerIcon.SetActive(true);
                ActiveGamepads.Add(gamepad, XPlayer);
                XPlayer.InputWait = DateTime.Now.Ticks + (InputWaitMs * TimeSpan.TicksPerMillisecond);
                Debug.Log("X Connected");
            }
            else if (OPlayer.Gamepad == null)
            {
                OPlayer.Xs      = false;
                OPlayer.FyoApp  = this;
                OPlayer.Gamepad = gamepad;
                OPlayer.PlayerIcon.SetActive(true);
                Debug.Log("O Connected");
                ActiveGamepads.Add(gamepad, OPlayer);
                OPlayer.InputWait = DateTime.Now.Ticks + (InputWaitMs * TimeSpan.TicksPerMillisecond);
            }
            else
            {
                //Reconnected?
                if (CurrentMode == CurrentModeType.Playing && (XPlayer.Gamepad == gamepad || OPlayer.Gamepad == gamepad))
                {
                    SendGameState(gamepad);
                }
            }

            if (XPlayer.Gamepad != null && OPlayer.Gamepad != null && CurrentMode == CurrentModeType.WaitForPlayers)
            {
                CurrentMode = CurrentModeType.WaitForReady;
                Debug.Log("Waiting for Players to Ready");
            }
        }
示例#11
0
 protected override void OnGamepadTimingOut(SocketGamepad gamepad)
 {
     //TODO: Show Timing Out
 }
示例#12
0
 protected override void OnGamepadReconnect(SocketGamepad gamepad)
 {
     //TODO: Cancel Timing Out
 }
示例#13
0
 protected override void OnGamepadReconnect(SocketGamepad gamepad)
 {
 }
示例#14
0
 protected override void OnGamepadTimingOut(SocketGamepad gamepad)
 {
     Debug.Log("Timing out " + gamepad.SGID);
 }
示例#15
0
 protected override void OnGamepadReconnect(SocketGamepad gamepad)
 {
     Debug.Log("Reconnected " + gamepad.SGID);
 }
示例#16
0
 protected override void OnGamepadTimingOut(SocketGamepad gamepad)
 {
     gamepad.InputData.Clear();
 }
示例#17
0
 protected override void OnUpdateGamepad(SocketGamepad gamepad)
 {
 }
示例#18
0
 protected override void OnGamepadTimingOut(SocketGamepad gamepad)
 {
 }