### Get Descriptor from Report Item - C# Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/manual/compare-issues This code retrieves the `Descriptor` associated with a `ReportItem`'s `Id` and logs its description and recommendation. The `Descriptor` object contains detailed information about the type of issue, including its description and recommended solutions. Requires a valid `reportItem.Id`. ```C# var descriptor = reportItem.Id.GetDescriptor(); Debug.Log($"Id: {reportItem.Id.ToString()}"); Debug.Log($"Description: {descriptor.Description}"); Debug.Log($"Recommendation: {descriptor.Recommendation}"); ``` -------------------------------- ### GetNumCustomProperties Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/api/Unity.ProjectAuditor.Editor Gets the total number of custom properties associated with this issue. ```APIDOC ## GET /custom-properties/count ### Description Gets the total number of custom properties associated with this issue. ### Method GET ### Endpoint /custom-properties/count ### Parameters None ### Request Example None ### Response #### Success Response (200) - **count** (int) - The number of custom properties. #### Response Example ```json { "count": 5 } ``` ``` -------------------------------- ### Configure Project Auditor Analysis Parameters (C#) Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/manual/run-from-command-line This C# code snippet illustrates how to customize the Project Auditor's analysis process by creating and configuring an `AnalysisParams` object. It shows how to specify target categories (e.g., only Code issues), assembly names, build platform, code optimization level, and define callbacks for issue discovery and completion. This allows for more granular control over the analysis compared to using default parameters. ```csharp int foundIssues = 0; var analysisParams = new AnalysisParams { Categories = new[] { IssueCategory.Code }, AssemblyNames = new[] { "Assembly-CSharp" }, Platform = BuildTarget.Android, CodeOptimization = CodeOptimization.Debug, OnIncomingIssues = issues => { foundIssues += issues.Count(); }, OnCompleted = (report) => { Debug.Log($"Found {foundIssues} code issues"); report.Save(reportPath); } }; projectAuditor.AuditAsync(analysisParams); ``` -------------------------------- ### Command to Run Unity Editor in Batch Mode (Shell) Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/manual/run-from-command-line This command line instruction shows how to launch the Unity Editor in batch mode to execute a specific Editor script method. It's used in conjunction with a script like `ProjectAuditorCI.AuditAndExport` to automate project analysis. Ensure you replace `path/to/unity/executable` and `path/to/your/project` with your actual file paths. ```bash path/to/unity/executable -batchmode -quit -projectPath path/to/your/project -executeMethod ProjectAuditorCI.AuditAndExport ``` -------------------------------- ### Get Custom Property String (C#) Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/api/Unity.ProjectAuditor.Editor Retrieves the string value of a custom property. The property is identified by an enum value. ```csharp public string GetCustomProperty(T propertyEnum) where T : struct { // Implementation details... return ""; } ``` -------------------------------- ### Get Custom Property Float (C#) Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/api/Unity.ProjectAuditor.Editor Retrieves the float value of a custom property. Returns 0.0f if the property is invalid or not a float. ```csharp public float GetCustomPropertyFloat(T propertyEnum) where T : struct { // Implementation details... return 0.0f; } ``` -------------------------------- ### Execute Project Auditor Analysis via Command Line (C#) Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/manual/run-from-command-line This C# script demonstrates how to use the Project Auditor API within Unity to perform an analysis and save the report. It's designed to be executed via the Unity Editor's batch mode from the command line. The script instantiates ProjectAuditor, runs a full audit, and saves the report to a specified path, also logging the count of code-related issues. ```csharp using Unity.ProjectAuditor.Editor; using UnityEngine; public static class ProjectAuditorCI { public static void AuditAndExport() { string reportPath = "C:/Dev/MyProject/my-report.projectauditor"; var projectAuditor = new ProjectAuditor(); var report = projectAuditor.Audit(); report.Save(reportPath); var codeIssues = report.FindByCategory(IssueCategory.Code); Debug.Log($"Project Auditor found {codeIssues.Count} code issues"); } } ``` -------------------------------- ### Get Custom Property Int32 (C#) Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/api/Unity.ProjectAuditor.Editor Retrieves the integer value of a custom property. Returns 0 if the property is invalid or not an integer. ```csharp public int GetCustomPropertyInt32(T propertyEnum) where T : struct { // Implementation details... return 0; } ``` -------------------------------- ### Get Number of Custom Properties (C#) Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/api/Unity.ProjectAuditor.Editor Returns the total count of custom properties associated with an issue. This method does not take any parameters. ```csharp public int GetNumCustomProperties() { // Implementation details... return 0; } ``` -------------------------------- ### C# DOTS System Update Methods Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/manual/code-view-reference Shows update methods used in Unity's Data-Oriented Technology Stack (DOTS). Project Auditor analyzes code within these systems for performance and memory management issues, marking them as 'Major' if they are part of a frame-updating path. ```csharp SystemBase.OnUpdate(); ISystem.OnUpdate(); ``` -------------------------------- ### Get Custom Property Int64 (C#) Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/api/Unity.ProjectAuditor.Editor Retrieves the long integer value of a custom property. Returns 0 if the property is invalid or not a long. ```csharp public long GetCustomPropertyInt64(T propertyEnum) where T : struct { // Implementation details... return 0; } ``` -------------------------------- ### C# MonoBehaviour Update Methods Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/manual/code-view-reference Illustrates common Unity script methods that are called every frame. Project Auditor can identify issues within these 'hot' code paths, marking them as 'Major' severity due to their potential performance impact. ```csharp MonoBehaviour.Update(); MonoBehaviour.FixedUpdate(); MonoBehaviour.LateUpdate(); ``` -------------------------------- ### Get Custom Property UInt64 (C#) Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/api/Unity.ProjectAuditor.Editor Retrieves the unsigned long integer value of a custom property. Returns 0 if the property is invalid or not a ulong. ```csharp public ulong GetCustomPropertyUInt64(T propertyEnum) where T : struct { // Implementation details... return 0; } ``` -------------------------------- ### ReportItem Class Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/api/Unity.ProjectAuditor.Editor Describes an issue that ProjectAuditor reports in the Unity project. ```APIDOC ## Class ReportItem Describes an issue that ProjectAuditor reports in the Unity project. ### Properties #### Category This issue's category (read-only). - **Type**: `IssueCategory` #### CustomProperties Custom properties. See the "moduleMetadata" section of an exported Report JSON file for information on the formats and meanings of the custom properties for each IssueCategory. - **Type**: `string[]` #### Description Project issue Description (read-only). - **Type**: `string` #### FileExtension File extension of the file that contains this issue. - **Type**: `string` #### Filename Name of the file that contains this issue. - **Type**: `string` #### Id An unique identifier for the issue descriptor (read-only). - **Type**: `DescriptorId` *Remarks*: Reports can contain two different types of ReportItem: * Issues, which indicate a potential problem which should be investigated and possibly fixed: for example, a texture with its Read/Write Enabled checkbox ticked. * Insights, for informational purposes: for example, general information about a texture in the project. Issues can be identified by having a valid DescriptorId. See also: the IsIssue() method. #### Line Line in the file that contains this issue. - **Type**: `int` #### Location Location of the Insight or Issue (read-only). - **Type**: `Location` #### LogLevel Log level. - **Type**: `LogLevel` #### RelativePath Relative path of the file that contains this issue. - **Type**: `string` #### Severity Issue-specific Severity (read-only). - **Type**: `Severity` ### Methods #### GetCustomPropertyBool(T propertyEnum) Check whether a custom property is a boolean type and whether its value is true. - **Parameters**: - `propertyEnum` (T) - Enum value indicating a property. - **Returns**: `bool` - Returns the property's value if the property is valid and if the value type is boolean. Otherwise, returns false. - **Type Parameters**: - `T` - Can be any struct, but the method expects an enum. #### GetCustomPropertyDouble(T propertyEnum) Check whether a custom property is a double type and return its value. - **Parameters**: - `propertyEnum` (T) - Enum value indicating a property. - **Returns**: `double` - Returns the property's value if the property is valid and if the value is a double type. Otherwise, returns 0.0. - **Type Parameters**: - `T` - Can be any struct, but the method expects an enum. #### GetCustomPropertyFloat(T propertyEnum) Check whether a custom property is a float type and return its value. - **Parameters**: - `propertyEnum` (T) - Enum value indicating a property. - **Returns**: `float` - Returns the property's value if the property is valid and if the value is a float type. Otherwise, returns 0.0. - **Type Parameters**: - `T` - Can be any struct, but the method expects an enum. ``` -------------------------------- ### IsIssue Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/api/Unity.ProjectAuditor.Editor Checks if this ReportItem represents an Issue. ```APIDOC ## GET /issue/check ### Description Checks if this ReportItem represents an Issue. ### Method GET ### Endpoint /issue/check ### Parameters None ### Request Example None ### Response #### Success Response (200) - **isIssue** (bool) - True if the item is an issue, false otherwise. #### Response Example ```json { "isIssue": true } ``` ``` -------------------------------- ### ReportItem Properties (C#) Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/api/Unity.ProjectAuditor.Editor Details the properties of the ReportItem class, including read-only access to issue category, custom properties, description, file information, and severity. Some properties are ignored by JSON serialization. ```csharp [JsonProperty("category")] public IssueCategory Category { get; } [JsonProperty("properties")] public string[] CustomProperties { get; } [JsonProperty("description")] public string Description { get; } [JsonIgnore] public string FileExtension { get; } [JsonIgnore] public string Filename { get; } [JsonIgnore] public DescriptorId Id { get; } [JsonIgnore] public int Line { get; } [JsonProperty("location")] public Location Location { get; } [JsonIgnore] public LogLevel LogLevel { get; } [JsonIgnore] public string RelativePath { get; } [JsonIgnore] public Severity Severity { get; } ``` -------------------------------- ### C# GetComponentsInChildren Method Overloads Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/manual/code-view-reference Demonstrates two overloads for GetComponentsInChildren, highlighting a limitation where Project Auditor cannot differentiate between them, potentially leading to false positives. The first overload allocates managed memory, while the second does not. ```csharp public Component[] GetComponentsInChildren(Type type, bool includeInactive = false); public void GetComponentsInChildren(List results); ``` -------------------------------- ### ReportItem Class Definition (C#) Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/api/Unity.ProjectAuditor.Editor Defines the structure for reporting issues within a Unity project using the ProjectAuditor. This class is marked as Serializable and belongs to the Unity.ProjectAuditor.Editor namespace. ```csharp using System; namespace Unity.ProjectAuditor.Editor { [Serializable] public class ReportItem { // Properties and Methods defined here } } ``` -------------------------------- ### Create Custom Texture Analyzer in Unity Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/manual/custom-analyzers This C# script defines a custom analyzer for Unity's Project Auditor. It inherits from `TextureModuleAnalyzer` to check sprite texture dimensions against a defined limit (`k_MaxSpriteSize`). The analyzer registers a custom descriptor for oversized sprites and includes a fixer to automatically adjust the `maxTextureSize` in the Texture Import Settings. It utilizes `DiagnosticParameterAttribute` to allow configuration of the size limit and `TextureAnalysisContext` to access texture importer and dimension information. ```csharp using System; using System.Collections.Generic; using Unity.ProjectAuditor.Editor; using Unity.ProjectAuditor.Editor.Core; using UnityEditor; // Inherit from TextureModuleAnalyzer to allow TextureModule to create and run an // instance of this analyzer. class CustomTextureAnalyzer : TextureModuleAnalyzer { // Define our custom maximum sprite size const int k_MaxSpriteSize = 1024; // Data for constructing a descriptor. const string k_SpriteTooBigId = "PAA9000"; // Make sure this ID is unique. const string k_Title = "(Custom) Texture: Oversized Sprite"; const Areas k_ImpactedAreas = Areas.Memory | Areas.Quality; const string k_Description = "The source texture for this Sprite is larger than the limit specified by " + "the game's art direction. Oversized textures can take up too much memory " + "and compromise visual style."; const string k_Recommendation = "Resize the source texture, or set the Max Size option in the " + "Texture Import Settings to a suitable value."; // Declare a Descriptor to describe the issue we want to report. static readonly Descriptor k_CustomSpriteTooBigDescriptor = new Descriptor ( k_SpriteTooBigId, k_Title, k_ImpactedAreas, k_Description, k_Recommendation ) { // As well as the constructor parameters above, this area can be used to set // the values of other Descriptor fields. // Project Auditor will format this message using the Name that's passed into // CreateIssue. MessageFormat = "Sprite '{0}' is oversized", // Optionally declare a delegate to fix the issue in a single button click. Fixer = (issue, analysisParams) => { var textureImporter = AssetImporter.GetAtPath(issue.RelativePath) as TextureImporter; if (textureImporter != null) { textureImporter.maxTextureSize = k_MaxSpriteSize; textureImporter.SaveAndReimport(); } } }; // Declare m_CustomSpriteSizeLimit as a DiagnosticParam. Give the parameter a // unique name and a sensible default. [DiagnosticParameter("CustomSpriteSizeLimit", "Sprite Size Limit", "Warn if any sprites have a width or height greater than this value.", k_MaxSpriteSize)] int m_CustomSpriteSizeLimit; // Override the initialize method in order to pass the custom Descriptor to the // registerDescriptor Action so that ProjectAuditor knows about it. public override void Initialize(Action registerDescriptor) { registerDescriptor(k_CustomSpriteTooBigDescriptor); } // Implementation of the custom Analyze coroutine method. In the case of a class // inheriting from TextureModuleAnalyzer, the AnalysisContext passed to this // method is a TextureAnalysisContext. public override IEnumerable Analyze(TextureAnalysisContext context) { // Check to see if a texture is treated as a sprite, and check its dimensions if (context.Importer.textureType == TextureImporterType.Sprite && (context.Texture.width > m_CustomSpriteSizeLimit || context.Texture.height > m_CustomSpriteSizeLimit)) { // Create the issue with the correct category, DescriptorId, name and path yield return context.CreateIssue(IssueCategory.AssetIssue, k_CustomSpriteTooBigDescriptor.Id, context.Name) .WithLocation(context.Importer.assetPath); } } } ``` -------------------------------- ### IsValid Source: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/Packages/com.unity.project-auditor%401.0/api/Unity.ProjectAuditor.Editor Validates whether this issue has a valid description string. ```APIDOC ## GET /issue/valid ### Description Validates whether this issue has a valid description string. ### Method GET ### Endpoint /issue/valid ### Parameters None ### Request Example None ### Response #### Success Response (200) - **isValid** (bool) - True if the issue has a valid description, false otherwise. #### Response Example ```json { "isValid": true } ``` ```