Files
2026-03-13 12:34:01 +07:00

1.6 KiB

Quick Start - Unity Editor Only Analyzer

Bước 1: Analyzer đã được build

Analyzer đã được build thành công tại:

E:\Projects\perfect-world-unity\UnityEditorOnlyAnalyzer\bin\Release\netstandard2.0\UnityEditorOnlyAnalyzer.dll

Bước 2: Kích hoạt Analyzer

Tự động (Khuyến nghị):

  1. Mở Unity Editor
  2. File Assets/Editor/AddAnalyzerPostprocessor.cs sẽ tự động thêm analyzer vào .csproj files khi Unity generate chúng
  3. Reload project trong Visual Studio/VS Code

Thủ công:

Mở file Assembly-CSharp.csproj và thêm trước thẻ </Project>:

  <ItemGroup>
    <Analyzer Include="E:\Projects\perfect-world-unity\UnityEditorOnlyAnalyzer\bin\Release\netstandard2.0\UnityEditorOnlyAnalyzer.dll" />
  </ItemGroup>
</Project>

Bước 3: Kiểm tra

Tạo file test để kiểm tra:

#if UNITY_EDITOR
public class EditorOnlyClass
{
    public static void EditorMethod() { }
}
#endif

public class RegularClass
{
    public void Test()
    {
        EditorOnlyClass.EditorMethod(); // ⚠️ Nên có warning ở đây
    }
}

Bạn sẽ thấy warning trong Visual Studio/VS Code:

UNITY_EDITOR_ONLY_USAGE: Method/Type 'EditorMethod' is only available in UNITY_EDITOR and may cause build errors

Lưu ý

  • Analyzer chỉ hoạt động trong IDE (Visual Studio/VS Code), không phải trong Unity Editor
  • Cần reload project sau khi thêm analyzer
  • Nếu không thấy warnings, kiểm tra Error List trong Visual Studio (View > Error List)

Troubleshooting

Nếu analyzer không hoạt động, xem file SETUP_UNITY_EDITOR_ANALYZER.md để biết chi tiết.