🇺🇸 English | 🇺🇦 Українська
Unity tool for analyzing C# code structure and generating XML files with metadata about classes, methods, and fields. Specifically designed to improve context for AI assistants and tools. Allows AI to better understand project architecture without needing to index all code.
- Open Package Manager in Unity (Window > Package Manager)
- Click "+" in the top left corner
- Select "Add package from git URL..."
- Paste URL:
https://github.com/ErikTakoev/Unity-AI-Context.git
- Click "Add"
- In the main menu select:
Expecto > AI Context > Create Settings
- The
CodeAnalyzerSettings.asset
file will be created automatically in theAssets/Expecto
folder. - If needed, move the file to your desired project folder.
- Configure parameters:
- Output Directory: directory for saving XML files
- Namespace Filters: namespaces to analyze
- Combined Namespace Filters: namespaces to combine into a single XML file
Code analysis runs automatically on Unity startup or script recompilation. You can also run analysis manually:
- In the main menu select:
Expecto > AI Context > Generate Context
Adds additional context to a class, method, field, or property:
[ContextCodeAnalyzer(
@purpose: "Attempts to generate a new chip if the generator is charged and there is free space.",
@usage: "Call when generator is charged and a chip needs to be generated, either automatically or manually.",
@returns: "True if a chip was generated, false otherwise.",
@notes: "Handles charge decrement, state transitions, and chip creation. Sets waiting state if no space is available."
)]
private bool TryGenerateChip()
{
...
}
Excludes a class, method, or field from analysis:
[IgnoreCodeAnalyzer]
private void TestFillField()
{
...
}
- Rule file: context-guidelines.mdc — add rule for cursor, or use as context
- Prompt:
"Add context for classes, methods, and fields according to the rules in @context-guidelines.mdc"
— use this exact text for better results - Run AI agent on your code files
- Review generated context attributes
Generated XML files contain the following information:
<CodeAnalysis Namespace="Merge2">
<Class n="ChipGenerator" b="Chip" c="Purpose: Represents a chip that can generate other chips, supporting both automatic and manual generation modes.; Usage: Attach to a cell in the game field. Initialize with ChipData. Handles chip generation, charging, and visual effects.; Notes: Manages event subscriptions, runtime state, and effect activation. Key for gameplay mechanics involving chip creation and field interaction.">
<Fields>
...
<Field v="- generatorData: ChipGeneratorData" c="Purpose: Stores static configuration for the chip generator.; Usage: Initialized in Init from ChipData. Used for generation logic.; Notes: Should not be null. Affects generator mode and chip creation." />
...
</Fields>
<Methods>
...
<Method v="- TryGenerateChip(): bool" c="Purpose: Attempts to generate a new chip if the generator is charged and there is free space.; Usage: Call when generator is charged and a chip needs to be generated, either automatically or manually.; Returns: True if a chip was generated, false otherwise.; Notes: Handles charge decrement, state transitions, and chip creation. Sets waiting state if no space is available." />
...
</Methods>
</Class>
</CodeAnalysis>
Abbreviation explanations:
- n — class name
- b — base class
- c — context (description)
- v — value
Access modifiers:
- ++ and + — public
- +- — public getter, private setter
- ~ — protected
- - — private