< Summary

Class:GDX.Developer.ConsoleCommands.ScreenCaptureConsoleCommand
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/ConsoleCommands/ScreenCaptureConsoleCommand.cs
Covered lines:4
Uncovered lines:27
Coverable lines:31
Total lines:77
Line coverage:12.9% (4 of 31)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:7
Method coverage:28.5% (2 of 7)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ScreenCaptureConsoleCommand()0%110100%
Evaluate(...)0%2100%
GetKeyword()0%110100%
GetHelpMessage()0%2100%
GetInstance(...)0%20400%
GetPath(...)0%2100%
GetDefaultName()0%2100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/ConsoleCommands/ScreenCaptureConsoleCommand.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using System.IO;
 7using UnityEngine;
 8
 9namespace GDX.Developer.ConsoleCommands
 10{
 11#if UNITY_2022_2_OR_NEWER
 12    public class ScreenCaptureConsoleCommand : ConsoleCommandBase
 13    {
 14        string m_FilePath;
 715        int m_SuperSize = 1;
 16
 17        public override bool Evaluate(float deltaTime)
 018        {
 019            ScreenCapture.CaptureScreenshot(m_FilePath, m_SuperSize);
 020            Debug.Log($"Wrote screen capture to '{m_FilePath}'.");
 021            return true;
 022        }
 23
 24        public override string GetKeyword()
 725        {
 726            return "screencapture";
 727        }
 28
 29        public override string GetHelpMessage()
 030        {
 031            return "Captures a screenshot.";
 032        }
 33
 34        /// <inheritdoc />
 35        public override ConsoleCommandBase GetInstance(string context)
 036        {
 37            // Early out
 038            if (string.IsNullOrEmpty(context))
 039            {
 040                return new ScreenCaptureConsoleCommand() { m_FilePath = GetPath(GetDefaultName())};
 41            }
 42
 43            // Handle arguments
 044            string[] split = context.Split(' ', StringSplitOptions.RemoveEmptyEntries);
 045            if (split.Length > 1)
 046            {
 047                return new ScreenCaptureConsoleCommand()
 48                {
 49                    m_FilePath = GetPath(split[0]), m_SuperSize = int.Parse(split[1])
 50                };
 51            }
 52
 053            if (split[0].IsNumeric())
 054            {
 055                return new ScreenCaptureConsoleCommand()
 56                {
 57                    m_FilePath = GetPath(GetDefaultName()), m_SuperSize = int.Parse(split[0])
 58                };
 59            }
 60
 061            return new ScreenCaptureConsoleCommand()
 62            {
 63                m_FilePath = GetPath(split[0])
 64            };
 065        }
 66
 67        public static string GetPath(string fileName)
 068        {
 069            return Path.Combine(Platform.GetOutputFolder("Screenshots"), fileName);
 070        }
 71        static string GetDefaultName()
 072        {
 073            return $"Screenshot_{DateTime.Now.ToString(Platform.FilenameTimestampFormat)}.png";
 074        }
 75    }
 76#endif // UNITY_2022_2_OR_NEWER
 77}

Coverage by test methods







Methods/Properties

ScreenCaptureConsoleCommand()
Evaluate(System.Single)
GetKeyword()
GetHelpMessage()
GetInstance(System.String)
GetPath(System.String)
GetDefaultName()