void SpawnFood(object sender, MessageReceivedEventArgs e)
    {
        using (Message message = e.GetMessage())
            using (DarkRiftReader reader = message.GetReader())
            {
                if (reader.Length % 13 != 0)
                {
                    Debug.LogWarning("Received malformed spawn packet.");
                    return;
                }

                while (reader.Position < reader.Length)
                {
                    ushort  id       = reader.ReadUInt16();
                    Vector3 position = new Vector3(reader.ReadSingle(), reader.ReadSingle());
                    Color32 color    = new Color32(
                        reader.ReadByte(),
                        reader.ReadByte(),
                        reader.ReadByte(),
                        255
                        );

                    Debug.Log("Spawning food with ID = " + id + ".");

                    GameObject obj = Instantiate(foodPrefab, position, Quaternion.identity) as GameObject;

                    AgarObject agarObj = obj.GetComponent <AgarObject>();

                    agarObj.SetRadius(0.2f);
                    agarObj.SetColor(color);

                    food.Add(id, agarObj);
                }
            }
    }
Exemple #2
0
    private void SpawnFood(Message message)
    {
        using (DarkRiftReader reader = message.GetReader())
        {
            if (reader.Length % 17 != 0)
            {
                Debug.LogWarning("Received malformed food spawn packet.");
                return;
            }

            while (reader.Position < reader.Length)
            {
                ushort  id       = reader.ReadUInt16();
                Vector3 position = new Vector3(reader.ReadSingle(), reader.ReadSingle());
                float   radius   = reader.ReadSingle();
                Color32 color    = new Color32(
                    reader.ReadByte(),
                    reader.ReadByte(),
                    reader.ReadByte(),
                    255
                    );

                GameObject obj;
                obj = Instantiate(this.foodPrefab, position, Quaternion.identity) as GameObject;

                AgarObject agarObj = obj.GetComponent <AgarObject>();

                agarObj.SetRadius(radius);
                agarObj.SetColor(color);
                agarObj.SetMovePosition(position);

                this.Add(id, agarObj);
            }
        }
    }
    void SpawnPlayer(object sender, MessageReceivedEventArgs e)
    {
        using (Message message = e.GetMessage())
            using (DarkRiftReader reader = message.GetReader())
            {
                if (reader.Length % 17 != 0)
                {
                    Debug.LogWarning("Received malformed spawn packet.");
                    return;
                }

                while (reader.Position < reader.Length)
                {
                    ushort  id       = reader.ReadUInt16();
                    Vector3 position = new Vector3(reader.ReadSingle(), reader.ReadSingle());
                    float   radius   = reader.ReadSingle();
                    Color32 color    = new Color32(
                        reader.ReadByte(),
                        reader.ReadByte(),
                        reader.ReadByte(),
                        255
                        );

                    Debug.Log("Spawning client for ID = " + id + ".");

                    GameObject obj;
                    if (id == client.ID)
                    {
                        obj = Instantiate(controllablePrefab, position, Quaternion.identity) as GameObject;

                        Player player = obj.GetComponent <Player>();
                        player.Client = client;

                        Camera.main.GetComponent <CameraFollow>().Target = obj.transform;
                    }
                    else
                    {
                        obj = Instantiate(networkPrefab, position, Quaternion.identity) as GameObject;
                    }

                    AgarObject agarObj = obj.GetComponent <AgarObject>();

                    agarObj.SetRadius(radius);
                    agarObj.SetColor(color);

                    networkPlayerManager.Add(id, agarObj);
                }
            }
    }
    private void SpawnPlayer(Message message)
    {
        using (DarkRiftReader reader = message.GetReader())
        {
            if (message.Tag == Tags.SpawnPlayerTag)
            {
                if (reader.Length % 17 != 0)
                {
                    Debug.LogWarning("Received malformed spawn packet.");
                    return;
                }

                while (reader.Position < reader.Length)
                {
                    ushort  id       = reader.ReadUInt16();
                    Vector3 position = new Vector3(reader.ReadSingle(), reader.ReadSingle());
                    float   radius   = reader.ReadSingle();
                    Color32 color    = new Color32(
                        reader.ReadByte(),
                        reader.ReadByte(),
                        reader.ReadByte(),
                        255
                        );

                    GameObject obj;
                    if (id == this.client.ID)
                    {
                        obj = Instantiate(this.controllablePrefab, position, Quaternion.identity) as GameObject;

                        Player player = obj.GetComponent <Player>();
                        player.Client = this.client;

                        this.cameraFollow.Target = obj.transform;
                    }
                    else
                    {
                        obj = Instantiate(this.networkPrefab, position, Quaternion.identity) as GameObject;
                    }

                    AgarObject agarObj = obj.GetComponent <AgarObject>();

                    agarObj.SetRadius(radius);
                    agarObj.SetColor(color);
                    this.networkPlayerManager.Add(id, agarObj);
                }
            }
        }
    }
