Instruction file imported from Ethan014/wildRift (
.cursor/rules/general-principles.mdc). Copyright stays with the author.
General Principles
Core Values
| Principle | Guideline |
|---|---|
| SOLID | Single responsibility per MonoBehaviour; depend on abstractions |
| DRY | Extract shared logic into utility classes or base classes |
| KISS | Prefer simple, readable code over clever optimizations |
| Composition | Favor component composition over deep inheritance hierarchies |
| Production-grade | Every script must be null-safe, handle edge cases, and clean up resources |
C# Best Practices in Unity
- Use
[SerializeField]instead ofpublicfor inspector-exposed fields - Prefer
TryGetComponent<T>()overGetComponent<T>()when the component might not exist - Use
CompareTag("TagName")instead ofgameObject.tag == "TagName"(avoids GC allocation) - Cache component references in
Awake()orStart(), never inUpdate() - Use
readonlyfor fields that should not change after initialization - Prefer
string.IsNullOrEmpty()overstr == null || str == ""
Anti-Patterns to Avoid
// BAD: GetComponent every frame
void Update() {
GetComponent<Rigidbody>().AddForce(Vector3.up);
}
// GOOD: Cache in Awake
Rigidbody _rb;
void Awake() {
_rb = GetComponent<Rigidbody>();
}
void Update() {
_rb.AddForce(Vector3.up);
}
// BAD: String comparison for tags
if (other.gameObject.tag == "Player") { }
// GOOD: CompareTag
if (other.CompareTag("Player")) { }
// BAD: Find at runtime
void Update() {
var player = GameObject.Find("Player");
}
// GOOD: Reference via inspector or cache
[SerializeField] GameObject player;
File Organization
Assets/
Scripts/ → Standalone utility scripts
MOBA Tutorial/ → Game-specific scripts, materials, prefabs
Minions/ → Minion AI, targeting, prefabs, materials
MoveIcon/ → Movement indicator prefab and animations
Scenes/ → Scene files and baked data
Materials/ → Shared materials (skybox, etc.)
Settings/ → URP render pipeline settings
Prefabs/ → Shared prefab assets
Dependencies
- Never reference Editor-only APIs (
UnityEditor) outside#if UNITY_EDITORblocks - Keep
usingstatements minimal and ordered: Unity namespaces first, then System, then project - Avoid third-party packages unless absolutely necessary; prefer Unity built-in systems