ai-agent-unity-rules / rules
Cursor rule40 starsChanged 12 months agoMITView on GitHub
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 4,181 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository8 other files it gives its agents.
- .cursor/rules/unity-architecture.mdcCursor rule
- .cursor/rules/unity-core.mdcCursor rule
- .cursor/rules/unity-ecs.mdcCursor rule
- .cursor/rules/unity-input.mdcCursor rule
- .cursor/rules/unity-networking.mdcCursor rule
- .cursor/rules/unity-performance.mdcCursor rule
- .cursor/rules/unity-testing.mdcCursor rule
- .cursor/rules/unity-ui.mdcCursor rule
The file
Show its rules and text
We split this code-organization.mdc into the rules it gives an agent
16 rules. About 0 are common, 16 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈16
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 87
Follow Microsoft C# conventions:
- Distinctive: line 256
Use PascalCase for all public identifiers (classes, methods, properties)
- Distinctive: line 257
Use _camelCase for private instance fields
- Distinctive: line 258
Use s_camelCase for static fields
- Distinctive: line 259
Use camelCase for local variables and parameters
- Distinctive: line 260
Use meaningful, descriptive names - prefer clarity over brevity
- Distinctive: line 261
Avoid abbreviations except widely known ones (UI, FX, AI)
- Distinctive: line 262
No Hungarian notation or type prefixes
- Distinctive: line 266
Use Assembly Definitions to reduce compilation time
- Distinctive: line 269
Use Addressables for content management with clear grouping strategy
- Distinctive: line 272
Use ScriptableObject-based architecture for events and shared data
- Distinctive: line 274
Use Assembly Definitions to enforce architectural boundaries
- Distinctive: line 276
Create custom packages for reusable systems
- Distinctive: line 280
Use separate assemblies for test code
- Distinctive: line 281
Create TestUtilities assembly for shared test helpers
- Distinctive: line 282
Write tests for critical gameplay systems
≈ “Common” is an estimate: at least 1 in 5 of the 6,668 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
alwaysApply: true
---
# Code Organization
## Project Folder Structure
```
Assets/
├── !_Project/ # Main project content (! keeps it at top)
│ ├── Art/
│ │ ├── Materials/
│ │ ├── Models/
│ │ ├── Textures/
│ │ └── Animations/
│ ├── Audio/
│ │ ├── Music/
│ │ ├── SFX/
│ │ └── Mixers/
│ ├── Prefabs/
│ │ ├── Characters/
│ │ ├── Environment/
│ │ ├── UI/
│ │ └── Effects/
│ ├── Scenes/
│ │ ├── Levels/
│ │ ├── Menus/
│ │ └── Test/
│ ├── Scripts/
│ │ ├── Runtime/ # Runtime code
│ │ │ ├── Core/ # Base systems
│ │ │ ├── Gameplay/ # Game logic
│ │ │ ├── UI/ # UI controllers
│ │ │ ├── Utilities/ # Helper classes
│ │ │ ├── DOTS/ # ECS implementation
│ │ │ │ ├── Components/ # IComponentData
│ │ │ │ ├── Systems/ # SystemBase/ISystem
│ │ │ │ └── Aspects/ # Aspects
│ │ │ └── Hybrid/ # Mixed MonoBehaviour + DOTS
│ │ ├── Editor/ # Editor scripts
│ │ └── Tests/ # Test assembly scripts
│ ├── ScriptableObjects/
│ │ ├── GameConfig/ # Game settings
│ │ ├── EventChannels/ # SO-based events
│ │ ├── Variables/ # Runtime shared data
│ │ ├── Sets/ # SO Sets for collections
│ │ └── Stats/ # Character/weapon data
│ └── Settings/ # Project settings
├── Packages/ # Custom packages
│ └── com.yourcompany.core/ # Reusable modules
│ ├── Runtime/
│ ├── Editor/
│ ├── Tests/
│ └── Documentation~/
├── AddressableAssets/ # Addressables content
│ ├── Groups/ # Addressable Groups configs
│ ├── Settings/ # Addressable Settings
│ └── Content/ # Organized by strategy
│ ├── PerLevel/ # Concurrent usage strategy
│ ├── Characters/ # Logical entity strategy
│ └── Shared/ # Shared resources
├── Plugins/ # Third-party plugins
├── Tests/ # Test assemblies
│ ├── EditMode/
│ │ ├── Unit/ # Unit tests
│ │ └── Integration/ # Integration tests
│ ├── PlayMode/
│ │ ├── Functional/ # Functional tests
│ │ └── Performance/ # Profiling tests
│ └── TestUtilities/ # Common mocks and helpers
└── TextMesh Pro/ # TMP resources
```
## Asset Naming Conventions
### Modern Naming (No Hungarian Prefixes)
Organization through folders, not prefixes. Use PascalCase for all asset names.
### Prefabs
- Characters: `PlayerKnight.prefab` in `Prefabs/Characters/`
- Environment: `TreeOak.prefab` in `Prefabs/Environment/`
- UI: `MainMenu.prefab` in `Prefabs/UI/`
- Effects: `Explosion.prefab` in `Prefabs/Effects/VFX/`
### Scripts
Follow Microsoft C# conventions:
#### Classes and Methods
```
// PascalCase for classes, methods, properties, and public fields
public class GameManager { }
public class AudioManager { }
public class PlayerController { }
public void Initialize() { }
public int MaxHealth { get; set; }
```
#### Fields and Variables
```
// Private instance fields: _camelCase
private int _currentHealth;
private Transform _targetTransform;
// Static fields: s_camelCase
private static int s_instanceCount;
private static GameManager s_instance;
// Public fields: PascalCase (prefer properties)
public int MaxHealth;
// Local variables and parameters: camelCase
public void SetHealth(int newHealth)
{
int previousHealth = _currentHealth;
_currentHealth = newHealth;
}
// Constants: PascalCase
private const int MaxPlayers = 4;
public const string GameVersion = "1.0.0";
```
#### Interfaces
```
// Prefix with 'I' + PascalCase
public interface IInteractable { }
public interface IDamageable { }
public interface IPoolable { }
```
### Scenes
- Levels: `Level01_Forest.unity`
- Menus: `MenuMain.unity`, `MenuSettings.unity`
- Test: `TestPlayerMovement.unity`
## Assembly Definition Organization
### Core Assemblies
```
Scripts/Runtime/Core/YourCompany.Core.asmdef
Scripts/Runtime/Gameplay/YourCompany.Gameplay.asmdef
Scripts/Runtime/UI/YourCompany.UI.asmdef
Scripts/Runtime/DOTS/YourCompany.DOTS.asmdef
Scripts/Editor/YourCompany.Editor.asmdef
Scripts/Tests/YourCompany.Tests.asmdef
```
### Example Assembly Definition
```
{
"name": "YourCompany.Core",
"rootNamespace": "YourCompany.Core",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
```
## Scene Hierarchy Organization
```
Hierarchy:
--- SYSTEMS --- # Persistent (DontDestroyOnLoad)
├── GameManager
├── AudioManager
├── InputManager
└── UIManager
--- LEVEL --- # Level content
├── Environment
│ ├── Terrain
│ ├── Props
│ └── Lighting
├── Gameplay
│ ├── SpawnPoints
│ └── Triggers
└── UI
├── Canvas_HUD
└── Canvas_Menus
--- DYNAMIC --- # Runtime spawned objects
```
## Prefab Structure
```
Player
├── Model # Visual model
├── Colliders # Physics colliders
├── Effects # Particles, effects
└── Audio # Audio sources
```
## DOTS/ECS Structure
### Component Example
```
// Components/HealthComponent.cs
using Unity.Entities;
namespace YourCompany.DOTS.Components
{
public struct HealthComponent : IComponentData
{
public float CurrentHealth;
public float MaxHealth;
}
}
```
### System Example
```
// Systems/HealthSystem.cs
using Unity.Entities;
using Unity.Burst;
namespace YourCompany.DOTS.Systems
{
[BurstCompile]
public partial struct HealthSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
// System logic
}
}
}
```
### Aspect Example
```
// Aspects/CharacterAspect.cs
using Unity.Entities;
using Unity.Transforms;
namespace YourCompany.DOTS.Aspects
{
public readonly partial struct CharacterAspect : IAspect
{
readonly RefRW<LocalTransform> _transform;
readonly RefRW<HealthComponent> _health;
}
}
```
## Best Practices
### Naming
- Use PascalCase for all public identifiers (classes, methods, properties)
- Use _camelCase for private instance fields
- Use s_camelCase for static fields
- Use camelCase for local variables and parameters
- Use meaningful, descriptive names - prefer clarity over brevity
- Avoid abbreviations except widely known ones (UI, FX, AI)
- No Hungarian notation or type prefixes
### Organization
- Organize assets by type through folder structure, not prefixes
- Use Assembly Definitions to reduce compilation time
- Separate Runtime and Editor code
- Group DOTS code separately from MonoBehaviour code
- Use Addressables for content management with clear grouping strategy
### Architecture
- Use ScriptableObject-based architecture for events and shared data
- Implement EventChannel pattern for decoupled communication
- Use Assembly Definitions to enforce architectural boundaries
- Separate concerns: Core, Gameplay, UI, Utilities
- Create custom packages for reusable systems
### Testing
- Organize tests by type: Unit, Integration, Functional, Performance
- Use separate assemblies for test code
- Create TestUtilities assembly for shared test helpers
- Write tests for critical gameplay systemsDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

