Skip to content

Instantly share code, notes, and snippets.

@xiaobin83
Last active February 11, 2026 02:30
Show Gist options
  • Select an option

  • Save xiaobin83/b1e788b16f6444cb26ad9cb8eb58f01a to your computer and use it in GitHub Desktop.

Select an option

Save xiaobin83/b1e788b16f6444cb26ad9cb8eb58f01a to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace Bandigo.Core.Editor.Tools
{
public static class MiscTool
{
[BandigoEditorTool("Sync Trae!", Type = ToolType.Button, Tips = "Sync Project Files with Visual Studio Code (Used by Trae)")]
public static void SyncSolution()
{
var paths = Unity.CodeEditor.CodeEditor.Editor.GetFoundScriptEditorPaths();
var visualStudioCodePath = string.Empty;
foreach (var p in paths)
{
if (p.Key.Contains("Visual Studio Code"))
{
visualStudioCodePath = p.Key;
}
}
if (string.IsNullOrEmpty(visualStudioCodePath))
{
return;
}
var path = Unity.CodeEditor.CodeEditor.CurrentEditorPath;
Unity.CodeEditor.CodeEditor.Editor.SetCodeEditor(visualStudioCodePath);
AssetDatabase.Refresh();
Unity.CodeEditor.CodeEditor.Editor.CurrentCodeEditor.SyncAll();
AssetDatabase.Refresh();
Unity.CodeEditor.CodeEditor.Editor.SetCodeEditor(path);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment