Example #1
0
    public override void init()
    {
        generateDifferColor();//use color to identify players
        uint PN = 0;

        Debug.Log("Entry to init method adapter.connectionClient=" + adapter.connectionClient.Count);
        //instance player
        foreach (int id in adapter.connectionClient.Keys)
        {
            Color tmpc;
            adapter.sendmessage(id, new byte[] { (byte)id }, msgType.SeverSideId);
            Debug.Log("clientId=" + id + " byteId=" + (byte)id);
            tmpc = availableColor.Dequeue();
            byte[] colinfo = NetWorkAdapter.GetBytes(tmpc.r + "," + tmpc.g + "," + tmpc.b);
            adapter.sendmessage(id, colinfo, msgType.color);
            Vector3    spawnPOS = new Vector3(-synchronizationObj.Count + PN, 0);
            GameObject player   = Instantiate(PlayePrefab, spawnPOS, gameObject.transform.rotation);
            player.name = "player" + id;
            player.GetComponent <SpriteRenderer>().color = tmpc;
            string which = adapter.connectionClient[id].Stext;
            string ip    = which.Replace("::ffff:", "");
            IpToObj.Add(ip, id);
            synchronizationObj.Add("player" + id, player);
        }
    }
Example #2
0
    //  Codeing shot action,id is the key of syncObj dictionary
    public void sendshotAction(byte bulletCategory, string id)
    {
        string info   = id + "," + bulletCategory;
        string patten = @"play\w";

        if (Regex.IsMatch(id, patten))
        {
            print("shotAction " + info);
        }
        byte[] transfer = NetWorkAdapter.GetBytes(info);
        broadcast(transfer, msgType.shoot);
    }