第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Unity以特定速率保存相機(jī)圖像

Unity以特定速率保存相機(jī)圖像

C#
森林海 2021-04-10 22:19:28
在我的項目中,我將相機(jī)圖像保存到一個文件夾中,但是每秒可節(jié)省約60。如何將保存的圖像數(shù)量減少到每秒10張左右?void Update(){     if (TLB)    {        DirectoryInfo p = new DirectoryInfo(path);        FileInfo[] files = p.GetFiles();        saveFrame(path, "TLB", fileCounter);        fileCounter = files.Length + 1;    }}    void saveFrame(string path, string type, int counter){    RenderTexture rt = new RenderTexture(frameWidth, frameHeight, 24);    GetComponentInChildren<Camera>().targetTexture = rt;    Texture2D frame = new Texture2D(frameWidth, frameHeight, TextureFormat.RGB24, false);    GetComponentInChildren<Camera>().Render();    RenderTexture.active = rt;    frame.ReadPixels(new Rect(0, 0, frameWidth, frameHeight), 0, 0);    GetComponentInChildren<Camera>().targetTexture = null;    RenderTexture.active = null;    Destroy(rt);    byte[] bytes = frame.EncodeToPNG();    string filename = path + type + "/" + "/" + frameName(type, counter);    File.WriteAllBytes(filename, bytes);}
查看完整描述

1 回答

?
慕斯709654

TA貢獻(xiàn)1840條經(jīng)驗 獲得超5個贊

在Unity中一定時間間隔后重復(fù)執(zhí)行代碼

使用Update()方法:


// Invoke the method after interval seconds

public float interval = 0.1f;


// time counter

float elapsed = 0f;


void Update() 

{

    elapsed += Time.deltaTime;


    // if time is elapsed, reset the time counter and call the method.

    if (elapsed >= interval) 

    {

        elapsed = 0;

        TakeShot();

    }

}


void TakeShot() 

{

   // do your thing here...

}

使用InvokeRepeating()方法:


// Invoke the method after interval seconds

public float interval = 0.1f;


float delaySeconds = 0f; // delay the first call by seconds


void Start()

{

    InvokeRepeating("TakeShot", delaySeconds, interval);

}


void TakeShot() 

{

   // do your thing here...

}

注意:這兩種方法都是framerate和time-scale依賴的。


查看完整回答
反對 回復(fù) 2021-04-17
  • 1 回答
  • 0 關(guān)注
  • 258 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號