untiy吧 关注:161贴子:158
  • 2回复贴,共1

Update 中调用的函数阻塞会怎样?

只看楼主收藏回复

小弟对引擎不是很了解,现有一事不明,求大神指导。
Update是每一帧都执行的,但是满足怎样的条件Unity才会去渲染下一帧呢?和Update中调用的函数是否阻塞有没有关系?Update中如果阻塞,Unity会怎样处理呢?
为了得到结论,简单的做个实验。实验方法就是在Update中Copy一个大文件夹到另外一个磁盘分区,只Copy三次。
实验现象:在三个文件的复制过程中,Untiy未响应(FPS为不会变化,每次复制完没有console中没有log)。当复制完成后,log全部出现。实验之后更乱了,求大神指导迷津。

代码如下:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
public class copy : MonoBehaviour {
int count = 0;
void Update ()
{
count++;
if(count>300&&count<304)
{
Debug.LogWarning("start copy"+count +"start time :"+DateTime.Now+"_unity time :"+Time.time);
CopyDir(Application.dataPath + "/UI/Prefab/", "H:/0/Test" + count + "/");
Debug.LogWarning("end copy"+count +"end time :"+DateTime.Now+"_unity time :"+Time.time+"_delta time :"+Time.deltaTime);
}
}
static private void CopyDir(string srcPath, string aimPath)
{
try
{
if (aimPath[aimPath.Length - 1] != System.IO.Path.DirectorySeparatorChar)
{
aimPath += System.IO.Path.DirectorySeparatorChar;
}
if (!System.IO.Directory.Exists(aimPath))
{
System.IO.Directory.CreateDirectory(aimPath);
}
string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
foreach (string file in fileList)
{
if (System.IO.Directory.Exists(file))
{
CopyDir(file, aimPath + System.IO.Path.GetFileName(file));
}
else
{
System.IO.File.Copy(file, aimPath + System.IO.Path.GetFileName(file), true);
}
}
}
catch (System.Exception e)
{
Debug.LogError(e);
}
}
}


IP属地:北京1楼2015-02-04 19:10回复

    ✎﹏₯㎕﹍﹍
          我是一条小尾巴,我不会摇摆,不会讨人欢心,只会默默跟着我的主人。满足他那有我——小尾巴的虚荣心而已!
     ╭══╮ ┌══════┐
    ╭╯让路║═║酱油专用车 ↘
    ╰⊙═⊙╯ └══⊙═⊙═~--卸货中,请勿打扰!
    --来自丿至尊灬版贴吧客户端


    IP属地:伊朗来自Android客户端2楼2015-04-01 16:17
    回复
      知道答案要发出来,现在我还触碰到那里也是小白


      来自Android客户端3楼2015-05-07 02:18
      回复