示例#1
0
 public void TearDown()
 {
     ScreenshotUtils.TakeScreenshot(TestContext);
     QuitBrowser();
 }
示例#2
0
    /// <summary>
    /// Takes a screenshot.
    /// </summary>
    /// <param name="focus">The focus of the screenshot.</param>
    /// <param name="screenshotDir">The screenshot direction.</param>
    /// <returns>The screenshot texture</returns>
    public Texture2D TakeScreenshot(Vector3 focus, ScreenshotDir screenshotDir, string scoreText, string topScoreText)
    {
        // Enable screenshot camera to take the screenshot
        m_screenshotCamera.gameObject.SetActive(true);

        // Lazy init UIText
        if (!m_scoreText.IsInitialized)
        {
            m_scoreText.Initialize();
        }
        if (!m_topScoreText.IsInitialized)
        {
            m_topScoreText.Initialize();
        }

        // Set up score and top score display
        m_scoreText.SetText(scoreText);
        m_topScoreText.SetText(topScoreText);

        // Rotate dir around the x and y axes
        float vertAngle = m_vertAngleOffset + Random.Range(-m_randomDeltaAngle, m_randomDeltaAngle);
        float horAngle  = Random.Range(-m_randomDeltaAngle, m_randomDeltaAngle);
        // Screenshot can be taken obliquely from the right or from the left of the subject
        float horAngleOffsetSign = (Random.value > 0.5f) ? 1.0f : -1.0f;

        switch (screenshotDir)
        {
        case ScreenshotDir.Front:
            horAngle += m_horAngleOffset * horAngleOffsetSign;
            break;

        case ScreenshotDir.Side_Left:
            horAngle += -90.0f;
            break;

        case ScreenshotDir.Side_Right:
            horAngle += 90.0f;
            break;

        case ScreenshotDir.Back:
            horAngle += 180.0f + m_horAngleOffset * horAngleOffsetSign;
            break;
        }
        // Get the direction vector from the subject to the screenshot position
        //  (i.e. where camera should take the screenshot from)
        Vector3 focusToScreenshotPosDir = Quaternion.Euler(vertAngle, -horAngle, 0.0f) * Vector3.back;

        // Set camera distance and vertical offset from the subject
        float camDist = m_screenshotCamDist + Random.Range(-m_randomDeltaDist, m_randomDeltaDist);

        focus.y += m_verticalOffset;
        // Move camera to the screenshot position and make it look at the focus point
        m_screenshotCamera.transform.position = focus + focusToScreenshotPosDir * camDist;
        m_screenshotCamera.transform.LookAt(focus);

        // Take screenshot
        m_screenshotResult = ScreenshotUtils.TakeScreenshot(m_screenshotWidth, m_screenshotHeight, m_screenshotCamera);

        // Disable screenshot camera once screenshot has been taken
        m_screenshotCamera.gameObject.SetActive(false);

        return(m_screenshotResult);
    }