示例#1
0
    //client + server



    /*
     * // Use this for initialization
     * void Start () {
     *  bFormatter = new BinaryFormatter();
     *
     *  //PlayerUpdates testUpdatesIn = new PlayerUpdates(new PlayerInfo[1] { new PlayerInfo(1, 1.1f,2.2f) });
     * // PlayerUpdates testUpdatesOut = (PlayerUpdates)DeserializeClass(SerializeClass(testUpdatesIn));
     *  SerializeBase input;    //send input with udp message
     *  SerializeBase output;   //get output from received udp message
     *
     *  input = new PlayerUpdates(new PlayerInfo[1] { new PlayerInfo(1, 1.1f, 2.2f) });
     *  output = DeserializeClass(SerializeClass(input));
     *
     *  //server + client
     *  HandleSerializedData(output);
     *
     *
     *  // Debug.Log(testUpdatesOut.PlayerInfos[0].playerID);
     *  // PlayerInput testInput = new PlayerInput(0, 1.1f, true, false);
     *  // PlayerInput testOutput = (PlayerInput)DeserializeClass(SerializeClass(testInput));
     * }*/

    //server + client but different
    protected virtual void HandleSerializedData(SerializeBase data)
    {
        //BOTH
        Debug.Log("dont do this pls");
        Type t = data.GetType();


        //SERVER
        //pseudo code:
        //if(t.Equals(typeof(ConnectionInfo)))
        //{
        //ConnectionInfo connectionInfo = (ConnectionInfo)data;
        //if(connectionInfo.requestMatch)
        //{
        //save client data and wait for another client with the same request
        //return;
        //}
        //}


        //CLIENT
        //if(t.Equals(typeof(MatchInfo)))
        //{
        //MatchInfo matchInfo = (MatchInfo)data;
        //if(matchInfo.gameEnd)
        //{
        //get matchInfo.scores
        //goto lobby menu, ready for next match
        //return;
        //}
        //if(matchInfo.playerdied)//do something? TODO design syncing
        //}

        //SERVER
        if (t.Equals(typeof(PlayerInput)))
        {
            //update corresponding player object based on input

            //pseudo code:
            //PlayerInput input = (PlayerInput)data;
            //find player object and execute movement method... players[input.playerid].doMovement(input.xAxis, input.Jump, input.Action);
            //create new PlayerUpdates(input.playerid, new playerInfo(players[input.playerid].tranform.position.x, players[input.playerid].tranform.position.y);
            //serialize PlayerUpdates....
            //send serialized Playerupdates to all (or all other?) clients
        }

        //CLIENT
        if (t.Equals(typeof(PlayerUpdates)))
        {
            //pseudo code:
            //PlayerUpdates updates = (PlayerUpdates)data;
            //for (int i = 0; i < updates.PlayerInfos.Length; i++)
            //{
            //PlayerInfo info = updates.PlayerInfos[i];
            //find player object and execute set position method... players[info.playerID].SetPosition(info.xPos, info.yPos);
            //no need to update server after this
            //}
        }
    }
示例#2
0
    protected override void HandleSerializedData(SerializeBase data)
    {
        //return;
        //Debug.Log("handling data...");
        //Debug.Log("gametimer: " + data.gameTime);
        testFloat = 99;
        if (GameTimer - data.gameTime > (float)Ping / 2000f + 0.01f || GameTimer - data.gameTime < (float)Ping / 2000f - 0.01f)
        {
            GameTimer = data.gameTime + ((float)Ping / 2000f);
        }
        Type t = data.GetType();

        testFloat = 91;
        if (t.Equals(typeof(PlayerUpdates)))
        {
            newUpdates = (PlayerUpdates)data;
            //pseudo code:

            /*
             *    PlayerUpdates updates = (PlayerUpdates)data;
             *    for (int i = 0; i < updates.PlayerInfos.Length; i++)
             *    {
             *    PlayerInfo info = updates.PlayerInfos[i];
             *    GameObject player = Array.Find(players, x => (int)x.playerID == info.playerID).gameObject;
             *    player.transform.position = new Vector3(info.xPos, info.yPos, player.transform.position.z);
             *
             *
             *    //find player object and execute set position method... players[info.playerID].SetPosition(info.xPos, info.yPos);
             *    //no need to update server after this
             *    }
             */
        }
        //CLIENT
        //if(t.Equals(typeof(MatchInfo)))
        //{
        //MatchInfo matchInfo = (MatchInfo)data;
        //if(matchInfo.gameEnd)
        //{
        //get matchInfo.scores
        //goto lobby menu, ready for next match
        //return;
        //}
        //if(matchInfo.playerdied)//do something? TODO design syncing
        //}
    }
示例#3
0
    protected override void HandleSerializedData(SerializeBase data)
    {
        testFloat = 1111;
        Type t = data.GetType();

        if (t.Equals(typeof(PlayerInput)))
        {
            PlayerInput input = (PlayerInput)data;
            lock (inputs)
            {
                inputs[input.playerID] = input;
            }
            testFloat = 2222;
            //find player object and execute movement method... players[input.playerid].doMovement(input.xAxis, input.Jump, input.Action);
            //create new PlayerUpdates(input.playerid, new playerInfo(players[input.playerid].tranform.position.x, players[input.playerid].tranform.position.y);
            //serialize PlayerUpdates....
            //send serialized Playerupdates to all (or all other?) clients
        }
    }