u3d 巧用 CaptureScreenshot捕捉遊戲畫面,現在無法捕捉畫面

來源:互聯網
上載者:User

u3d 巧用 CaptureScreenshot捕捉遊戲畫面,現在無法捕捉畫面

孫廣東   2015.4.27

遊戲中測試人員在測試的時候,我們很希望能他們捕捉到當時的問題瞬間,而不是簡單的用語言描述。
帳號Unity提供了這個遊戲截屏的功能, 現在我們就來實現一下這個東東吧。Application.CaptureScreenshot
static void CaptureScreenshot(string filename, int superSize = 0); 檔案預設被儲存在這個路徑:persistent data path那麼圖片我們儲存在哪裡呢? 在行動裝置上的路徑,我們有一下幾種:Application.dataPath:
此屬性用於返回程式的資料檔案所在檔案夾的路徑。例如在Editor中就是Assets了。
Application.streamingAssetsPath:
此屬性用於返迴流資料的緩衝目錄,返迴路徑為相對路徑,適合設定一些外部資料檔案的路徑。
Application.persistentDataPath:
此屬性用於返回一個持久化資料存放區目錄的路徑,可以在此路徑下儲存一些持久化的資料檔案。這個路徑是可讀可寫的
Application.temporaryCachePath:
此屬性用於返回一個臨時資料的緩衝目錄。

android平台Application.dataPath:
/data/app/xxx.xxx.xxx.apk
Application.streamingAssetsPath:
jar:file:///data/app/xxx.xxx.xxx.apk/!/assets
Application.persistentDataPath:
/data/data/xxx.xxx.xxx/files
Application.temporaryCachePath:
/data/data/xxx.xxx.xxx/cache

IOS平台
Application.dataPath:
Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data
Application.streamingAssetsPath:
Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data/Raw
Application.persistentDataPath:
Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents
Application.temporaryCachePath:
Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Library/Caches
我們就是在遊戲介面中繪製一個Button(位置要選擇好不要礙事), 這個指令碼最好是 永遠不被銷毀的,這樣就可以一直可用了。
單擊按鈕就及時的捕捉到問題的畫面就OK了。(我以前在這篇文章中也寫過類似的代碼了:http://blog.csdn.net/u010019717/article/details/43113305)


using UnityEngine;using System.Collections;using System;/// <summary>/// 用於對遊戲的畫面進行捕捉,就是截屏/// 測試可以使用,對問題捕捉下來/// </summary>public class ScreenShoter : MonoBehaviour{    public string filePath  = Application.dataPath;    void Awake()    {        DontDestroyOnLoad(transform.gameObject);    }    void OnGUI()    {        if (GUI.Button(new Rect((Screen.width - 60) * 0.5f, 0, 60, 30), "截屏"))        {            Application.CaptureScreenshot(string.Format("{0}\\ss_{1}x{2}_{3}.jpg",filePath, Screen.width, Screen.height, System.DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds));        }    }}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.