Exemple #1
0
 public static void sendItemData(ItemData data)
 {
     using (Packet packet = new Packet((int)packetTypes.itemInfo))
     {
         packet.Write(data);
         SendUDPData(packet);
     }
 }
 public static void handleItem(Packet _packet)
 {
     ItemData data = _packet.ReadItemData();
     if (data.playerControl != Client.myId)
     {
         if (ignoredItems.Contains(data.itemId)) return;
         if (Client.items.ContainsKey(data.networkId) && Client.items[data.networkId].clientsideItem != null)
         {
             if(Client.items[data.networkId].clientsideItem.data.id!=data.itemId)
             {
                 Client.items[data.networkId].clientsideItem.Despawn();
                 return;
             }
             Client.items[data.networkId].clientsideItem.transform.position = data.objectData.position;
             Client.items[data.networkId].clientsideItem.transform.rotation = data.objectData.rotation;
             Client.items[data.networkId].clientsideItem.rb.velocity = data.objectData.velocity;
             Client.items[data.networkId].clientsideItem.rb.angularVelocity = data.objectData.angularVelocity;
             Client.items[data.networkId].clientsideItem.rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
             Client.items[data.networkId].toDelete = DateTime.Now.AddMilliseconds(100);
         }
         else
         {
             if(Catalog.current.GetData<BS.ItemData>(data.itemId)!=null)
             {
                 data.clientsideItem = Catalog.current.GetData<BS.ItemData>(data.itemId).Spawn();
                 data.clientsideItem.data.forceLayer = LayerName.MovingObject;
                 data.clientsideItem.SetColliderAndMeshLayer(VRManager.GetLayer(LayerName.MovingObject));
                 data.clientsideItem.data.moduleAI = null;
                 data.clientsideItem.transform.position = data.objectData.position;
                 data.clientsideItem.transform.rotation = data.objectData.rotation;
                 data.clientsideItem.rb.velocity = data.objectData.velocity;
                 data.clientsideItem.rb.angularVelocity = data.objectData.angularVelocity;
                 data.toDelete = DateTime.Now.AddMilliseconds(100);
                 Client.items[data.networkId] = data;
                 Client.networkedItems[data.networkId] = data.clientsideItem;
             }
             else
             {
                 Debug.Log($"{data.itemId} failed to spawn, adding to ignored items list");
                 ignoredItems.Add(data.itemId);
             }
         }
     }
 }
        /// <summary>
        /// Will handle item information from a client
        /// </summary>
        /// <param name="_fromClient">Client id the packet came from</param>
        /// <param name="_packet">The packet received</param>
        public static void handleItemInfo(int _fromClient, Packet _packet)
        {
            ItemData data = _packet.ReadItemData();

            if (!Server.items.ContainsKey(_fromClient))
            {
                Server.items[_fromClient] = new Dictionary <int, ItemData>();
            }

            if (Server.items[_fromClient].ContainsKey(data.clientsideId))
            {
                data.networkId = Server.items[_fromClient][data.clientsideId].networkId;
            }
            else
            {
                data.networkId = Server.networkIds;
                Server.networkIds++;
            }

            Server.items[_fromClient][data.clientsideId] = data;
        }