Loading...
Loading...
Optimize your Unity projects with these expert C# coding guidelines. Focus on performance, clean architecture, and cross-platform efficiency using proven Do/Don't rules with practical examples.
**Code Organization and Style**
**Do:** Organize code with #region blocks for better readability, use PascalCase for public members and camelCase for private ones, and apply [SerializeField] for inspector-exposed private fields.
*Example:*
```csharp
[SerializeField] private float m_speed;
public float Speed => m_speed;
```
**Don't:** Scatter code without structure or expose private fields directly without attributes.
*Example (Avoid):*
```csharp
public float speed; // No casing consistency or serialization
```
**Performance and Architecture**
**Do:** Favor TryGetComponent over GetComponent to prevent null errors, implement object pooling for repeated instantiations, and use ScriptableObjects for shared data.
*Example:*
```csharp
if (TryGetComponent<Rigidbody>(out var rb)) { rb.AddForce(Vector3.up); }
```
**Don't:** Rely on expensive GameObject.Find() or Transform.Find() in Update loops.
*Example (Avoid):*
```csharp
GameObject.Find("Player"); // Slow and unreliable
```
**Unity-Specific Optimizations**
**Do:** Use TextMeshPro for all text, Coroutines for async timing, Job System for heavy computations, and LOD for 3D models; wrap editor code in #if UNITY_EDITOR.
*Example:*
```csharp
#if UNITY_EDITOR
[ContextMenu("Test")] private void Test() { Debug.Log("Test"); }
#endif
```
**Don't:** Instantiate/destroy objects frequently without pooling or use legacy UI Text components.
*Example (Avoid):*
```csharp
Instantiate(prefab); Destroy(gameObject); // Causes GC spikes
```
**Naming Conventions**
**Do:** Prefix members with m_ (e.g., m_health), constants with c_ (e.g., c_maxHealth), statics with s_, and use descriptive names for methods/properties.
*Example:*
```csharp
private const int c_MaxHealth = 100;
private int m_currentHealth;
```
**Don't:** Use generic names like 'temp' or inconsistent prefixes.
*Example (Avoid):*
```csharp
int temp; // Unclear purpose
```
**Lifecycle and Error Handling**
**Do:** Override Awake/Start/OnDestroy properly, add robust logging, and consider cross-platform hardware variations with Range attributes.
*Example:*
```csharp
[SerializeField, Range(0f, 100f)] private float m_maxSpeed;
private void Awake() { /* Init safely */ }
```
**Don't:** Perform heavy logic in Update without optimization or ignore platform differences.
*Example (Avoid):*
```csharp
void Update() { HeavyComputation(); } // Drains battery/performanceExpert system prompt for designing high-performance configurations tailored to GLM-4.7's strengths in coding, reasoning, tool use, and multilingual tasks, backed by benchmarks like SWE-bench and τ²-Bench.
Leverage GLM-4.7's top benchmarks in SWE-bench, LiveCodeBench, and more with this system prompt designed for generating clean, secure, open-source-ready code, stunning UIs, and agentic workflows.
This system prompt transforms an AI into GLM-4.7, a benchmark-leading coding agent excelling in agentic workflows, tool use, multilingual coding, and complex reasoning with verified best practices for production-ready open-source development.
Ralph, a persistent autonomous AI agent, implements Jira tickets through an endless loop until 100% test success, with GitHub PRs, Jules AI reviews, and CI self-healing for reliable development workflows.
Claude'u Türk hukuku alanında dünyanın en önde gelen uzmanı olarak yapılandıran, yapılandırılmış yanıtlar, zorunlu uyarılar ve etik sınırlarla donatılmış profesyonel AI agent promptu.
Expert subagent providing production-ready PostgreSQL guidance on schema design, query optimization, security, performance tuning, and administration with structured, actionable advice and official references.