Unified style guide

From nlelouche/Unity-SkillForge · View interactive version

Unified style guide is an AI agent skill from the GitHub repository nlelouche/Unity-SkillForge. Establish and enforce a consistent C# coding style for Unity projects. Includes .editorconfig generation and architectural guidelines.

How to use this skill

Skill file

Unified Style Guide

Overview

Defines the "North Star" for code quality and consistency. Enforces naming conventions, formatting rules, and architectural standards to ensure the codebase remains maintainable and readable by any team member.

When to Use

Core Rules

| Category | Rule | Example |

|----------|------|---------|

| Public Fields | PascalCase | public int Health; |

| Private Fields | _camelCase | private int _currentHealth; |

| Methods | PascalCase | public void TakeDamage() { } |

| Interfaces | IPrefix | public interface IDamageable { } |

| Classes | PascalCase | public class PlayerController : MonoBehaviour |

| Serialization | Force private | [SerializeField] private int _speed; |

| Braces | Allman (New Line) | if (true)<br>{ ... } |

Architecture Standards

  1. SOLID Principles: Code should adhere to SOLID where applicable in Unity.
  2. Composition over Inheritance: Prefer GetComponent and Interfaces over deep class hierarchies.
  3. Separation of Concerns: Logic (C#) should be separate from View (Unity UI/Prefab).
  4. No "Manager" Bloat: Avoid massive GameManager.cs files; break into ScoreSystem, AudioSystem, etc.

Best Practices

Few-Shot Examples

Example 1: Installing Config

User: "Setup the style guide."

Agent:

# Writes .editorconfig to project root
write_to_file(TargetFile=".editorconfig", Content=TemplateContent...)

Example 2: Code Correction

User: "Fix this script style."

Code (Before):

public int speed = 10;
void Update() {
    if(speed>5) {
        transform.Translate(0,0,1);
    }
}

Agent (After):

[SerializeField] private int _speed = 10;

private void Update()
{
    if (_speed > 5)
    {
        transform.Translate(Vector3.forward);
    }
}

TDD Contract

⚠️ Legacy Skill — Refactor Pending

Este skill NO tiene tests automatizados aún. El siguiente boilerplate es un punto de partida.

// Escribe estos tests ANTES de implementar:

// Test 1: should [expected behavior] when [condition]
[Test]
public void UnifiedStyleGuide_Should{ExpectedBehavior}_When{Condition}()
{{
    // Arrange
    // TODO: Setup test fixtures
    
    // Act
    // TODO: Execute system under test
    
    // Assert
    Assert.Fail("Not implemented — write test first");
}}

// Test 2: should handle [edge case]
[Test]
public void UnifiedStyleGuide_ShouldHandle{EdgeCase}()
{{
    // Arrange
    // TODO: Setup edge case scenario
    
    // Act
    // TODO: Execute
    
    // Assert
    Assert.Fail("Not implemented");
}}

// Test 3: should throw when [invalid input]
[Test]
public void UnifiedStyleGuide_ShouldThrow_When{InvalidInput}()
{{
    // Arrange
    var invalidInput = default;
    
    // Act & Assert
    Assert.Throws<Exception>(() => {{ /* execute */ }});
}}

Pasos para completar el TDD:

  1. Descomenta los tests above
  2. Implementa la funcionalidad mínima para que compile
  3. Ejecuta los tests — deben fallar (RED)
  4. Implementa la funcionalidad real
  5. Verifica que los tests pasen (GREEN)
  6. Refactorea manteniendo los tests verdes

Nota: Este skill fue marcado como tdd_first: false durante la auditoría v2.0.1. La sección TDD fue agregada automáticamente pero requiere customización manual para reflejar el comportamiento real del skill.

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.