UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"how to download data from addressable c#"
using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.ResourceManagement.ResourceLocations; public class DownloadAddressableData : MonoBehaviour { public string addressableKey; // Start is called before the first frame update void Start() { DownloadData(); } private void DownloadData() { Addressables.LoadResourceLocationsAsync(addressableKey).Completed += OnResourceLocationsLoaded; } private void OnResourceLocationsLoaded(AsyncOperationHandle<IList<IResourceLocation>> obj) { if (obj.Status == AsyncOperationStatus.Succeeded) { Addressables.LoadAssetAsync<TextAsset>(obj.Result[0]).Completed += OnDataDownloaded; } else { Debug.LogError("Failed to load resource locations."); } } private void OnDataDownloaded(AsyncOperationHandle<TextAsset> obj) { if (obj.Status == AsyncOperationStatus.Succeeded) { Debug.Log("Data downloaded: " + obj.Result.text); } else { Debug.LogError("Failed to download data."); } } }