From 5f5595b2881cb0fe4cb4f5c030db2432f39d1aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 20:42:09 +0300 Subject: [PATCH 1/7] feat(editor): add rendering and physics content standards --- .../_ZoneUA/Editor/ZoneUAContentStandards.cs | 250 ++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 Assets/_ZoneUA/Editor/ZoneUAContentStandards.cs diff --git a/Assets/_ZoneUA/Editor/ZoneUAContentStandards.cs b/Assets/_ZoneUA/Editor/ZoneUAContentStandards.cs new file mode 100644 index 0000000..0295dce --- /dev/null +++ b/Assets/_ZoneUA/Editor/ZoneUAContentStandards.cs @@ -0,0 +1,250 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using UnityEditor; +using UnityEditor.Build; +using UnityEditor.Build.Reporting; +using UnityEngine; +using UnityEngine.Rendering; + +namespace ZoneUA.EditorValidation +{ + [Serializable] + public sealed class ContentStandardsReport + { + public readonly List issues = new List(); + public int ErrorCount => issues.Count(issue => issue.severity == ValidationSeverity.Error); + public int WarningCount => issues.Count(issue => issue.severity == ValidationSeverity.Warning); + public bool IsValid => ErrorCount == 0; + + public void Add(ValidationSeverity severity, string code, string message, string path = "") + { + issues.Add(new ValidationIssue(severity, code, message, path)); + } + } + + public static class ZoneUAContentStandards + { + private static readonly string[] RequiredSortingLayers = + { + "BackGroundTiles", "GeneratedAndPlayer", "TargetMouse", "TopLayer", "UI" + }; + + private static readonly string[] RequiredPhysicsLayers = + { + "Player", "NPC", "Projectile", "World", "Interactable" + }; + + private const float RootScaleTolerance = 0.0001f; + private const float SpriteZTolerance = 0.001f; + private const int RecommendedPixelsPerUnit = 16; + + [MenuItem("Zone UA/Validation/Validate Rendering and Physics", priority = 10)] + public static void ValidateMenu() + { + ContentStandardsReport report = ValidateProject(); + foreach (ValidationIssue issue in report.issues) + { + string text = $"[{issue.code}] {issue.message} {issue.assetPath}"; + if (issue.severity == ValidationSeverity.Error) Debug.LogError(text); + else if (issue.severity == ValidationSeverity.Warning) Debug.LogWarning(text); + else Debug.Log(text); + } + + EditorUtility.DisplayDialog( + "Zone UA content standards", + $"Errors: {report.ErrorCount}\nWarnings: {report.WarningCount}\n\nSee Console for details.", + "OK"); + } + + public static ContentStandardsReport ValidateProject() + { + ContentStandardsReport report = new ContentStandardsReport(); + ValidateProjectLayers(report); + ValidatePrefabs(report); + ValidateSpriteImports(report); + ValidateDuplicateMaterials(report); + return report; + } + + private static void ValidateProjectLayers(ContentStandardsReport report) + { + foreach (string layer in RequiredSortingLayers) + { + if (!SortingLayer.layers.Any(value => value.name == layer)) + { + report.Add(ValidationSeverity.Error, "SORTING_LAYER_MISSING", $"Required sorting layer '{layer}' is missing.", "ProjectSettings/TagManager.asset"); + } + } + + foreach (string layer in RequiredPhysicsLayers) + { + if (LayerMask.NameToLayer(layer) < 0) + { + report.Add(ValidationSeverity.Warning, "PHYSICS_LAYER_MISSING", $"Recommended physics layer '{layer}' is missing.", "ProjectSettings/TagManager.asset"); + } + } + } + + private static void ValidatePrefabs(ContentStandardsReport report) + { + foreach (string guid in AssetDatabase.FindAssets("t:Prefab", new[] { "Assets" })) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + if (!IsFirstParty(path)) continue; + + GameObject root = PrefabUtility.LoadPrefabContents(path); + try + { + ValidateRootTransform(root.transform, path, report); + ValidateHierarchy(root, path, report); + } + finally + { + PrefabUtility.UnloadPrefabContents(root); + } + } + } + + private static void ValidateRootTransform(Transform root, string path, ContentStandardsReport report) + { + if ((root.localScale - Vector3.one).sqrMagnitude > RootScaleTolerance) + { + report.Add(ValidationSeverity.Warning, "PREFAB_ROOT_SCALE", "Prefab root scale should normally be (1,1,1).", path); + } + + if (root.localPosition.sqrMagnitude > RootScaleTolerance || Quaternion.Angle(root.localRotation, Quaternion.identity) > 0.01f) + { + report.Add(ValidationSeverity.Warning, "PREFAB_ROOT_TRANSFORM", "Prefab root should normally use zero position and identity rotation.", path); + } + } + + private static void ValidateHierarchy(GameObject root, string path, ContentStandardsReport report) + { + SpriteRenderer[] renderers = root.GetComponentsInChildren(true); + if (renderers.Length > 1 && root.GetComponentInChildren(true) == null) + { + report.Add(ValidationSeverity.Warning, "SORTING_GROUP_RECOMMENDED", "Prefab contains multiple SpriteRenderers but no SortingGroup.", path); + } + + foreach (SpriteRenderer renderer in renderers) + { + if (Mathf.Abs(renderer.transform.localPosition.z) > SpriteZTolerance) + { + report.Add(ValidationSeverity.Warning, "ARBITRARY_SPRITE_Z", $"SpriteRenderer '{renderer.name}' uses a non-zero local Z offset; prefer sorting layers/order.", path); + } + + if (string.IsNullOrWhiteSpace(renderer.sortingLayerName)) + { + report.Add(ValidationSeverity.Error, "SORTING_LAYER_INVALID", $"SpriteRenderer '{renderer.name}' has no valid sorting layer.", path); + } + } + + foreach (Transform transform in root.GetComponentsInChildren(true)) + { + Vector3 scale = transform.localScale; + if (scale.x < 0f || scale.y < 0f || scale.z < 0f) + { + report.Add(ValidationSeverity.Warning, "NEGATIVE_SCALE", $"'{GetHierarchyPath(transform)}' uses negative scale; prefer SpriteRenderer.flipX/flipY where possible.", path); + } + } + + foreach (BoxCollider2D collider in root.GetComponentsInChildren(true)) + { + if (collider.size.x <= 0f || collider.size.y <= 0f) + { + report.Add(ValidationSeverity.Error, "COLLIDER_ZERO_SIZE", $"BoxCollider2D '{GetHierarchyPath(collider.transform)}' has zero size.", path); + } + } + + foreach (CircleCollider2D collider in root.GetComponentsInChildren(true)) + { + if (collider.radius <= 0f) + { + report.Add(ValidationSeverity.Error, "COLLIDER_ZERO_RADIUS", $"CircleCollider2D '{GetHierarchyPath(collider.transform)}' has zero radius.", path); + } + } + } + + private static void ValidateSpriteImports(ContentStandardsReport report) + { + foreach (string guid in AssetDatabase.FindAssets("t:Texture2D", new[] { "Assets" })) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + if (!IsFirstParty(path)) continue; + if (!(AssetImporter.GetAtPath(path) is TextureImporter importer) || importer.textureType != TextureImporterType.Sprite) continue; + + if (!Mathf.Approximately(importer.spritePixelsPerUnit, RecommendedPixelsPerUnit)) + { + report.Add(ValidationSeverity.Warning, "SPRITE_PPU", $"Sprite uses {importer.spritePixelsPerUnit} PPU; project recommendation is {RecommendedPixelsPerUnit}.", path); + } + + if (importer.filterMode != FilterMode.Point) + { + report.Add(ValidationSeverity.Warning, "SPRITE_FILTER", "Pixel-art sprite should normally use Point filtering.", path); + } + + if (importer.mipmapEnabled) + { + report.Add(ValidationSeverity.Warning, "SPRITE_MIPMAPS", "2D pixel-art sprite has mipmaps enabled.", path); + } + } + } + + private static void ValidateDuplicateMaterials(ContentStandardsReport report) + { + Dictionary firstPathBySignature = new Dictionary(StringComparer.Ordinal); + foreach (string guid in AssetDatabase.FindAssets("t:Material", new[] { "Assets" })) + { + string path = AssetDatabase.GUIDToAssetPath(guid); + if (!IsFirstParty(path)) continue; + Material material = AssetDatabase.LoadAssetAtPath(path); + if (material == null) continue; + + string signature = material.shader != null ? material.shader.name + "|" + EditorJsonUtility.ToJson(material) : EditorJsonUtility.ToJson(material); + if (firstPathBySignature.TryGetValue(signature, out string existing)) + { + report.Add(ValidationSeverity.Warning, "DUPLICATE_MATERIAL", $"Material duplicates '{existing}'. Reuse one shared material where possible.", path); + } + else + { + firstPathBySignature.Add(signature, path); + } + } + } + + private static bool IsFirstParty(string path) + { + return path.StartsWith("Assets/", StringComparison.Ordinal) && + !path.StartsWith("Assets/ThirdParty/", StringComparison.Ordinal) && + !path.Contains("/Tests/") && + !path.Contains("/Samples~/"); + } + + private static string GetHierarchyPath(Transform target) + { + Stack names = new Stack(); + while (target != null) + { + names.Push(target.name); + target = target.parent; + } + return string.Join("/", names); + } + } + + public sealed class ZoneUAContentStandardsBuildValidator : IPreprocessBuildWithReport + { + public int callbackOrder => -900; + + public void OnPreprocessBuild(BuildReport report) + { + ContentStandardsReport validation = ZoneUAContentStandards.ValidateProject(); + if (!validation.IsValid) + { + throw new BuildFailedException($"Zone UA content standards failed with {validation.ErrorCount} error(s)."); + } + } + } +} From 6d28e074a4015553f1fd6ff5038d1be603fac88e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 20:42:20 +0300 Subject: [PATCH 2/7] chore(unity): add content standards script meta --- Assets/_ZoneUA/Editor/ZoneUAContentStandards.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/_ZoneUA/Editor/ZoneUAContentStandards.cs.meta diff --git a/Assets/_ZoneUA/Editor/ZoneUAContentStandards.cs.meta b/Assets/_ZoneUA/Editor/ZoneUAContentStandards.cs.meta new file mode 100644 index 0000000..983b372 --- /dev/null +++ b/Assets/_ZoneUA/Editor/ZoneUAContentStandards.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 82d6f8347e9c4c02a13f82a592bf04e7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 16ed9971efe3ff5bcf47195976169557bf1dbaa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 20:42:31 +0300 Subject: [PATCH 3/7] test(editor): add content standards report tests --- .../Tests/Editor/ContentStandardsTests.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Assets/_ZoneUA/Tests/Editor/ContentStandardsTests.cs diff --git a/Assets/_ZoneUA/Tests/Editor/ContentStandardsTests.cs b/Assets/_ZoneUA/Tests/Editor/ContentStandardsTests.cs new file mode 100644 index 0000000..20dcfff --- /dev/null +++ b/Assets/_ZoneUA/Tests/Editor/ContentStandardsTests.cs @@ -0,0 +1,38 @@ +using NUnit.Framework; + +namespace ZoneUA.EditorValidation.Tests +{ + public sealed class ContentStandardsTests + { + [Test] + public void EmptyReport_IsValid() + { + ContentStandardsReport report = new ContentStandardsReport(); + + Assert.That(report.IsValid, Is.True); + Assert.That(report.ErrorCount, Is.Zero); + Assert.That(report.WarningCount, Is.Zero); + } + + [Test] + public void Warning_DoesNotInvalidateReport() + { + ContentStandardsReport report = new ContentStandardsReport(); + report.Add(ValidationSeverity.Warning, "TEST_WARNING", "warning"); + + Assert.That(report.IsValid, Is.True); + Assert.That(report.WarningCount, Is.EqualTo(1)); + } + + [Test] + public void Error_InvalidatesReport() + { + ContentStandardsReport report = new ContentStandardsReport(); + report.Add(ValidationSeverity.Error, "TEST_ERROR", "error", "Assets/Test.prefab"); + + Assert.That(report.IsValid, Is.False); + Assert.That(report.ErrorCount, Is.EqualTo(1)); + Assert.That(report.issues[0].assetPath, Is.EqualTo("Assets/Test.prefab")); + } + } +} From 6bf1c9fbf6e8c47080947fa67059b54a8c55dc44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 20:42:45 +0300 Subject: [PATCH 4/7] chore(project): define production physics layers --- ProjectSettings/TagManager.asset | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index b1a2fbc..a73f27a 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -17,11 +17,11 @@ TagManager: - UI - - End - - - - - - - - - - + - Player + - NPC + - Projectile + - World + - Interactable - - - From 2ee8bb22c910b8a281f06337521ca5dba29c1dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 20:42:59 +0300 Subject: [PATCH 5/7] chore(unity): add content standards tests meta --- .../Tests/Editor/ContentStandardsTests.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Assets/_ZoneUA/Tests/Editor/ContentStandardsTests.cs.meta diff --git a/Assets/_ZoneUA/Tests/Editor/ContentStandardsTests.cs.meta b/Assets/_ZoneUA/Tests/Editor/ContentStandardsTests.cs.meta new file mode 100644 index 0000000..f54f08f --- /dev/null +++ b/Assets/_ZoneUA/Tests/Editor/ContentStandardsTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4ca8d31c90fb459db7e83626d3f4b318 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 555ed31f52e20b57e8c26d2e236b6941b7d73bc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 20:43:27 +0300 Subject: [PATCH 6/7] docs: add rendering physics and content standards --- Docs/RENDERING_PHYSICS_CONTENT_STANDARDS.md | 122 ++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 Docs/RENDERING_PHYSICS_CONTENT_STANDARDS.md diff --git a/Docs/RENDERING_PHYSICS_CONTENT_STANDARDS.md b/Docs/RENDERING_PHYSICS_CONTENT_STANDARDS.md new file mode 100644 index 0000000..f42ed4e --- /dev/null +++ b/Docs/RENDERING_PHYSICS_CONTENT_STANDARDS.md @@ -0,0 +1,122 @@ +# Rendering, physics and content standards + +This document defines the production rules enforced by `ZoneUAContentStandards`. + +## Rendering policy + +Use sorting layers and `sortingOrder` for 2D draw order. Avoid arbitrary transform Z offsets on objects containing `SpriteRenderer`. + +Required sorting layers: + +1. `BackGroundTiles` +2. `GeneratedAndPlayer` +3. `TargetMouse` +4. `TopLayer` +5. `UI` + +Prefab hierarchies containing multiple sprite renderers should normally have one `SortingGroup` at the visual root. This keeps body parts, weapons and effects together when actors overlap. + +Negative transform scale is reported because it can invert collider geometry and complicate nested transforms. Prefer `SpriteRenderer.flipX` and `flipY` for visual facing where practical. + +## Physics layers + +The project defines these first-party physics layers: + +- `Player` +- `NPC` +- `Projectile` +- `World` +- `Interactable` + +Recommended collision intent: + +| Layer | Expected interaction | +|---|---| +| Player | World, Interactable, hostile projectiles | +| NPC | World, Interactable, hostile projectiles | +| Projectile | World and damageable actors according to faction policy | +| World | Actors and projectiles | +| Interactable | Player/NPC sensors as required | + +Review the Physics 2D collision matrix in Unity after migration. The repository does not guess faction-specific collision behaviour; `FactionMember` remains authoritative for damage permission. + +## Prefab transforms + +Production prefab roots should normally use: + +```text +Position: 0, 0, 0 +Rotation: 0, 0, 0 +Scale: 1, 1, 1 +``` + +Visual sizing belongs on child transforms or sprite import settings. Physics colliders should remain easy to inspect and should not rely on deeply compounded scales. + +The validator reports zero-size `BoxCollider2D` and zero-radius `CircleCollider2D` as errors. + +## Sprite import policy + +The current pixel-art recommendation is: + +```text +Pixels Per Unit: 16 +Filter Mode: Point +Mip Maps: disabled +``` + +These are warnings rather than errors because UI art, large backgrounds or non-pixel assets may intentionally use different settings. Review every warning and document approved exceptions. + +## Materials + +Identical first-party materials are reported as likely duplicates. Reuse shared material assets to reduce state changes and avoid configuration drift. + +The duplicate check is advisory. Two assets may intentionally remain separate when future independent tuning is expected. + +## Editor workflow + +Run: + +```text +Zone UA → Validation → Validate Rendering and Physics +``` + +The validator checks: + +- required sorting layers; +- production physics layers; +- prefab root transforms; +- negative hierarchy scales; +- arbitrary sprite Z offsets; +- missing `SortingGroup` on multi-renderer prefabs; +- invalid collider dimensions; +- sprite PPU, filtering and mipmaps; +- duplicate material content. + +Content-standard errors also block Unity builds through `ZoneUAContentStandardsBuildValidator`. Warnings remain non-blocking. + +## Migration order + +1. Open the project in Unity 6000.5.5f1. +2. Confirm the new physics layer names in Project Settings. +3. Review and configure the Physics 2D collision matrix. +4. Run the content validator. +5. Fix errors first. +6. Review sprite-import warnings by asset category. +7. Replace arbitrary Z sorting with sorting layers and order. +8. Add `SortingGroup` to composed actor and weapon visuals where needed. +9. Re-run production composition and project validation. +10. Run representative overlap, projectile and collision smoke tests. + +## Smoke-test checklist + +- player and NPC sprites overlap in a stable order; +- equipped weapons remain grouped with their actor; +- grass and terrain do not pop in front of actors incorrectly; +- target indicators and top-layer effects remain visible; +- UI renders above world content; +- player and NPC collide with world geometry; +- projectiles hit only intended world and actor layers; +- faction rules still prevent disallowed damage; +- flipped actors retain correct collider behaviour; +- no production collider has zero dimensions; +- representative scenes show no unexpected material or texture changes. From e6622cfe51d1c8d2fc3ede3a1ff30cb667031382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= Date: Mon, 27 Jul 2026 20:43:38 +0300 Subject: [PATCH 7/7] chore(unity): add rendering standards documentation meta --- Docs/RENDERING_PHYSICS_CONTENT_STANDARDS.md.meta | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Docs/RENDERING_PHYSICS_CONTENT_STANDARDS.md.meta diff --git a/Docs/RENDERING_PHYSICS_CONTENT_STANDARDS.md.meta b/Docs/RENDERING_PHYSICS_CONTENT_STANDARDS.md.meta new file mode 100644 index 0000000..2aadb71 --- /dev/null +++ b/Docs/RENDERING_PHYSICS_CONTENT_STANDARDS.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e548a99c3ccf4357a5e7eaa5f867fb87 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: