コード例 #1
0
 private static void UpdateOpponentState(string state)
 {
     PlayerManagement[] playerManagers = FindObjectsOfType <PlayerManagement>();
     foreach (PlayerManagement pm in playerManagers)
     {
         if (pm.role == PlayerRole.Opponent)
         {
             pm.player.state = SNBPlayerState.FromJson(state);
             print("Opponent state updated");
         }
     }
 }
コード例 #2
0
    public void SendPlayerStateToOpponent(SNBPlayerState state)
    {
        if (status == ConnectionState.Connected)
        {
            byte   error;
            byte[] message = Encoding.UTF8.GetBytes("{\"messageType\": \"state\", \"result\": " + state.ToJson() + "}");
            NetworkTransport.Send(hostId, connectionId, channelId, message, message.Length, out error);

            if ((NetworkError)error != NetworkError.Ok)
            {
                print("Error sending message: " + message);
            }
        }
    }
コード例 #3
0
    public static SNBPlayerState FromJson(string json)
    {
        bool            dashing, skipping, blocking, crouching, attacking, grounded;
        float           lastHorizontal, lastVertical;
        List <MoveInfo> currentCombo = new List <MoveInfo>();
        string          comboMovesArrayStr;
        SNBPlayerState  newState = new SNBPlayerState();

        JSONObject obj = new JSONObject(json);

        obj.GetField(out dashing, "dashing", false);
        obj.GetField(out skipping, "skipping", false);
        obj.GetField(out blocking, "blocking", false);
        obj.GetField(out crouching, "crouching", false);
        obj.GetField(out attacking, "attacking", false);
        obj.GetField(out grounded, "grounded", false);
        obj.GetField(out lastHorizontal, "lastHorizontalThrow", 0f);
        obj.GetField(out lastVertical, "lastVerticalThrow", 0f);
        obj.GetField(out comboMovesArrayStr, "currentCombo", null);

        if (comboMovesArrayStr != null)
        {
            JSONObject comboMoves = new JSONObject(comboMovesArrayStr);
            foreach (JSONObject j in comboMoves.list)
            {
                currentCombo.Add(MoveInfo.fromJson(j.ToString()));
            }
        }

        newState.dashing        = dashing;
        newState.skipping       = skipping;
        newState.blocking       = blocking;
        newState.crouching      = crouching;
        newState.attacking      = attacking;
        newState.grounded       = grounded;
        newState.lastHorizontal = lastHorizontal;
        newState.lastVertical   = lastVertical;
        newState.currentCombo   = currentCombo;

        return(newState);
    }
コード例 #4
0
 public void ResetState()
 {
     character = CharacterType.None;
     status    = PlayerStatus.Alive;
     state     = new SNBPlayerState();
 }