异步webrequest加载资源

 protected IEnumerator GetLoadAssetTileData(string assetPath, Vector3Int assetnumber, UnityAction requestData, UnityAction loadState)
        {
            using (UnityWebRequest request = UnityWebRequest.Get("file://" + assetPath))
            {
                yield return request.SendWebRequest();
                if (request.result != UnityWebRequest.Result.Success)
                {
                    UnityEngine.Debug.LogError("Error loading file: " + request.error);
                    loadState?.Invoke(false);
                }
                else
                {
                    byte[] reqData = request.downloadHandler.data;
                    requestData?.Invoke(reqData, assetnumber);
                    loadState?.Invoke(true);
                }
            }
        }




StartCoroutine(GetLoadAssetTileData(loadDataPath, assetnumber, (loadTile, tileNumber) =>{},(loadTile, tileNumber) =>{}));

你可能感兴趣的:(前端,c#)