Exemple #1
0
        public void OnRecv_Ready_Ntf(Packet.MsgSvrCli_Ready_Ntf ntf)
        {
            StartCoroutine(PacketDelay((float)Network.NetworkDelay / 1000, () =>
            {
                room.state = Room.State.Ready;

                foreach (Packet.Block block in ntf.blocks)
                {
                    Block localBlock = Instantiate <Block>(blockPrefab);
                    localBlock.Init(room, block.type);
                    localBlock.id   = block.id;
                    localBlock.name = $"block_{block.id}";
                    localBlock.transform.SetParent(transform);
                    localBlock.transform.localPosition = block.localPosition;
                    blocks.Add(block.id, localBlock);
                }

                foreach (Packet.Player player in ntf.players)
                {
                    Bar bar = Instantiate <Bar>(barPrefab);
                    bar.Init(room);
                    bar.id = player.bar.id;
                    bar.transform.SetParent(transform);
                    bar.destination             = player.bar.localPosition;
                    bar.transform.rotation      = player.bar.rotation;
                    bar.transform.localPosition = player.bar.localPosition;
                    objects.Add(bar.id, bar.gameObject);

                    Ball ball = Instantiate <Ball>(ballPrefab);
                    ball.Init(room);
                    ball.id = player.ball.id;
                    ball.transform.SetParent(transform);
                    ball.rigidBody.velocity      = player.ball.velocity;
                    ball.transform.rotation      = player.ball.rotation;
                    ball.transform.localPosition = player.ball.localPosition;
                    objects.Add(ball.id, ball.gameObject);
                    ball.transform.SetParent(bar.transform);

                    if (player.playerNum == ntf.playerNum)
                    {
                        this.bar  = bar;
                        this.ball = ball;
                    }
                    else
                    {
                        {
                            Renderer renderer = bar.GetComponent <Renderer>();
                            renderer.material.SetColor("_Color", Color.red);
                        }
                        {
                            Renderer renderer = ball.GetComponent <Renderer>();
                            renderer.material.SetColor("_Color", Color.red);
                        }
                    }
                }
            }));
        }
Exemple #2
0
        public void Ready()
        {
            uint blockId = 1;

            for (float x = -8f; x <= 8f; x += 2f)
            {
                for (int y = 3; y < 12; y++)
                {
                    Block block = Instantiate <Block>(Main.Instance.prefabs.block);
                    block.Init(this, Block.metaData[Random.Range(0, Block.metaData.Length)].type);
                    block.id   = blockId++;
                    block.name = $"block_{block.id}";
                    block.gameObject.AddComponent <Block.Collider>();
                    block.transform.SetParent(transform);
                    block.transform.localPosition = new Vector3(x, y, 0);
                    blocks.Add(block.id, block);
                }
            }

            Packet.MsgSvrCli_Ready_Ntf ntf = new Packet.MsgSvrCli_Ready_Ntf();
            for (int i = 0; i < sessions.Count; i++)
            {
                Session session = sessions[i];

                Bar bar = GameObject.Instantiate <Bar>(Main.Instance.prefabs.bar);
                bar.Init(this);
                bar.id = Room.objectId++;
                bar.transform.SetParent(transform);
                bar.destination             = start_position[i];
                bar.transform.localPosition = start_position[i];

                Ball ball = GameObject.Instantiate <Ball>(Main.Instance.prefabs.ball);
                ball.Init(this);
                ball.id = Room.objectId++;
                ball.transform.SetParent(transform);
                ball.transform.localPosition = new Vector3(start_position[i].x, start_position[i].y + 1, start_position[i].z);

                session.room = this;
                session.bar  = bar;
                session.ball = ball;

                Packet.Player player = new Packet.Player();
                player.playerNum         = i + 1;
                player.bar.id            = bar.id;
                player.bar.rotation      = bar.transform.rotation;
                player.bar.localPosition = bar.transform.localPosition;
                player.bar.velocity      = Vector3.zero;

                player.ball.id            = ball.id;
                player.ball.rotation      = ball.transform.rotation;
                player.ball.localPosition = ball.transform.localPosition;
                player.ball.velocity      = ball.rigidBody.velocity;

                ball.transform.SetParent(bar.transform);
                ntf.players.Add(player);
            }

            foreach (var itr in blocks)
            {
                Block block = itr.Value;
                ntf.blocks.Add(new Packet.Block {
                    id = block.id, type = block.meta.type, localPosition = block.transform.localPosition
                });
            }

            for (int i = 0; i < sessions.Count; i++)
            {
                ntf.playerNum = i + 1;

                Session session = sessions[i];
                session.Send(ntf);
            }

            state = Room.State.Ready;
        }