コード例 #1
0
        public static double?ReadNullableDouble(this DarkRiftReader reader)
        {
            bool   hasValue = reader.ReadBoolean();
            double?b        = null;

            if (hasValue)
            {
                b = reader.ReadDouble();
            }
            return(b);
        }
コード例 #2
0
        public void ReadDoubleTest()
        {
            // GIVEN a buffer of serialized data
            mockMessageBuffer.Setup(m => m.Buffer).Returns(new byte[] { 0x3f, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
            mockMessageBuffer.Setup(m => m.Offset).Returns(0);
            mockMessageBuffer.Setup(m => m.Count).Returns(10);

            // WHEN I read a double from the reader
            double result = reader.ReadDouble();

            // THEN the value is as expected
            Assert.AreEqual(0.75d, result);
        }
コード例 #3
0
    public void MessageReceived(object sender, DarkRift.Client.MessageReceivedEventArgs e)
    {
        using (Message message = e.GetMessage() as Message)
        {
            if (message.Tag == Tags.PlayerDeathTag)
            {
                Debug.Log("called death sucessfully");
                using (DarkRiftReader reader = message.GetReader())
                {
                    ushort  id          = reader.ReadUInt16();
                    Vector3 newPosition = new Vector3(reader.ReadSingle(), reader.ReadSingle(), 0);

                    if (networkPlayers.ContainsKey(id))
                    {
                        networkPlayers[id].gameObject.transform.position = newPosition;
                        networkPlayers[id].SetRadius(1);
                    }
                }
            }
            if (message.Tag == Tags.ClientNameUpdateTag)
            {
                using (DarkRiftReader reader = message.GetReader())
                {
                    Debug.Log("called name refresh");
                    string n  = reader.ReadString();
                    ushort ID = reader.ReadUInt16();

                    GameObject g = networkPlayers[ID].gameObject;
                    if (g.GetComponent <Player>())
                    {
                        g.GetComponent <Player>().pname = n;
                    }
                    else
                    {
                        g.GetComponentInChildren <TextMeshPro>().text = n;
                    }

                    g.GetComponent <SpriteRenderer>().enabled = true;
                }
            }
            if (message.Tag == Tags.SpawnPlayerTag)
            {
                Debug.Log("recieved player creation request");
                spawner.SpawnPlayer(sender, e);
            }
            if (message.Tag == Tags.MovePlayerTag)
            {
                using (DarkRiftReader reader = message.GetReader())
                {
                    ushort  id          = reader.ReadUInt16();
                    Vector3 newPosition = new Vector3(reader.ReadSingle(), reader.ReadSingle(), 0);

                    if (networkPlayers.ContainsKey(id))
                    {
                        networkPlayers[id].SetMovePosition(newPosition);
                    }
                }
            }
            if (message.Tag == Tags.SetRadiusTag)
            {
                Debug.Log("setting radius");
                using (DarkRiftReader reader = message.GetReader())
                {
                    ushort id = reader.ReadUInt16();
                    double r  = reader.ReadDouble();

                    networkPlayers[id].SetRadius((float)r);
                }
                if (message.Tag == Tags.DespawnPlayerTag)
                {
                    spawner.DespawnPlayer(sender, e);
                }
            }
        }
    }