コード例 #1
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);
                }
            }
        }
    }