Mobile optimization

From nlelouche/Unity-SkillForge · View interactive version

Mobile optimization is an AI agent skill from the GitHub repository nlelouche/Unity-SkillForge. Mobile-specific optimization for Android/iOS including framerate, resolution, thermal, and battery management.

How to use this skill

Skill file

Mobile Optimization

Overview

Mobile-specific performance optimization for Android/iOS. Covers framerate targeting, resolution scaling, thermal throttling, and battery efficiency.

When to Use

Mobile Constraints

┌─────────────────────────────────────────────────────────────┐
│                 MOBILE PERFORMANCE PYRAMID                  │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│                    ┌────────┐                               │
│                    │ BATTERY│                               │
│                    └────┬───┘                               │
│                ┌────────┴────────┐                          │
│                │    THERMAL      │                          │
│                └────────┬────────┘                          │
│           ┌─────────────┴─────────────┐                     │
│           │         MEMORY            │                     │
│           └─────────────┬─────────────┘                     │
│      ┌──────────────────┴──────────────────┐                │
│      │             CPU / GPU               │                │
│      └─────────────────────────────────────┘                │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Key Settings

| Setting | Low Device | High Device |

|---------|:----------:|:-----------:|

| Target FPS | 30 | 60 |

| Resolution Scale | 0.7 | 1.0 |

| Shadow Resolution | 512 | 2048 |

| Texture Quality | Half | Full |

| MSAA | Off | 2x |

Optimization Techniques

| Technique | Impact | Implementation |

|-----------|:------:|----------------|

| Frame Rate Cap | High | Application.targetFrameRate |

| Resolution Scale | High | Screen.SetResolution |

| VSync | Medium | QualitySettings.vSyncCount |

| GPU Skinning | Medium | Player Settings |

| Texture Streaming | High | QualitySettings |

Best Practices

Few-Shot Examples

Example 1: App Configuration

User: "Set up mobile performance."

Agent:

public class MobileConfig : MonoBehaviour
{
    [Header("Performance")]
    [SerializeField] private int _targetFPS = 60;
    [SerializeField] private bool _enableVSync = true;
    [SerializeField] private float _resolutionScale = 1f;
    
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    private static void Initialize()
    {
        var config = new MobileConfig();
        config.ApplySettings();
    }
    
    public void ApplySettings()
    {
        Application.targetFrameRate = _targetFPS;
        QualitySettings.vSyncCount = _enableVSync ? 1 : 0;
        
        if (_resolutionScale < 1f)
        {
            int width = (int)(Screen.width * _resolutionScale);
            int height = (int)(Screen.height * _resolutionScale);
            Screen.SetResolution(width, height, true);
        }
    }
}

Example 2: Adaptive Quality

User: "Auto-adjust quality based on FPS."

Agent:

public class AdaptiveQuality : MonoBehaviour
{
    [SerializeField] private int _targetFPS = 30;
    [SerializeField] private int _fpsThresholdLow = 25;
    [SerializeField] private int _fpsThresholdHigh = 40;
    
    private float _checkInterval = 5f;
    private float _timer;
    private float _avgFPS;
    
    private void Update()
    {
        _avgFPS = Mathf.Lerp(_avgFPS, 1f / Time.deltaTime, 0.1f);
        _timer += Time.deltaTime;
        
        if (_timer >= _checkInterval)
        {
            AdjustQuality();
            _timer = 0;
        }
    }
    
    private void AdjustQuality()
    {
        int current = QualitySettings.GetQualityLevel();
        
        if (_avgFPS < _fpsThresholdLow && current > 0)
        {
            QualitySettings.DecreaseLevel();
            Debug.Log("Quality decreased");
        }
        else if (_avgFPS > _fpsThresholdHigh && current < QualitySettings.names.Length - 1)
        {
            QualitySettings.IncreaseLevel();
            Debug.Log("Quality increased");
        }
    }
}

Example 3: Battery Saver Mode

User: "Add battery saving option."

Agent:

public void EnableBatterySaver(bool enabled)
{
    if (enabled)
    {
        Application.targetFrameRate = 30;
        QualitySettings.SetQualityLevel(0); // Lowest
        Screen.brightness = 0.5f;
    }
    else
    {
        Application.targetFrameRate = 60;
        QualitySettings.SetQualityLevel(2); // Medium
        Screen.brightness = 1f;
    }
    
    PlayerPrefs.SetInt("BatterySaver", enabled ? 1 : 0);
}

Platform Specifics


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 MobileOptimization_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 MobileOptimization_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 MobileOptimization_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.