Unity 使用UnityWebRequest 读取存档 (IOS只能这样做)

打IOS包的时候发现的,不能使用正常的IO流读取,不然会读取不到数据,只能使用UnityWebRequest 读取

代码如下

  public IEnumerator ReadArchive(Action<bool, string> ac, string filepath = "")
    {
        UnityWebRequest request = UnityWebRequest.Get(PathManger.PlatformSwitchingUrl(filepath));
        yield return request.SendWebRequest();
        var text = "";
        if (request.result == UnityWebRequest.Result.ConnectionError)
        {
            DebugEX.Log("资源读取失败", request.error);
        }
        else
        {
            text = request.downloadHandler.text;
            DebugEX.Log("读取到的本地资源是", filepath, request.downloadHandler.text);
        }
        if (text == "")
        {
            m_CurrentArchiveVersion = NewestArchiveVersion;
            ac?.Invoke(false, null, fileType);
        }
            ac?.Invoke(true, payload, fileType);
        }
    }

使用协程读取 返回的数据就是string 读档内容

你可能感兴趣的:(unity,ios,游戏引擎)