Пример #1
0
 public void OnAsset(AssetPacket packet)
 {
     // If im recieving from the server that i need an asset
     if (packet.Asset == null)
     {
         // if i dont have it
         if (!File.Exists(Path.Combine(Application.persistentDataPath, packet.ResquestedImageName)) || DEBUG_ALWAYS_DOWNLOAD)
         {
             _assetsRequested.Add(packet);
         }
         else
         {
             var spriteMap = AssetHandler.LoadNewSprite(Path.Combine(Application.persistentDataPath, packet.ResquestedImageName));
             AssetHandler.LoadedAssets.Add(packet.ResquestedImageName, spriteMap);
             AssetsRecieved++;
         }
     }
     else
     {
         Debug.Log("Saving asset " + packet.ResquestedImageName + " SIZE " + packet.Asset.Length);
         File.WriteAllBytes(Path.Combine(Application.persistentDataPath, packet.ResquestedImageName), packet.Asset);
         var spriteMap = AssetHandler.LoadNewSprite(Path.Combine(Application.persistentDataPath, packet.ResquestedImageName));
         AssetHandler.LoadedAssets.Add(packet.ResquestedImageName, spriteMap);
         AssetsRecieved++;
         if (AssetsRecieved == NumberOfAssetsToRecieve && AssetsRecieved > 0)
         {
             DoneDownloading();
         }
     }
 }
Пример #2
0
 public void OnAsset(AssetPacket packet)
 {
     // if client doesnt have the asset we gotta send it
     if (packet.HaveIt == false)
     {
         var assetType = packet.AssetType;
         var asset     = AssetLoader.LoadedAssets.GetAsset(packet.AssetType, packet.ResquestedImageName);
         var bytes     = asset.ImageData;
         packet.Asset = bytes;
         Server.TcpHandler.GetClient(packet.ClientId).Send(packet);
     }
 }
Пример #3
0
 public void OnAsset(AssetPacket packet)
 {
     // if client doesnt have the asset we gotta send it
     if (packet.HaveIt == false)
     {
         byte[] bytes = null;
         if (packet.AssetType == AssetType.TILESET)
         {
             bytes = Server.Map.Tilesets[packet.ResquestedImageName];
         }
         else if (packet.AssetType == AssetType.SPRITE)
         {
             bytes = MapLoader.LoadImageData(packet.ResquestedImageName);
         }
         packet.Asset = bytes;
         ServerTcpHandler.GetClient(packet.ClientId).Send(packet);
     }
 }
Пример #4
0
 public void OnAsset(AssetPacket packet)
 {
     Debug.Log("ASSET PACKET");
     // If im recieving from the server that i need an asset
     if (packet.Asset == null)
     {
         // if i dont have it
         // if (!File.Exists(Path.Combine(Application.persistentDataPath, packet.ResquestedImageName)))
         // {
         _assetRequests.Add(packet);
         //  }
         //   else
         //    {
         //        var spriteMap = AssetHandler.LoadNewSprite(Path.Combine(Application.persistentDataPath, packet.ResquestedImageName));
         //        AssetHandler.LoadedAssets.Add(packet.ResquestedImageName, spriteMap);
         //         UnityClient.TcpClient.Send(new AssetsReadyPacket()
         //        {
         //             UserId = UnityClient.UserId
         //        });
         //    }
     }
     else
     {
         Debug.Log("Saving asset " + packet.ResquestedImageName);
         File.WriteAllBytes(Path.Combine(Application.persistentDataPath, packet.ResquestedImageName), packet.Asset);
         var spriteMap = AssetHandler.LoadNewSprite(Path.Combine(Application.persistentDataPath, packet.ResquestedImageName));
         AssetHandler.LoadedAssets.Add(packet.ResquestedImageName, spriteMap);
         AssetsRecieved++;
         if (AssetsRecieved == NumberOfAssetsToRecieve && AssetsRecieved > 0)
         {
             LoadingBehaviour.Loading.StopLoading();
             _assetRequests.Clear();
             NumberOfAssetsToRecieve = 0;
             AssetsRecieved          = 0;
             State = AssetLoadingState.UPDATED;
             Debug.Log("Assets of user " + UnityClient.Player.UserId + " ready");
             UnityClient.TcpClient.Send(new AssetsReadyPacket()
             {
                 UserId = UnityClient.Player.UserId
             });
         }
     }
 }