今天查找unity中加载配置表卡的问题

我们游戏中第一次运行中,会下载配置表并进行加载。

但是我们发现一个现象:

第一次下载后,会在加载那里卡5秒左右。而以后再也不会遇到相同的卡的状况。

花了些时间发现了原因是c#代码导致的。

我们配置表使用csv,第一次下载后通过www类可以拿到下载的byte[],想避免一次IO操作,就使用c#写了解析为字符串数组的代码。

而非第一次下载,则使用File.ReadAllLine直接从文件中读取。

原来写时,以为能避免一次IO操作,可以提高性能,这里不能不说,C#自带的函数(底层使用c/c++实现),要远比c#的代码速度快的多。

也有可能是我写的C#代码太烂了的原因。

烂代码大家可以了解下:就是被注释掉的代码引导的卡。

string[] allDatas = null;

 	 	/*
        if (doneList != null)
        {
            for (int m = 0; m < doneList.Count; m++)
            {
                ConfigFile cf = doneList[m];
                if (cf.configName.Equals(configName+".bin"))
                {
					Debug.Log("Time1 :"+Time.realtimeSinceStartup);
                    StringReader sr = new StringReader(UTF8Encoding.UTF8.GetString(cf.content));
                    List<string> list = new List<string>();
                    string str = null;
                    while ((str = sr.ReadLine()) != null)
                    {
                        list.Add(str);
                    }
					Debug.Log("Time2:"+Time.realtimeSinceStartup);
                    allDatas = list.ToArray();
					Debug.Log("Time3:"+Time.realtimeSinceStartup+" "+configName+" "+list.Count);
                    break;
                }
            }
        }
        */
        if (allDatas == null)
        {
            string path = PathMgr.Config_Path + configName + ".bin";
            allDatas = File.ReadAllLines(path);
        }
发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /opt/wordpress/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048