• Unity读取StreamingAssets路径下的文件


        /// <summary>
        ///读取StreamingAssets中的文件 
        /// </summary>
        /// <param name="path">StreamingAssets下的文件路径</param>
        /// <returns>读取到的字符串</returns>
        public static string GetTextForStreamingAssets(string path)
        {
            string localPath = "";
            if (Application.platform == RuntimePlatform.Android)
            {
                localPath = Application.streamingAssetsPath + "/" + path;
            }
            else
            {
                localPath = "file:///" + Application.streamingAssetsPath + "/" + path;
            }
    
            WWW www = new WWW(localPath);
    
            if (www.error != null)
            {
                Debug.LogError("error while reading files : " + localPath);
                return ""; //读取文件出错
            }
            while (!www.isDone) { }
            Debug.Log("File content :  " + www.text);//www下面还有获取字节数组的属性
            return www.text;
        }
    
  • 相关阅读:
    字符,字符串,字节
    111
    串口通信
    字符编码
    枚举和结构体
    参数数组
    .Net垃圾回收机制
    try{ } catch{ } finally{ }
    LVS 工作原理图文讲解
    自动化运维工具—Ansible常用模块二
  • 原文地址:https://www.cnblogs.com/ezhar/p/12899746.html
Copyright © 2020-2023  润新知