コード例 #1
0
    public void OnRecieveSyncState(NetworkMessage netMsg)
    {
        if (customIsServer == false)
        {
            ServerBehaviour.SyncStateMsg             msg = netMsg.ReadMessage <ServerBehaviour.SyncStateMsg>();
            ServerBehaviour.SerializablePositionList deserializedPositions = new ServerBehaviour.SerializablePositionList();

            //where 0 is ball position and 1 is it's velocity
            ServerBehaviour.SerializablePositionList deserializedBallInfo = new ServerBehaviour.SerializablePositionList();

            BinaryFormatter bf     = new BinaryFormatter();
            Byte[]          buffer = msg.robotPositions;

            System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer);
            deserializedPositions = bf.Deserialize(ms) as ServerBehaviour.SerializablePositionList;

            Debug.Log(deserializedPositions.Count + " positions recived!");
            foreach (Position p in deserializedPositions)
            {
                Debug.Log(p.x);
            }


            //put the positons into the turnhandlers robots
            //the first robotCount(3) robots should be put in the otherTurnhandler

            for (int i = 0; i < 3; i++)
            {
                GameObject r = otherTurnhandler.Robots[i];
                //positions
                r.transform.position =
                    deserializedPositions[i].V2();
            }
            //and the remaining 3 should be put in the playerTurnhandler
            for (int i = 3; i < 6; i++)
            {
                GameObject r = playerTurnhandler.Robots[i - 3];
                r.transform.position =
                    deserializedPositions[i].V2();
            }
            Debug.Log(deserializedPositions[0].x + " y: " + deserializedPositions[0].y);


            //put the ballinfo in the ball

            Byte[] ballinfobuffer      = msg.ballInfo;
            System.IO.MemoryStream ms2 = new System.IO.MemoryStream(ballinfobuffer);

            deserializedBallInfo = bf.Deserialize(ms2) as ServerBehaviour.SerializablePositionList;

            Debug.Log(deserializedBallInfo[0].x);
            ball.transform.position = deserializedBallInfo[0].V2();
            ball.GetComponent <Ball>().PreviousVelocity = deserializedBallInfo[1].V2();
        }
    }
コード例 #2
0
    public void OnRecieveSyncVelocities(NetworkMessage netMsg)
    {
        if (customIsServer == false)
        {
            ServerBehaviour.SyncVelocityMsg          msg = netMsg.ReadMessage <ServerBehaviour.SyncVelocityMsg>();
            ServerBehaviour.SerializablePositionList deserializedVelocities = new ServerBehaviour.SerializablePositionList();

            BinaryFormatter bf     = new BinaryFormatter();
            Byte[]          buffer = msg.robotVelocities;

            System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer);
            deserializedVelocities = bf.Deserialize(ms) as ServerBehaviour.SerializablePositionList;

            Debug.Log(deserializedVelocities.Count + " velocities recived!");
            foreach (Position p in deserializedVelocities)
            {
                Debug.Log(p.x);
            }
            if (deserializedVelocities.Count > 0)
            {
                for (int i = 0; i < 3; i++)
                {
                    GameObject r = otherTurnhandler.Robots[i];
                    //positions
                    r.GetComponent <RobotBehaviour>().prevVelocity =
                        deserializedVelocities[i].V2();
                }
                //and the remaining 3 should be put in the playerTurnhandler
                for (int i = 3; i < 6; i++)
                {
                    GameObject r = playerTurnhandler.Robots[i - 3];
                    r.GetComponent <RobotBehaviour>().prevVelocity =
                        deserializedVelocities[i].V2();
                }
            }
            else
            {
                Debug.Log("deserialzed velocity count was 0");
            }
        }
    }