├── StaticAnalysis ├── ViolationLevel.cs ├── ViolationScope.cs ├── Rules.meta ├── Violations.meta ├── IViolation.cs ├── CLI.cs.meta ├── Rule.cs.meta ├── Rules │ ├── NoImageWithMissingSprite.cs.meta │ ├── NoDuplicateComponents.cs.meta │ ├── NoInactiveBehaviours.cs.meta │ ├── NoMissingComponents.cs.meta │ ├── NoMissingObjectReferences.cs.meta │ ├── NoImageWithMissingSprite.cs │ ├── NoMissingComponents.cs │ ├── NoInactiveBehaviours.cs │ ├── NoDuplicateComponents.cs │ └── NoMissingObjectReferences.cs ├── Utility.cs.meta ├── IViolation.cs.meta ├── StaticAnalysis.cs.meta ├── ViolationLevel.cs.meta ├── ViolationScope.cs.meta ├── StaticAnalysisBuilder.cs.meta ├── Violations │ ├── NoImageWithMissingSpriteViolation.cs.meta │ ├── NoDuplicateComponentsViolation.cs.meta │ ├── NoInactiveBehavioursViolation.cs.meta │ ├── NoMissingComponentsViolation.cs.meta │ ├── NoMissingObjectReferencesViolation.cs.meta │ ├── NoImageWithMissingSpriteViolation.cs │ ├── NoMissingComponentsViolation.cs │ ├── NoInactiveBehavioursViolation.cs │ ├── NoDuplicateComponentsViolation.cs │ └── NoMissingObjectReferencesViolation.cs ├── Utility.cs ├── Rule.cs ├── StaticAnalysis.cs ├── StaticAnalysisBuilder.cs └── CLI.cs ├── .github └── PULL_REQUEST_TEMPLATE.md ├── LICENSE.meta ├── README.md.meta ├── moobleconfig.json.meta ├── Config.meta ├── EditorExtensions.meta ├── StaticAnalysis.meta ├── Log.cs.meta ├── Config ├── Config.cs.meta └── Config.cs ├── EditorExtensions ├── Console.cs.meta ├── ConsoleWindow.cs.meta ├── StaticAnalysisMenu.cs.meta ├── Console.cs ├── StaticAnalysisMenu.cs └── ConsoleWindow.cs ├── Log.cs ├── .gitignore ├── moobleconfig.json ├── README.md └── LICENSE /StaticAnalysis/ViolationLevel.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | namespace Mooble.StaticAnalysis { 3 | public enum ViolationLevel { 4 | Warning, 5 | Error 6 | } 7 | } 8 | #endif 9 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Changes: 2 | - Change 1. 3 | - Change 2. 4 | 5 | ## Comments: 6 | This is an example of a comment that talks about what's in this pull request. 7 | -------------------------------------------------------------------------------- /LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e6e5fdeb1a3ef6a4c9d4481b4990bb42 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f056834e24e0bce4387131e3f36bee77 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /StaticAnalysis/ViolationScope.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | namespace Mooble.StaticAnalysis { 3 | public enum ViolationScope { 4 | Both, 5 | Prefab, 6 | Scene 7 | } 8 | } 9 | #endif 10 | -------------------------------------------------------------------------------- /moobleconfig.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2199765738d8fff458e0a26833cf7a82 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Config.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5292db045974e4236a37ffcd63078f54 3 | folderAsset: yes 4 | timeCreated: 1479400962 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /EditorExtensions.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9f94b51787b6b4a5bbf9dfe84acb2210 3 | folderAsset: yes 4 | timeCreated: 1479421143 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /StaticAnalysis.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5071d586abe844626831315f39b979cd 3 | folderAsset: yes 4 | timeCreated: 1479314708 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /StaticAnalysis/Rules.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 960a3266b0df34b8a80229a9080f636e 3 | folderAsset: yes 4 | timeCreated: 1479315206 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /StaticAnalysis/Violations.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3db61dd8757a945ca9d099dd0cbd9047 3 | folderAsset: yes 4 | timeCreated: 1479324295 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /StaticAnalysis/IViolation.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | namespace Mooble.StaticAnalysis { 3 | public interface IViolation { 4 | ViolationLevel Level { get; set; } 5 | 6 | string FormatCLI(); 7 | 8 | string FormatEditor(); 9 | 10 | UnityEngine.Object GetObject(); 11 | } 12 | } 13 | #endif 14 | -------------------------------------------------------------------------------- /Log.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 23e7305e0ed074681b9a3881e2d3db88 3 | timeCreated: 1479332002 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Config/Config.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1bdcf1500fa5447a8985379cfbe733f 3 | timeCreated: 1479401263 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/CLI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69b5e3cc98b8f428c97ca83ddb5ba1a6 3 | timeCreated: 1479484631 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/Rule.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d7c82e63667b34e6fa0f870186917f0e 3 | timeCreated: 1479314866 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/Rules/NoImageWithMissingSprite.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cff89fb395aac0f4ca8b3e4aaee7a11d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /StaticAnalysis/Utility.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ffed6dc6265da4f589f69dd919f8b2f3 3 | timeCreated: 1479506030 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /EditorExtensions/Console.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 275fc93e5923049b296cde0466ac46b7 3 | timeCreated: 1479473054 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/IViolation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb0f87a7a716b49bf9340bc8a8be3ed6 3 | timeCreated: 1479324675 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /EditorExtensions/ConsoleWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 37f47b09f180b478cb7648a78b7d1327 3 | timeCreated: 1479473054 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/StaticAnalysis.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0d5fbb765b6b44d30a751639ccdff30b 3 | timeCreated: 1479314220 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/ViolationLevel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cad4209d393854524b8f906164c47611 3 | timeCreated: 1479314708 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/ViolationScope.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 66cd8f1dd505f4bcb9226d513ebc0ddc 3 | timeCreated: 1479920755 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /EditorExtensions/StaticAnalysisMenu.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c3349d9a9590f450c8767bc404431f30 3 | timeCreated: 1479498407 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/StaticAnalysisBuilder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 34260d4cb64a3433682f8812c249ca1f 3 | timeCreated: 1479409520 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/Violations/NoImageWithMissingSpriteViolation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 75b8a96d35cb00e47967ffdef02826cd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /StaticAnalysis/Rules/NoDuplicateComponents.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1709791802aa74acfa0e6ba0dbab1790 3 | timeCreated: 1479330199 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/Rules/NoInactiveBehaviours.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4b16ff728d71451b9c7be8f4d0fb2c6 3 | timeCreated: 1479330191 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/Rules/NoMissingComponents.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 22116d5c9c1c8404caaeab03e385fcca 3 | timeCreated: 1479398278 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/Rules/NoMissingObjectReferences.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 17f2ca77a65b4453090a19da03a2db8b 3 | timeCreated: 1479315239 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/Violations/NoDuplicateComponentsViolation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e8c585113b74459ea88e243a2d63617 3 | timeCreated: 1479325768 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/Violations/NoInactiveBehavioursViolation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aab8f194bc1d94025a6ce63176a12da6 3 | timeCreated: 1479330108 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/Violations/NoMissingComponentsViolation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 11308adbc2949436f929b672e67f0ad1 3 | timeCreated: 1479398278 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /StaticAnalysis/Violations/NoMissingObjectReferencesViolation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 55e51d9262a5b43279e13d1e88df4ed1 3 | timeCreated: 1479324213 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /EditorExtensions/Console.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections.Generic; 3 | 4 | using UnityEngine; 5 | 6 | namespace Mooble.EditorExtensions { 7 | [System.Serializable] 8 | public class Console : ScriptableObject { 9 | public int ErrorCount { get; set; } 10 | 11 | public int WarningCount { get; set; } 12 | 13 | public List RuleNames { get; private set; } 14 | 15 | public static Console Create() { 16 | var logger = ScriptableObject.CreateInstance(); 17 | logger.ErrorCount = 0; 18 | logger.WarningCount = 0; 19 | return logger; 20 | } 21 | } 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /Log.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Diagnostics.CodeAnalysis; 3 | 4 | namespace Mooble { 5 | public static class Log { 6 | [SuppressMessage("Unity.StyleCop.CSharp.DebugLogRule", "UN1000:DebugLogsShouldBeRemoved", Justification = "This is the place where we log.")] 7 | public static void Warning(string message, UnityEngine.Object obj) { 8 | UnityEngine.Debug.LogWarning(message, obj); 9 | } 10 | 11 | [SuppressMessage("Unity.StyleCop.CSharp.DebugLogRule", "UN1000:DebugLogsShouldBeRemoved", Justification = "This is the place where we log.")] 12 | public static void Debug(string message) { 13 | UnityEngine.Debug.Log(message); 14 | } 15 | } 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /obj 2 | /Temp 3 | /Library 4 | /Assets/Plugins/Editor/RelationsInspector/LayoutCaches.meta 5 | /Assets/Plugins/Editor/RelationsInspector/LayoutCaches 6 | 7 | .DS_Store 8 | .vscode 9 | .vs 10 | *.svd 11 | *.userprefs 12 | *.csproj 13 | *.pidb 14 | *.suo 15 | *.sln 16 | *.user 17 | *.unityproj 18 | *.booproj 19 | *.orig.meta 20 | *.sublime-project 21 | *.sublime-workspace 22 | 23 | # Unity3D generated meta files 24 | *.pidb.meta 25 | 26 | # Unity3D Generated File On Crash Reports 27 | sysinfo.txt 28 | 29 | # StyleCop generated violations 30 | StyleCopViolations.xml 31 | 32 | # Windows Store Build Generated Files 33 | UWP/* 34 | 35 | # LibreOffice Generated Files 36 | *.xlsx# 37 | 38 | /Builds 39 | 40 | /Assets/StreamingAssets/crashlytics-build.properties* 41 | /Assets/StreamingAssets.meta 42 | 43 | AdjustPostBuildAndroidLog.txt 44 | AdjustPostBuildiOSLog.txt 45 | -------------------------------------------------------------------------------- /StaticAnalysis/Rules/NoImageWithMissingSprite.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections.Generic; 3 | 4 | using Mooble.StaticAnalysis.Violation; 5 | using UnityEngine.UI; 6 | 7 | namespace Mooble.StaticAnalysis.Rules { 8 | public class NoImageWithMissingSprite : Rule { 9 | public NoImageWithMissingSprite( 10 | ViolationLevel level = ViolationLevel.Warning, 11 | ViolationScope scope = ViolationScope.Both) : base(level, scope) { 12 | } 13 | 14 | public override List Handle(object thing) { 15 | return this.Handle(thing as Image); 16 | } 17 | 18 | public override List Handle(Image thing) { 19 | var violations = new List(); 20 | 21 | if (thing == null) { 22 | return violations; 23 | } 24 | 25 | if (thing.sprite == null && thing.sprite.GetInstanceID() != 0) 26 | { 27 | violations.Add(new NoImageWithMissingSpriteViolation(this.Level, thing)); 28 | } 29 | 30 | return violations; 31 | } 32 | } 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /StaticAnalysis/Violations/NoImageWithMissingSpriteViolation.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using UnityEngine; 3 | using UnityEngine.UI; 4 | 5 | namespace Mooble.StaticAnalysis.Violation { 6 | public class NoImageWithMissingSpriteViolation : IViolation { 7 | private Image image; 8 | 9 | public NoImageWithMissingSpriteViolation(ViolationLevel level, Image image) { 10 | this.Level = level; 11 | this.image = image; 12 | } 13 | 14 | public ViolationLevel Level { get; set; } 15 | 16 | public string FormatCLI() { 17 | return string.Format( 18 | "{2} {1}: Image {0} has a missing sprite reference.", 19 | this.image.name, 20 | Utility.FormatObjectPath(this.image.gameObject), 21 | this.Level.ToString().ToUpper()); 22 | } 23 | 24 | public string FormatEditor() { 25 | return string.Format( 26 | "Image {0} has a missing sprite reference.", 27 | Utility.FormatPrimaryObject(this.image.name)); 28 | } 29 | 30 | public UnityEngine.Object GetObject() { 31 | return this.image.gameObject; 32 | } 33 | } 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /StaticAnalysis/Violations/NoMissingComponentsViolation.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using UnityEngine; 3 | 4 | namespace Mooble.StaticAnalysis.Violation { 5 | public class NoMissingComponentsViolation : IViolation { 6 | private GameObject gameObject; 7 | 8 | public NoMissingComponentsViolation(ViolationLevel level, GameObject o) { 9 | this.Level = level; 10 | this.gameObject = o; 11 | } 12 | 13 | public ViolationLevel Level { get; set; } 14 | 15 | public string FormatCLI() { 16 | return string.Format( 17 | "{1} {0}: GameObject has an undefined Component (missing script reference).", 18 | Utility.FormatObjectPath(this.gameObject), 19 | this.Level.ToString().ToUpper()); 20 | } 21 | 22 | public string FormatEditor() { 23 | return string.Format( 24 | "GameObject {0} has an undefined Component (missing script reference).", 25 | Utility.FormatPrimaryObject(Utility.FormatObjectPath(this.gameObject))); 26 | } 27 | 28 | public UnityEngine.Object GetObject() { 29 | return this.gameObject; 30 | } 31 | } 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /moobleconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "PrefabLocations": [ 3 | "Assets/Prefabs" 4 | ], 5 | "SceneLocations": [ 6 | "Assets/Scenes" 7 | ], 8 | "IgnoredSceneRootObjectNames": [ 9 | ], 10 | "Rules": [ 11 | { 12 | "Name": "NoDuplicateComponents", 13 | "ViolationLevel": "Warning", 14 | "ViolationScope": "Both", 15 | "Exclusions": [] 16 | }, 17 | { 18 | "Name": "NoMissingComponents", 19 | "ViolationLevel": "Error", 20 | "ViolationScope": "Both", 21 | "Exclusions": [] 22 | }, 23 | { 24 | "Name": "NoMissingObjectReferences", 25 | "ViolationLevel": "Warning", 26 | "ViolationScope": "Both", 27 | "Exclusions": [] 28 | }, 29 | { 30 | "Name": "NoInactiveBehaviours", 31 | "ViolationLevel": "Warning", 32 | "ViolationScope": "Both", 33 | "Exclusions": [ "UnityEngine.Animator, UnityEngine", "UnityEngine.FlareLayer, UnityEngine" ] 34 | }, 35 | { 36 | "Name": "NoImageWithMissingSprite", 37 | "ViolationLevel": "Error", 38 | "ViolationScope": "Both", 39 | "Exclusions": [] 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /StaticAnalysis/Violations/NoInactiveBehavioursViolation.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using UnityEngine; 3 | 4 | namespace Mooble.StaticAnalysis.Violation { 5 | public class NoInactiveBehavioursViolation : IViolation { 6 | private Component component; 7 | 8 | public NoInactiveBehavioursViolation(ViolationLevel level, Component c) { 9 | this.Level = level; 10 | this.component = c; 11 | } 12 | 13 | public ViolationLevel Level { get; set; } 14 | 15 | public string FormatCLI() { 16 | return string.Format( 17 | "{2} {0}: Behaviour {1} is inactive.", 18 | Utility.FormatObjectPath(this.component), 19 | this.component.GetType(), 20 | this.Level.ToString().ToUpper()); 21 | } 22 | 23 | public string FormatEditor() { 24 | return string.Format( 25 | "Behaviour {1} is inactive on {0}.", 26 | Utility.FormatPrimaryObject(this.component.name), 27 | Utility.FormatSecondaryObject(this.component.GetType().ToString())); 28 | } 29 | 30 | public UnityEngine.Object GetObject() { 31 | return this.component; 32 | } 33 | } 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /StaticAnalysis/Rules/NoMissingComponents.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections.Generic; 3 | 4 | using Mooble.StaticAnalysis.Violation; 5 | using UnityEngine; 6 | 7 | namespace Mooble.StaticAnalysis.Rules { 8 | public class NoMissingComponents : Rule { 9 | public NoMissingComponents( 10 | ViolationLevel level = ViolationLevel.Error, 11 | ViolationScope scope = ViolationScope.Both) : base(level, scope) { 12 | } 13 | 14 | public override List Handle(object thing) { 15 | return this.Handle(thing as GameObject); 16 | } 17 | 18 | public override List Handle(GameObject thing) { 19 | var violations = new List(); 20 | 21 | if (thing == null) { 22 | return violations; 23 | } 24 | 25 | Component[] allComponents = thing.GetComponents(); 26 | 27 | foreach (var component in allComponents) { 28 | if (component == null) { 29 | violations.Add(new NoMissingComponentsViolation(this.Level, thing)); 30 | } 31 | } 32 | 33 | return violations; 34 | } 35 | } 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /StaticAnalysis/Rules/NoInactiveBehaviours.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | using UnityEngine; 6 | 7 | namespace Mooble.StaticAnalysis.Rules { 8 | public class NoInactiveBehaviours : Rule { 9 | private List excludedTypes; 10 | 11 | public NoInactiveBehaviours( 12 | ViolationLevel level = ViolationLevel.Warning, 13 | ViolationScope scope = ViolationScope.Both, 14 | List excludedTypes = null) : base(level, scope) { 15 | this.excludedTypes = excludedTypes ?? new List(); 16 | } 17 | 18 | public override List Handle(object thing) { 19 | return this.Handle(thing as Behaviour); 20 | } 21 | 22 | public override List Handle(Behaviour thing) { 23 | var violations = new List(); 24 | 25 | if (thing == null || thing.enabled || this.excludedTypes.Contains(thing.GetType())) { 26 | return violations; 27 | } 28 | 29 | violations.Add(new Violation.NoInactiveBehavioursViolation(this.Level, thing)); 30 | 31 | return violations; 32 | } 33 | } 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /StaticAnalysis/Utility.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Text; 3 | using UnityEngine; 4 | 5 | namespace Mooble.StaticAnalysis { 6 | public static class Utility { 7 | public static string FormatObjectPath(Component component) { 8 | return FormatObjectPath(component.gameObject); 9 | } 10 | 11 | public static string FormatObjectPath(GameObject obj) { 12 | var path = new StringBuilder(); 13 | 14 | var transform = obj.transform; 15 | path.Append(transform.name); 16 | 17 | while (transform.parent != null) { 18 | transform = transform.parent; 19 | path.Insert(0, "/"); 20 | path.Insert(0, transform.name); 21 | } 22 | 23 | path.Insert(0, "/"); 24 | 25 | return path.ToString(); 26 | } 27 | 28 | public static string FormatPrimaryObject(string obj) { 29 | return "" + obj + ""; 30 | } 31 | 32 | public static string FormatSecondaryObject(string obj) { 33 | return "" + obj + ""; 34 | } 35 | 36 | public static string FormatTertiaryObject(string obj) { 37 | return "" + obj + ""; 38 | } 39 | } 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /StaticAnalysis/Rule.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | 5 | namespace Mooble.StaticAnalysis { 6 | public abstract class Rule { 7 | public readonly ViolationLevel Level; 8 | public readonly ViolationScope Scope; 9 | 10 | protected Rule(ViolationLevel level, ViolationScope scope) { 11 | this.Level = level; 12 | this.Scope = scope; 13 | } 14 | 15 | public string Name { 16 | get { 17 | return this.GetType().Name; 18 | } 19 | } 20 | 21 | public abstract List Handle(object thing); 22 | 23 | public bool ValidForScope(ViolationScope scope) { 24 | return this.Scope == ViolationScope.Both || this.Scope == scope; 25 | } 26 | } 27 | 28 | [SuppressMessage( 29 | "Microsoft.StyleCop.CSharp.MaintainabilityRules", 30 | "SA1402:FileMayOnlyContainASingleClass", 31 | Justification = "The rule class exists only because of C#'s silly generic system.")] 32 | public abstract class Rule : Rule { 33 | protected Rule(ViolationLevel level, ViolationScope scope) : base(level, scope) { 34 | } 35 | 36 | public abstract List Handle(T thing); 37 | } 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /StaticAnalysis/Violations/NoDuplicateComponentsViolation.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using UnityEngine; 3 | 4 | namespace Mooble.StaticAnalysis.Violation { 5 | public class NoDuplicateComponentsViolation : IViolation { 6 | private GameObject gameObject; 7 | private string componentName; 8 | private int count; 9 | 10 | public NoDuplicateComponentsViolation(ViolationLevel level, GameObject o, string c, int n) { 11 | this.Level = level; 12 | this.gameObject = o; 13 | this.componentName = c; 14 | this.count = n; 15 | } 16 | 17 | public ViolationLevel Level { get; set; } 18 | 19 | public string FormatCLI() { 20 | return string.Format( 21 | "{3} {2}: There are multiple ({0}) '{1}' Components.", 22 | this.count, 23 | this.componentName, 24 | Utility.FormatObjectPath(this.gameObject), 25 | this.Level.ToString().ToUpper()); 26 | } 27 | 28 | public string FormatEditor() { 29 | return string.Format( 30 | "There are multiple ({0}) {1} Components on {2}.", 31 | this.count, 32 | Utility.FormatSecondaryObject(this.componentName), 33 | Utility.FormatPrimaryObject(this.gameObject.name)); 34 | } 35 | 36 | public UnityEngine.Object GetObject() { 37 | return this.gameObject; 38 | } 39 | } 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /StaticAnalysis/Violations/NoMissingObjectReferencesViolation.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using UnityEngine; 3 | 4 | namespace Mooble.StaticAnalysis.Violation { 5 | public class NoMissingObjectReferencesViolation : IViolation { 6 | private Component component; 7 | private string fieldName; 8 | 9 | public NoMissingObjectReferencesViolation(ViolationLevel level, Component c, string n) { 10 | this.component = c; 11 | this.Level = level; 12 | this.fieldName = n; 13 | } 14 | 15 | public ViolationLevel Level { get; set; } 16 | 17 | public string FormatCLI() { 18 | return string.Format( 19 | "{3} {0}: Field {2} from Component {1} is undefined.", 20 | Utility.FormatObjectPath(this.component.gameObject), 21 | this.component.GetType(), 22 | this.fieldName, 23 | this.Level.ToString().ToUpper()); 24 | } 25 | 26 | public string FormatEditor() { 27 | return string.Format( 28 | "Field {2} from Component {1} on {0} is undefined.", 29 | Utility.FormatPrimaryObject(this.component.gameObject.name), 30 | Utility.FormatSecondaryObject(this.component.GetType().ToString()), 31 | Utility.FormatTertiaryObject(this.fieldName)); 32 | } 33 | 34 | public UnityEngine.Object GetObject() { 35 | return this.component; 36 | } 37 | } 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /StaticAnalysis/Rules/NoDuplicateComponents.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections.Generic; 3 | 4 | using Mooble.StaticAnalysis.Violation; 5 | using UnityEngine; 6 | 7 | namespace Mooble.StaticAnalysis.Rules { 8 | public class NoDuplicateComponents : Rule { 9 | public NoDuplicateComponents( 10 | ViolationLevel level = ViolationLevel.Warning, 11 | ViolationScope scope = ViolationScope.Both) : base(level, scope) { 12 | } 13 | 14 | public override List Handle(object thing) { 15 | return this.Handle(thing as GameObject); 16 | } 17 | 18 | public override List Handle(GameObject thing) { 19 | var violations = new List(); 20 | 21 | if (thing == null) { 22 | return violations; 23 | } 24 | 25 | Component[] allComponents = thing.GetComponents(); 26 | 27 | var s = new Dictionary(); 28 | 29 | foreach (var component in allComponents) { 30 | if (component == null) { 31 | continue; 32 | } 33 | 34 | var componentType = component.GetType().ToString(); 35 | 36 | if (s.ContainsKey(componentType)) { 37 | s[componentType]++; 38 | } else { 39 | s[componentType] = 1; 40 | } 41 | } 42 | 43 | foreach (var kvp in s) { 44 | if (kvp.Value > 1) { 45 | violations.Add(new NoDuplicateComponentsViolation(this.Level, thing, kvp.Key, kvp.Value)); 46 | } 47 | } 48 | 49 | return violations; 50 | } 51 | } 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /Config/Config.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | namespace Mooble.Config 7 | { 8 | public class Config 9 | { 10 | private static readonly string[] POTENTIAL_CONFIG_FILES = new[] { 11 | "moobleconfig.json", 12 | "Assets/Plugins/Mooble/moobleconfig.json" 13 | }; 14 | 15 | public string[] PrefabLocations; 16 | public string[] SceneLocations; 17 | public string[] IgnoredSceneRootObjectNames; 18 | public StaticAnalysisRuleConfig[] Rules; 19 | 20 | public static Config LoadFromFile(string fileName = null) 21 | { 22 | List fileNamesToTry = new List(); 23 | fileNamesToTry.Add(fileName); 24 | fileNamesToTry.AddRange(POTENTIAL_CONFIG_FILES); 25 | 26 | foreach (string path in fileNamesToTry) 27 | { 28 | if (System.IO.File.Exists(path)) 29 | { 30 | Log.Debug("Mooble: Using config file found at " + path); 31 | string text = System.IO.File.ReadAllText(path); 32 | return JsonUtility.FromJson(text); 33 | } 34 | } 35 | 36 | throw new ArgumentException("Could not not find Mooble config at " + fileName + " or any of the default locations: " + string.Join(", ", POTENTIAL_CONFIG_FILES)); 37 | } 38 | 39 | [Serializable] 40 | public class StaticAnalysisRuleConfig 41 | { 42 | public string Assembly; 43 | public string Name; 44 | public string ViolationLevel; 45 | public string ViolationScope; 46 | public string[] Exclusions; 47 | } 48 | } 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /StaticAnalysis/Rules/NoMissingObjectReferences.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | 6 | using Mooble.StaticAnalysis.Violation; 7 | using UnityEngine; 8 | 9 | namespace Mooble.StaticAnalysis.Rules { 10 | public class NoMissingObjectReferences : Rule { 11 | public NoMissingObjectReferences( 12 | ViolationLevel level = ViolationLevel.Warning, 13 | ViolationScope scope = ViolationScope.Both) : base(level, scope) { 14 | } 15 | 16 | public override List Handle(object thing) { 17 | return this.Handle(thing as MonoBehaviour); 18 | } 19 | 20 | public override List Handle(MonoBehaviour thing) { 21 | var violations = new List(); 22 | 23 | if (thing == null) { 24 | return violations; 25 | } 26 | 27 | Type componentType = thing.GetType(); 28 | 29 | if (componentType.Namespace != null && componentType.Namespace.Contains("UnityEngine")) { 30 | return violations; 31 | } 32 | 33 | FieldInfo[] fields = componentType.GetFields( 34 | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); 35 | 36 | foreach (var field in fields) { 37 | var val = field.GetValue(thing); 38 | 39 | if (field.IsPrivate && !field.IsDefined(typeof(SerializeField), false)) { 40 | continue; 41 | } 42 | 43 | if (field.IsPublic && field.IsDefined(typeof(HideInInspector), false)) { 44 | continue; 45 | } 46 | 47 | if (field.FieldType.IsClass && val == null) { 48 | violations.Add(new NoMissingObjectReferencesViolation(this.Level, thing, field.Name)); 49 | } 50 | } 51 | 52 | return violations; 53 | } 54 | } 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /EditorExtensions/StaticAnalysisMenu.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System; 3 | using System.Collections.Generic; 4 | using UnityEditor; 5 | using UnityEngine; 6 | using UnityEngine.SceneManagement; 7 | 8 | namespace Mooble.EditorExtension { 9 | using StaticAnalysis; 10 | using StaticAnalysis.Rules; 11 | 12 | public static class StaticAnalysisMenu { 13 | [MenuItem("Mooble/Static Analysis/Analyze All Prefabs")] 14 | public static void PrintPrefabAnalysis() { 15 | var config = Config.Config.LoadFromFile(); 16 | var sa = LoadStaticAnalysisRules(config); 17 | 18 | var prefabDirectories = config.PrefabLocations; 19 | var assets = AssetDatabase.FindAssets("t:prefab", prefabDirectories); 20 | var violations = new Dictionary>(); 21 | 22 | for (var i = 0; i < assets.Length; i++) { 23 | var asset = assets[i]; 24 | var path = AssetDatabase.GUIDToAssetPath(asset); 25 | var obj = AssetDatabase.LoadAssetAtPath(path); 26 | 27 | violations = StaticAnalysis.MergeRuleViolationDictionary(violations, sa.Analyze(ViolationScope.Prefab, obj)); 28 | } 29 | 30 | EditorExtensions.ConsoleWindow.Instance.SetViolations(violations); 31 | } 32 | 33 | [MenuItem("Mooble/Static Analysis/Analyze This Scene")] 34 | public static void PrintSceneAnalysis() { 35 | var config = Config.Config.LoadFromFile(); 36 | var sa = LoadStaticAnalysisRules(config); 37 | 38 | var violations = new Dictionary>(); 39 | HashSet ignoredSceneObjectNames = new HashSet(config.IgnoredSceneRootObjectNames); 40 | 41 | for (var i = 0; i < SceneManager.sceneCount; i++) { 42 | var scene = SceneManager.GetSceneAt(i); 43 | 44 | GameObject[] rootGameObjects = scene.GetRootGameObjects(); 45 | for (var j = 0; j < rootGameObjects.Length; j++) { 46 | var obj = rootGameObjects[j]; 47 | if (ignoredSceneObjectNames.Contains(obj.name)) { 48 | continue; 49 | } 50 | 51 | violations = StaticAnalysis.MergeRuleViolationDictionary(violations, sa.Analyze(ViolationScope.Scene, obj)); 52 | } 53 | } 54 | 55 | EditorExtensions.ConsoleWindow.Instance.SetViolations(violations); 56 | } 57 | 58 | private static StaticAnalysis LoadStaticAnalysisRules(Config.Config config) { 59 | return new StaticAnalysisBuilder(config).Get(); 60 | } 61 | } 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /StaticAnalysis/StaticAnalysis.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | using UnityEngine; 6 | 7 | namespace Mooble.StaticAnalysis { 8 | public class StaticAnalysis { 9 | private List> gameObjectRules; 10 | private Dictionary> componentRules; 11 | 12 | public StaticAnalysis() { 13 | this.gameObjectRules = new List>(); 14 | this.componentRules = new Dictionary>(); 15 | } 16 | 17 | public List EnabledRuleNames { 18 | get { 19 | var allRules = new List(); 20 | 21 | for (var i = 0; i < this.gameObjectRules.Count; i++) { 22 | allRules.Add(this.gameObjectRules[i].Name); 23 | } 24 | 25 | foreach (var kvp in this.componentRules) { 26 | for (var i = 0; i < kvp.Value.Count; i++) { 27 | allRules.Add(kvp.Value[i].Name); 28 | } 29 | } 30 | 31 | return allRules; 32 | } 33 | } 34 | 35 | public static Dictionary> MergeRuleViolationDictionary(Dictionary> violations1, Dictionary> violations2) { 36 | foreach (var more in violations2) { 37 | if (violations1.ContainsKey(more.Key)) { 38 | violations1[more.Key].AddRange(more.Value); 39 | } else { 40 | violations1[more.Key] = more.Value; 41 | } 42 | } 43 | 44 | return violations1; 45 | } 46 | 47 | public void RegisterComponentRule(Type type, Rule rule) { 48 | if (!this.componentRules.ContainsKey(type)) { 49 | this.componentRules[type] = new List(); 50 | } 51 | 52 | this.componentRules[type].Add(rule); 53 | } 54 | 55 | public void RegisterRule(Rule rule) { 56 | this.RegisterComponentRule(typeof(T), rule); 57 | } 58 | 59 | public void RegisterRule(Type type, Rule rule) { 60 | if (type == typeof(GameObject)) { 61 | this.RegisterRule((Rule)rule); 62 | } else { 63 | this.RegisterComponentRule(type, rule); 64 | } 65 | } 66 | 67 | public void RegisterRule(Rule rule) { 68 | this.gameObjectRules.Add(rule); 69 | } 70 | 71 | public Dictionary> Analyze(ViolationScope scope, GameObject root) { 72 | var violations = new Dictionary>(); 73 | 74 | if (root == null) { 75 | return violations; 76 | } 77 | 78 | for (var j = 0; j < this.gameObjectRules.Count; j++) { 79 | var rule = this.gameObjectRules[j]; 80 | if (!rule.ValidForScope(scope)) { 81 | continue; 82 | } 83 | 84 | violations[rule] = rule.Handle(root); 85 | } 86 | 87 | foreach (var componentRuleSet in this.componentRules) { 88 | var rules = componentRuleSet.Value; 89 | 90 | for (var j = 0; j < rules.Count; j++) { 91 | var rule = rules[j]; 92 | if (!rule.ValidForScope(scope)) { 93 | continue; 94 | } 95 | 96 | var components = root.GetComponents(componentRuleSet.Key); 97 | violations[rule] = new List(); 98 | 99 | for (var i = 0; i < components.Length; i++) { 100 | var component = components[i]; 101 | violations[rule].AddRange(rule.Handle(component)); 102 | } 103 | } 104 | } 105 | 106 | foreach (Transform child in root.transform) { 107 | var moreViolations = this.Analyze(scope, child.gameObject); 108 | 109 | violations = MergeRuleViolationDictionary(violations, moreViolations); 110 | } 111 | 112 | return violations; 113 | } 114 | } 115 | } 116 | #endif 117 | -------------------------------------------------------------------------------- /StaticAnalysis/StaticAnalysisBuilder.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | 6 | namespace Mooble.StaticAnalysis { 7 | public class StaticAnalysisBuilder { 8 | private Mooble.Config.Config config; 9 | 10 | public StaticAnalysisBuilder(Mooble.Config.Config config) { 11 | this.config = config; 12 | } 13 | 14 | public StaticAnalysis Get() { 15 | var sa = new StaticAnalysis(); 16 | 17 | for (var i = 0; i < this.config.Rules.Length; i++) { 18 | var ruleConfig = this.config.Rules[i]; 19 | var klassName = ruleConfig.Name; 20 | Assembly assembly = typeof(StaticAnalysis).Assembly; 21 | 22 | if (string.IsNullOrEmpty(ruleConfig.Assembly)) { 23 | var ns = "Mooble.StaticAnalysis.Rules."; 24 | 25 | if (!klassName.StartsWith(ns, StringComparison.CurrentCulture)) { 26 | klassName = ns + klassName; 27 | } 28 | } else { 29 | assembly = Assembly.Load(ruleConfig.Assembly); 30 | } 31 | 32 | Type ruleClass = assembly.GetType(klassName); 33 | 34 | if (ruleClass == null) { 35 | Log.Debug("Could not find rule class: " + klassName + ". Skipping."); 36 | continue; 37 | } 38 | 39 | if (!ruleClass.BaseType.IsGenericType || ruleClass.BaseType.BaseType != typeof(Rule)) { 40 | Log.Debug("Rule " + klassName + " did not extend Rule class two levels up; parent was not generic type. Skipping."); 41 | continue; 42 | } 43 | 44 | var level = (ViolationLevel)Enum.Parse(typeof(ViolationLevel), ruleConfig.ViolationLevel); 45 | var scope = (ViolationScope)Enum.Parse(typeof(ViolationScope), ruleConfig.ViolationScope); 46 | List excludedTypes = this.GetExcludedTypes(ruleConfig.Exclusions); 47 | 48 | var rule = this.ConstructRule(ruleClass, level, scope, excludedTypes); 49 | var ruleObjectType = ruleClass.BaseType.GetGenericArguments()[0]; 50 | 51 | sa.RegisterRule(ruleObjectType, rule); 52 | } 53 | 54 | return sa; 55 | } 56 | 57 | private Rule ConstructRule(Type ruleClass, ViolationLevel level, ViolationScope scope, List excludedTypes) { 58 | if (excludedTypes == null || excludedTypes.Count == 0) { 59 | ConstructorInfo ctor = ruleClass.GetConstructor(new[] { 60 | typeof(ViolationLevel), 61 | typeof(ViolationScope) 62 | }); 63 | return (Rule)ctor.Invoke(new object[] { level, scope }); 64 | } else { 65 | ConstructorInfo ctor = ruleClass.GetConstructor(new[] { 66 | typeof(ViolationLevel), 67 | typeof(ViolationScope), 68 | typeof(List) 69 | }); 70 | 71 | if (ctor == null) { 72 | Log.Debug("Could not find constructor for " + ruleClass + 73 | " that takes list of excluded types. Using default constructor."); 74 | ctor = ruleClass.GetConstructor(new[] { typeof(ViolationLevel), typeof(ViolationScope) }); 75 | return (Rule)ctor.Invoke(new object[] { level, scope }); 76 | } 77 | 78 | return (Rule)ctor.Invoke(new object[] { level, scope, excludedTypes }); 79 | } 80 | } 81 | 82 | private List GetExcludedTypes(string[] excludedTypeNames) { 83 | var excludedTypes = new List(); 84 | 85 | for (var i = 0; i < excludedTypeNames.Length; i++) { 86 | Type type = Type.GetType(excludedTypeNames[i]); 87 | 88 | if (type == null) { 89 | Log.Debug("Not including exclusion of type " + excludedTypeNames[i] + "; could not find type."); 90 | } else { 91 | excludedTypes.Add(type); 92 | } 93 | } 94 | 95 | return excludedTypes; 96 | } 97 | } 98 | } 99 | #endif 100 | -------------------------------------------------------------------------------- /StaticAnalysis/CLI.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | using UnityEditor; 6 | using UnityEditor.SceneManagement; 7 | using UnityEngine; 8 | using UnityEngine.SceneManagement; 9 | 10 | namespace Mooble.StaticAnalysis { 11 | public static class CLI { 12 | /** 13 | * Sample Usage: /Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -projectPath `pwd` -executeMethod Mooble.StaticAnalysis.CLI.RunPrefabAnalysis 14 | */ 15 | public static void RunPrefabAnalysis() { 16 | var config = Mooble.Config.Config.LoadFromFile(); 17 | 18 | var prefabGuids = AssetDatabase.FindAssets("t:prefab", config.PrefabLocations); 19 | 20 | var sa = new StaticAnalysisBuilder(config).Get(); 21 | 22 | bool foundError = false; 23 | var stringBuilder = new StringBuilder(); 24 | 25 | foreach (var prefabGuid in prefabGuids) { 26 | var path = AssetDatabase.GUIDToAssetPath(prefabGuid); 27 | var obj = AssetDatabase.LoadAssetAtPath(path); 28 | stringBuilder.Append("\nAnalyzing prefab: " + path); 29 | 30 | var violations = sa.Analyze(ViolationScope.Prefab, obj); 31 | var foundErrorThisTime = AppendViolations(stringBuilder, violations); 32 | foundError = foundError || foundErrorThisTime; 33 | } 34 | 35 | if (prefabGuids.Length == 0) { 36 | stringBuilder.Append("No prefabs were analyzed."); 37 | } 38 | 39 | Log.Debug(stringBuilder.ToString()); 40 | 41 | if (foundError) { 42 | throw new System.Exception("Error level violation found!"); 43 | } 44 | } 45 | 46 | /** 47 | * Sample Usage: /Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -projectPath `pwd` -executeMethod Mooble.StaticAnalysis.CLI.RunSceneAnalysis 48 | */ 49 | public static void RunSceneAnalysis() { 50 | var config = Mooble.Config.Config.LoadFromFile(); 51 | 52 | var scenes = LoadScenesFromConfig(config); 53 | 54 | var sa = new StaticAnalysisBuilder(config).Get(); 55 | 56 | var stringBuilder = new StringBuilder(); 57 | bool foundError = false; 58 | HashSet ignoredSceneObjectNames = new HashSet(config.IgnoredSceneRootObjectNames); 59 | 60 | foreach (var scene in scenes) { 61 | foreach (var root in scene.GetRootGameObjects()) { 62 | if (ignoredSceneObjectNames.Contains(root.name)) { 63 | stringBuilder.Append("\n Ignoring root object in scene: " + root.name); 64 | } else { 65 | stringBuilder.Append("\n Analyzing root object in scene: " + root.name); 66 | Dictionary> violations = sa.Analyze(ViolationScope.Scene, root); 67 | 68 | var foundErrorThisTime = AppendViolations(stringBuilder, violations); 69 | foundError = foundError || foundErrorThisTime; 70 | } 71 | } 72 | } 73 | 74 | if (scenes.Count == 0) { 75 | stringBuilder.Append("No scenes were analyzed."); 76 | } 77 | 78 | Log.Debug(stringBuilder.ToString()); 79 | 80 | if (foundError) { 81 | throw new System.Exception("Error level violation found!"); 82 | } 83 | } 84 | 85 | private static List LoadScenesFromConfig(Mooble.Config.Config config) { 86 | var scenes = new List(); 87 | 88 | var sceneGuids = AssetDatabase.FindAssets("t:scene", config.SceneLocations); 89 | 90 | foreach (var sceneGuid in sceneGuids) { 91 | Scene scene; 92 | 93 | try { 94 | scene = EditorSceneManager.OpenScene(AssetDatabase.GUIDToAssetPath(sceneGuid), OpenSceneMode.Additive); 95 | } catch (System.ArgumentException) { 96 | continue; 97 | } 98 | 99 | if (scene.IsValid()) { 100 | Log.Debug("Found valid scene: " + scene.name); 101 | scenes.Add(scene); 102 | } 103 | } 104 | 105 | return scenes; 106 | } 107 | 108 | private static bool AppendViolations(StringBuilder stringBuilder, Dictionary> violations) { 109 | bool foundError = false; 110 | 111 | foreach (var kvp in violations) { 112 | if (kvp.Value.Count == 0) { 113 | continue; 114 | } 115 | 116 | stringBuilder.Append("\n Violations for rule: "); 117 | stringBuilder.Append(kvp.Key.Name); 118 | 119 | foreach (var violation in kvp.Value) { 120 | if (violation.Level == ViolationLevel.Error) { 121 | foundError = true; 122 | } 123 | 124 | stringBuilder.Append("\n"); 125 | stringBuilder.Append(" "); 126 | stringBuilder.Append(violation.FormatCLI()); 127 | } 128 | } 129 | 130 | return foundError; 131 | } 132 | } 133 | } 134 | #endif 135 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mooble 2 | 3 | ## Acknowledgments 4 | 5 | This project was created by @kgooble and @elmoeleven during one of Uken's 2016 Hadoukathons 6 | 7 | ## Static Analysis 8 | 9 | Mooble provides tools to perform static analysis on prefabs and scene files - 10 | often unchecked in code review and hard to test without someone running the 11 | scene and going through every possible flow. Mooble's goal is to help catch 12 | errors ahead of time by checking for common errors in scene and prefab files, 13 | and allowing you to customize the static analysis by writing your own rules. 14 | 15 | ## Getting Started 16 | 17 | All it takes to get started with Mooble is to drop the Mooble directory into 18 | `Assets/Plugins` of your own project. Take a look at the sample project provided 19 | [here](https://github.com/kgooble/mooble-example-project) for an example. 20 | 21 | ### Built-in Rules 22 | 23 | #### `NoDuplicateComponents` 24 | 25 | This rule makes sure that `GameObjects` do not have two of the same type of 26 | `Component`, e.g. no `GameObject` has two `Text` components, etc. 27 | 28 | #### `NoInactiveBehaviours` 29 | 30 | This rule ensures that no 31 | [`Behaviour`](https://docs.unity3d.com/ScriptReference/Behaviour.html) is set to 32 | inactive. You can exclude certain types from this rule (i.e., allowing them to 33 | be inactive in the scene or prefab) by specifying an `Exclusions` array in the 34 | configuration. See [config](# Configuration Options) for more details. 35 | 36 | #### `NoMissingComponents` 37 | 38 | This rule ensures that all script components are not referencing missing 39 | scripts. If your object has a component with a missing script reference, 40 | something has likely gone wrong! 41 | 42 | #### `NoMissingObjectReferences` 43 | 44 | This rule outputs a warning if you have a 45 | [`MonoBehaviour`](https://docs.unity3d.com/ScriptReference/MonoBehaviour.html) 46 | with unassigned `public` or `SerializeField` fields - i.e. those with `null` 47 | values. This can be a smell in that your script either has some unused code 48 | in it or it may be that your `MonoBehaviour` is overly general. 49 | 50 | ### Writing Your Own Rules 51 | 52 | In order to write your own rule, you need to implement the following classes: 53 | 54 | 1. A class that implements `Rule`, where `T` is the type of component you'd 55 | like to validate (otherwise, `T` must be `GameObject`). Take a look at the 56 | `Rule` file to see which abstract methods must be implemented. 57 | 58 | 2. A class that implements `IViolation`. This is the type of violation that 59 | your rule generates. Take a look at the interface in this repository to see 60 | which methods it must implement. 61 | 62 | After you have implemented the class, add an entry to `moobleconfig.json` for 63 | that class. The class name must be fully namespaced. You must also provide the 64 | assembly name which you can find out by running the following code locally: 65 | 66 | ```csharp 67 | using System; 68 | using System.Reflection; 69 | 70 | public class FindAssembly : MonoBehaviour { 71 | private void Start() { 72 | // SomeClass is a class in your project 73 | Debug.Log(typeof(SomeClass).Assembly.GetName().Name); 74 | } 75 | } 76 | ``` 77 | 78 | In most cases it will be `"Assembly-CSharp"`. 79 | 80 | ### Configuration Options 81 | 82 | Add a `moobleconfig.json` file to your root project directory. This is the file 83 | that the menu items look for when trying to determine what rules you want to 84 | run over your scenes and prefabs. Take a look at the `moobleconfig.json` file 85 | provided in this repository for an example. 86 | 87 | Only rules listed in the `Rules` list will be run. 88 | 89 | #### Exclusions 90 | 91 | The `IgnoredSceneRootObjectNames` property at the root level of the `moobleconfig.json` 92 | file allows you to specify object names at the root level of scenes that should be ignored by Mooble. 93 | This can be useful if you need to ignore certain prefabs that are from, say, 3rd party plugins. 94 | 95 | The `Exclusions` list is to allow users to provide various types that the 96 | rule in question should _not_ run on. This type name must be qualified 97 | with the full namespace and the assembly it belongs to. For example, if you 98 | don't want to run the `NoInactiveBehaviours` rule on `Animator` behaviours, 99 | add it to the exclusion list: 100 | 101 | ```json 102 | "Exclusions": [ "UnityEngine.Animator, UnityEngine" ] 103 | ``` 104 | 105 | Other common assemblies include: 106 | * `Assembly-CSharp` for code in your project 107 | * `Assembly-CSharp-firstpass` for code in your plugins directory 108 | 109 | Not all rules accept `Exclusions` lists; take a look at the code for the 110 | specific rule to check whether it accepts exclusions. 111 | 112 | ### Build Integration 113 | 114 | You can integrate Mooble with your Jenkins build by using the command line tools provided (see [CLI.cs](https://github.com/uken/mooble/blob/master/Assets/Plugins/Mooble/StaticAnalysis/CLI.cs)). You can run the command line static analysis tools by using Unity's batch mode. Make sure to close any open instances of Unity before you run the following: 115 | 116 | ```bash 117 | /Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -projectPath ${WORKSPACE} -executeMethod Mooble.StaticAnalysis.CLI.RunPrefabAnalysis ${MOOBLE_PREFABS} 118 | ``` 119 | 120 | `${WORKSPACE}` is the location of the project that has integrated the Mooble plugin, and `${MOOBLE_PREFABS}` in this case is a space-delimited list of prefabs you want to run the prefab analysis on, e.g `Assets/Prefabs/A.prefab Assets/Prefabs/B.prefab Assets/Prefabs/MorePrefabs/C.prefab`. 121 | -------------------------------------------------------------------------------- /EditorExtensions/ConsoleWindow.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | using Mooble.StaticAnalysis; 6 | using UnityEditor; 7 | using UnityEngine; 8 | 9 | namespace Mooble.EditorExtensions { 10 | public class ConsoleWindow : EditorWindow { 11 | private const string ALL = "All"; 12 | private const float SPACE_INCREMENT = 6.0f; 13 | 14 | private readonly Color selectedColor = Color.grey; 15 | private readonly Color deselectedColor = Color.white; 16 | 17 | private static ConsoleWindow instance; 18 | 19 | private Texture2D errorIcon; 20 | private Texture2D warningIcon; 21 | 22 | private Console console; 23 | 24 | private GUIStyle logEntryOdd; 25 | private GUIStyle logEntryEven; 26 | 27 | private bool showErrors = true; 28 | private bool showWarnings = true; 29 | 30 | private Dictionary> rulesAndTheirViolations; 31 | private List filteredList; 32 | private List ruleNames; 33 | 34 | private float logListMaxWidth; 35 | private float logListLineHeight; 36 | private Vector2 logListScrollPosition; 37 | private int selectedLog = -1; 38 | private int popupIndex; 39 | 40 | public static ConsoleWindow Instance { 41 | get { 42 | if (instance == null) { 43 | Initialize(); 44 | } 45 | 46 | return instance; 47 | } 48 | } 49 | 50 | [MenuItem("Mooble/Show Console")] 51 | public static void ShowWindow() { 52 | Initialize(); 53 | } 54 | 55 | public void SetViolations(Dictionary> violations) { 56 | this.rulesAndTheirViolations = new Dictionary>(); 57 | this.rulesAndTheirViolations = StaticAnalysis.StaticAnalysis.MergeRuleViolationDictionary(this.rulesAndTheirViolations, violations); 58 | 59 | this.Repaint(); 60 | } 61 | 62 | private static void Initialize() { 63 | instance = EditorWindow.GetWindow(typeof(ConsoleWindow), false, "Mooble") as ConsoleWindow; 64 | instance.Show(); 65 | } 66 | 67 | private void OnEnable() { 68 | if (!this.console) { 69 | this.console = Console.Create(); 70 | } 71 | 72 | this.errorIcon = EditorGUIUtility.FindTexture("d_console.erroricon.sml"); 73 | this.warningIcon = EditorGUIUtility.FindTexture("d_console.warnicon.sml"); 74 | this.Repaint(); 75 | } 76 | 77 | private void OnGUI() { 78 | GUIStyle entryBackEven = GUI.skin.GetStyle("CN EntryBackEven"); 79 | GUIStyle entryBackOdd = GUI.skin.GetStyle("CN EntryBackOdd"); 80 | 81 | this.logEntryEven = new GUIStyle(); 82 | this.logEntryEven.normal = entryBackEven.normal; 83 | this.logEntryEven.margin = new RectOffset(0, 0, 0, 0); 84 | this.logEntryEven.border = new RectOffset(0, 0, 0, 0); 85 | this.logEntryEven.fixedHeight = 0; 86 | 87 | this.logEntryOdd = new GUIStyle(this.logEntryEven); 88 | this.logEntryOdd.normal = entryBackOdd.normal; 89 | 90 | this.logListLineHeight = 0; 91 | this.logListMaxWidth = 0; 92 | 93 | this.filteredList = this.PopulateErrorsAndWarnings(); 94 | this.SetupRuleDictAndNameList(); 95 | this.DrawToolbar(); 96 | this.DrawScrollRect(); 97 | this.HandleInput(); 98 | } 99 | 100 | private void SetupRuleDictAndNameList() { 101 | if (this.rulesAndTheirViolations == null) { 102 | this.rulesAndTheirViolations = new Dictionary>(); 103 | } 104 | 105 | if (this.ruleNames == null) { 106 | this.ruleNames = new List { ALL }; 107 | } 108 | 109 | foreach (KeyValuePair> kvp in this.rulesAndTheirViolations) { 110 | if (kvp.Value.Count > 0) { 111 | this.ruleNames.Add(kvp.Key.Name); 112 | } 113 | } 114 | } 115 | 116 | private void HandleInput() { 117 | if (Event.current != null && Event.current.isKey && Event.current.type.ToString() == "KeyUp") { 118 | bool shouldRepaint = false; 119 | 120 | switch (Event.current.keyCode) { 121 | case KeyCode.UpArrow: 122 | if (this.selectedLog == 0) { 123 | return; 124 | } 125 | 126 | this.selectedLog--; 127 | shouldRepaint = true; 128 | break; 129 | case KeyCode.DownArrow: 130 | if (this.selectedLog == this.filteredList.Count - 1) { 131 | return; 132 | } 133 | 134 | this.selectedLog++; 135 | shouldRepaint = true; 136 | break; 137 | } 138 | 139 | if (shouldRepaint) { 140 | this.Repaint(); 141 | this.UpdateSelection(); 142 | } 143 | } 144 | } 145 | 146 | private List PopulateErrorsAndWarnings() { 147 | this.SetupRuleDictAndNameList(); 148 | 149 | List violations = new List(); 150 | 151 | List errors = this.PopulateErrors(); 152 | List warnings = this.PopulateWarnings(); 153 | 154 | if (errors != null) { 155 | violations.AddRange(errors); 156 | } 157 | 158 | if (warnings != null) { 159 | violations.AddRange(warnings); 160 | } 161 | 162 | return violations; 163 | } 164 | 165 | private List PopulateErrors() { 166 | if (!this.showErrors) { 167 | return null; 168 | } 169 | 170 | List errors = new List(); 171 | 172 | foreach (KeyValuePair> kvp in this.rulesAndTheirViolations) { 173 | if (kvp.Key.Level == ViolationLevel.Error) { 174 | if (kvp.Value.Count == 0) { 175 | continue; 176 | } 177 | 178 | foreach (IViolation v in kvp.Value) { 179 | if (this.ruleNames[this.popupIndex] == kvp.Key.Name || this.ruleNames[this.popupIndex] == ALL) { 180 | errors.Add(new ConsoleViolation(kvp.Key.Level, v)); 181 | } 182 | } 183 | } 184 | } 185 | 186 | this.console.ErrorCount = errors.Count; 187 | 188 | return errors; 189 | } 190 | 191 | private List PopulateWarnings() { 192 | if (!this.showWarnings) { 193 | return null; 194 | } 195 | 196 | List warnings = new List(); 197 | 198 | foreach (KeyValuePair> kvp in this.rulesAndTheirViolations) { 199 | if (kvp.Key.Level == ViolationLevel.Warning) { 200 | if (kvp.Value.Count == 0) { 201 | continue; 202 | } 203 | 204 | foreach (IViolation v in kvp.Value) { 205 | if (this.ruleNames[this.popupIndex] == kvp.Key.Name || this.ruleNames[this.popupIndex] == ALL) { 206 | warnings.Add(new ConsoleViolation(kvp.Key.Level, v)); 207 | } 208 | } 209 | } 210 | } 211 | 212 | this.console.WarningCount = warnings.Count; 213 | 214 | return warnings; 215 | } 216 | 217 | private void Clear() { 218 | this.console.ErrorCount = 0; 219 | this.console.WarningCount = 0; 220 | this.showErrors = true; 221 | this.showWarnings = true; 222 | this.popupIndex = 0; 223 | this.filteredList.Clear(); 224 | this.rulesAndTheirViolations = new Dictionary>(); 225 | this.ruleNames = new List { ALL }; 226 | } 227 | 228 | private void DrawToolbar() { 229 | GUILayout.BeginHorizontal(EditorStyles.toolbar); 230 | 231 | this.DrawButton("Clear", this.Clear); 232 | 233 | this.InsertSpace(); 234 | 235 | this.DrawButton("Analyze Scene", Mooble.EditorExtension.StaticAnalysisMenu.PrintSceneAnalysis); 236 | 237 | this.InsertSpace(); 238 | 239 | this.DrawButton("Analyze All Prefabs", Mooble.EditorExtension.StaticAnalysisMenu.PrintPrefabAnalysis); 240 | 241 | GUILayout.FlexibleSpace(); 242 | 243 | GUILayout.Label("Rule: ", EditorStyles.toolbarButton); 244 | this.popupIndex = EditorGUILayout.Popup(this.popupIndex, this.ruleNames.ToArray(), EditorStyles.toolbarPopup); 245 | 246 | this.InsertSpace(); 247 | this.InsertSpace(); 248 | 249 | this.showWarnings = this.DrawToggle(this.showWarnings, new GUIContent(this.console.WarningCount.ToString(), this.warningIcon)); 250 | this.showErrors = this.DrawToggle(this.showErrors, new GUIContent(this.console.ErrorCount.ToString(), this.errorIcon)); 251 | 252 | GUILayout.EndHorizontal(); 253 | } 254 | 255 | private void DrawScrollRect() { 256 | if (this.filteredList.Count == 0) { 257 | return; 258 | } 259 | 260 | Color oldColor = GUI.backgroundColor; 261 | GUIStyle logLineStyle = this.logEntryEven; 262 | 263 | for (int k = 0; k < this.filteredList.Count; k++) { 264 | Vector2 size = logLineStyle.CalcSize(this.GUIContentForIViolation(this.filteredList[k])); 265 | this.logListMaxWidth = Mathf.Max(this.logListMaxWidth, size.x); 266 | this.logListLineHeight = Mathf.Max(this.logListLineHeight, size.y); 267 | } 268 | 269 | this.logListLineHeight *= 1.1f; 270 | 271 | Rect scrollRect = new Rect(0, EditorStyles.toolbarButton.fixedHeight, this.position.width, this.position.height); 272 | Rect contentRect = new Rect(0, EditorStyles.toolbarButton.fixedHeight, Mathf.Max(this.logListMaxWidth, scrollRect.width), this.filteredList.Count * this.logListLineHeight); 273 | this.logListScrollPosition = GUI.BeginScrollView(scrollRect, this.logListScrollPosition, contentRect); 274 | 275 | for (int i = 0; i < this.filteredList.Count; i++) { 276 | logLineStyle = i % 2 == 0 ? this.logEntryEven : this.logEntryOdd; 277 | GUI.backgroundColor = i == this.selectedLog ? this.selectedColor : this.deselectedColor; 278 | var rect = new Rect(0, this.logListLineHeight * i, contentRect.width, this.logListLineHeight); 279 | 280 | if (GUILayout.Button(this.GUIContentForIViolation(this.filteredList[i]), logLineStyle, GUILayout.Width(rect.width), GUILayout.Height(rect.height))) { 281 | if (i != this.selectedLog) { 282 | this.selectedLog = i; 283 | } 284 | 285 | this.UpdateSelection(); 286 | } 287 | } 288 | 289 | GUI.EndScrollView(); 290 | GUI.backgroundColor = oldColor; 291 | } 292 | 293 | private GUIContent GUIContentForIViolation(ConsoleViolation violation) { 294 | return new GUIContent(violation.Violation.FormatEditor(), violation.Level == ViolationLevel.Warning ? this.warningIcon : this.errorIcon); 295 | } 296 | 297 | private void UpdateSelection() { 298 | if (this.filteredList == null || this.filteredList.Count == 0) { 299 | return; 300 | } 301 | 302 | UnityEngine.Object obj = this.filteredList[this.selectedLog].Violation.GetObject(); 303 | if (obj != null) { 304 | Selection.activeObject = obj; 305 | } 306 | } 307 | 308 | private void DrawButton(string text, Action action) { 309 | if (GUILayout.Button(text, EditorStyles.toolbarButton)) { 310 | if (action == null) { 311 | return; 312 | } 313 | 314 | action(); 315 | } 316 | } 317 | 318 | private bool DrawToggle(bool selected, GUIContent content) { 319 | return GUILayout.Toggle(selected, content, EditorStyles.toolbarButton); 320 | } 321 | 322 | private void InsertSpace() { 323 | GUILayout.Space(SPACE_INCREMENT); 324 | } 325 | 326 | private struct ConsoleViolation { 327 | public readonly ViolationLevel Level; 328 | public readonly IViolation Violation; 329 | 330 | public ConsoleViolation(ViolationLevel level, IViolation violation) { 331 | this.Level = level; 332 | this.Violation = violation; 333 | } 334 | } 335 | } 336 | } 337 | #endif 338 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 Uken Studios, Inc. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------