Precautions for converting Unity project PC to Android

file read:

path:

StreamingAssets:

PC: Application.StreamingAssets + "/filename"

Android: "jar:file://" + Application.dataPath + "!/assets/filename"

 Code reprint:  (8 messages) Get local files through UnityWebRequest_DannySmith's blog-CSDN blog_unitywebrequest read local files

/// <summary>
    /// 通过UnityWebRequest获取本地StreamingAssets文件夹中的文件
    /// </summary>
    /// <param name="fileName">文件名称</param>
    /// <returns></returns>
    public static string UnityWebRequestFile(string fileName)
    {
        string url;
        #region 分平台判断 StreamingAssets 路径
#if UNITY_EDITOR || UNITY_STANDALONE
        url = "file://" + Application.dataPath + "/StreamingAssets/" + fileName;
#elif UNITY_IPHONE
        url = "file://" + Application.dataPath + "/Raw/"+ fileName;
#elif UNITY_ANDROID
        url = "jar:file://" + Application.dataPath + "!/assets/"+ fileName;
#endif
        #endregion
        UnityWebRequest request = UnityWebRequest.Get(url);
        request.SendWebRequest();//读取数据
        while (true)
        {
            if (request.downloadHandler.isDone)//是否读取完数据
            {
                return request.downloadHandler.text;
            }
        }
    }

    /// <summary>
    /// 通过UnityWebRequest获取本地StreamingAssets文件夹中的Json文件
    /// </summary>
    /// <param name="fileName">文件名称</param>
    /// <returns></returns>
    public static string UnityWebRequestJsonString(string fileName)
    {
        string url;

        #region 分平台判断 StreamingAssets 路径
#if UNITY_EDITOR || UNITY_STANDALONE
        url = "file://" + Application.dataPath + "/StreamingAssets/" + fileName;
#elif UNITY_IPHONE
        url = "file://" + Application.dataPath + "/Raw/"+ fileName;
#elif UNITY_ANDROID
        url = "jar:file://" + Application.dataPath + "!/assets/"+ fileName;
#endif
        #endregion
        UnityWebRequest request = UnityWebRequest.Get(url);
        request.SendWebRequest();//读取数据
        while (true)
        {
            if (request.downloadHandler.isDone)//是否读取完数据
            {
                return request.downloadHandler.text;
            }
        }
    }

Export configuration:

To be added

Model Shader:

To be added

Gradle offline package configuration:

Get the Gradle version corresponding to the unity version:

Android Gradle Plugin Release Notes | Android Developers | Android Developers (google.cn)

AndroidManifest.Xml:

If http cannot be requested after packaging, add the following code to the file:

android:usesCleartextTraffic="true" 

Guess you like

Origin blog.csdn.net/qq_33325776/article/details/126383205