コード例 #1
0
    // A coroutine that will take and show the screenshot
    private IEnumerator ShowScreenshot()
    {
        yield return(new WaitForEndOfFrame());

        // Take a screenshot (in the form of a Texture2D)
        Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

        texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
        texture.Apply();

        // Get a caption for the image containing the date
        var    now     = DateTime.Now;
        string caption = $"Taken on {now.ToString("dddd, dd MMMM yyyy")} at {now.ToString("HH:mm:ss")}";

        // Create ScreenShot entry
        var entry = DeveloperConsole.AppendEntry <ScreenshotEntry>(Resources.Load <GameObject>("Developer Console/Tests/ScreenshotEntry"));

        entry.SetData(texture, caption);
    }