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(); } } }
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 }); } } }