Exemple #5
0
        private void SpawnPlayer(object sender, MessageReceivedEventArgs e)
        {
            using (Message message = e.GetMessage())
                using (DarkRiftReader reader = message.GetReader())
                {
                    if (message.Tag == Tags.SpawnPlayerTag)
                    {
                        if (reader.Length % 17 != 0)
                        {
                            Debug.LogWarning("Received malformed spawn packet.");
                            return;
                        }

                        while (reader.Position < reader.Length)
                        {
                            ushort  id       = reader.ReadUInt16();
                            Vector3 position = new Vector3(reader.ReadSingle(), reader.ReadSingle());
                            float   radius   = reader.ReadSingle();
                            Color32 color    = new Color32(
                                reader.ReadByte(),
                                reader.ReadByte(),
                                reader.ReadByte(),
                                255
                                );

                            GameObject obj;
                            if (id == client.ID)
                            {
                                obj = Instantiate(controllablePrefab, position, Quaternion.identity) as GameObject;
                            }
                            else
                            {
                                obj = Instantiate(networkPrefab, position, Quaternion.identity) as GameObject;
                            }

                            AgarObject agarObj = obj.GetComponent <AgarObject>();

                            agarObj.SetRadius(radius);
                            agarObj.SetColor(color);
                        }
                    }
                }
        }
Exemple #6
0
    private void OnMessageReceived(object sender, MessageReceivedEventArgs e)
    {
        using (Message message = e.GetMessage())
        {
            if (message.Tag == Tags.SpawnFoodTag)
            {
                using (DarkRiftReader reader = message.GetReader())
                {
                    while (reader.Position < reader.Length)
                    {
                        ushort  id       = reader.ReadUInt16();
                        Vector3 position = new Vector3(reader.ReadSingle(), reader.ReadSingle());
                        Color32 color    = new Color32(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), 255);

                        GameObject foodGo  = Instantiate(foodPrefab, position, Quaternion.identity);
                        AgarObject foodObj = foodGo.GetComponent <AgarObject>();
                        foodObj.SetColor(color);
                        Add(id, foodObj);
                    }
                }
            }
            else if (message.Tag == Tags.MoveFoodTag)
            {
                using (DarkRiftReader reader = message.GetReader())
                {
                    ushort  id       = reader.ReadUInt16();
                    Vector3 position = new Vector3(reader.ReadSingle(), reader.ReadSingle());

                    if (Food.ContainsKey(id))
                    {
                        AgarObject foodObj = Food[id];
                        foodObj.transform.position = position;
                    }
                }
            }
        }
    }
    public void SpawnPlayer(object sender, DarkRift.Client.MessageReceivedEventArgs e)
    {
        Debug.Log("calling this ");

        using (Message message = e.GetMessage())
            using (DarkRiftReader reader = message.GetReader())
            {
                if (message.Tag == Tags.SpawnPlayerTag)
                {
                    //if (reader.Length % 22 != 0)
                    //{
                    //  Debug.LogWarning("Received malformed spawn packet.");
                    //   return;
                    //}

                    while (reader.Position < reader.Length)
                    {
                        ushort  id       = reader.ReadUInt16();
                        string  name     = reader.ReadString();
                        Vector3 position = new Vector3(reader.ReadSingle(), reader.ReadSingle());
                        float   radius   = reader.ReadSingle();
                        Color32 color    = new Color32(
                            reader.ReadByte(),
                            reader.ReadByte(),
                            reader.ReadByte(),
                            255
                            );
                        Debug.Log(id);
                        GameObject obj;
                        if (id == client.ID)
                        {
                            obj = Instantiate(controllablePrefab, position, Quaternion.identity) as GameObject;

                            Player player = obj.GetComponent <Player>();
                            player.Client = client;
                            player.name   = name;
                            if (obj.GetComponentInChildren <TextMeshPro>())
                            {
                                Debug.Log("found it");
                                obj.GetComponentInChildren <TextMeshPro>().text = name;
                            }
                            else
                            {
                                Debug.Log("didnt find it");
                            }
                        }
                        else
                        {
                            obj = Instantiate(networkPrefab, position, Quaternion.identity) as GameObject;
                            obj.GetComponentInChildren <TextMeshPro>().text = name;
                        }


                        AgarObject agarObj = obj.GetComponent <AgarObject>();

                        agarObj.SetRadius(radius);
                        agarObj.SetColor(color);

                        networkPlayerManager.Add(id, agarObj);
                    }
                }
            }
    }