Ejemplo n.º 1
0
        private void OnInstantiate(Socket socket, byte[] data)
        {
            C2S_Instantiate clientCmd = NetworkSerializer.Deserialize <C2S_Instantiate>(data);

            //新增对象数据
            instances[clientCmd.TypeId].Add(instanceId, new Entity(clients[socket], clientCmd.X, clientCmd.Y));

            S2C_Instantiate cmd = new S2C_Instantiate();

            cmd.Frame           = clientCmd.Frame;
            cmd.Instance.TypeId = clientCmd.TypeId;
            cmd.Instance.Id     = instanceId;
            cmd.Instance.X      = clientCmd.X;
            cmd.Instance.Y      = clientCmd.Y;
            //自增
            instanceId++;
            //广播所有人
            foreach (var client in clients.Keys)
            {
                if (client == socket) //调用者拥有IsLocal属性
                {
                    cmd.Instance.IsLocal = true;
                }
                else
                {
                    cmd.Instance.IsLocal = false;
                }
                Send(client, (ushort)NetworkRole.Server, (ushort)GameCmd.Instantiate, cmd);
            }
        }
Ejemplo n.º 2
0
        public void Instantiate_RPC(int typeId, Vector2Int position)
        {
            if (!prefabs.ContainsKey(typeId))
            {
                return;
            }
            C2S_Instantiate cmd = new C2S_Instantiate();

            cmd.Frame  = frame;
            cmd.TypeId = typeId;
            //修改坐标
            cmd.X = position.X;
            cmd.Y = position.Y;
            //发送指令
            Send((ushort)NetworkRole.Client, (ushort)GameCmd.Instantiate, cmd);
        }