@mflrevan/ucp 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -80,6 +80,47 @@ namespace UCP.Bridge
80
80
  return CreateReimportResult(requestedPath, assetPath, true, false, null);
81
81
  }
82
82
 
83
+ public static Dictionary<string, object> ReimportRecursive(string requestedPath, bool forceSynchronous = true)
84
+ {
85
+ var assetPath = GetPrimaryAssetPath(requestedPath);
86
+ if (string.IsNullOrEmpty(assetPath))
87
+ throw new ArgumentException("Missing 'path' parameter");
88
+ if (!IsProjectAssetPath(assetPath))
89
+ throw new ArgumentException($"Path is not under Assets/ or Packages/: {requestedPath}");
90
+
91
+ if (!AssetDatabase.IsValidFolder(assetPath))
92
+ return Reimport(requestedPath, forceSynchronous);
93
+
94
+ var options = ImportAssetOptions.ForceUpdate;
95
+ if (forceSynchronous)
96
+ options |= ImportAssetOptions.ForceSynchronousImport;
97
+
98
+ var guidResults = AssetDatabase.FindAssets(string.Empty, new[] { assetPath });
99
+ var importedPaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
100
+
101
+ foreach (var guid in guidResults)
102
+ {
103
+ var childPath = AssetDatabase.GUIDToAssetPath(guid);
104
+ if (string.IsNullOrEmpty(childPath) || AssetDatabase.IsValidFolder(childPath))
105
+ continue;
106
+
107
+ AssetDatabase.ImportAsset(childPath, options);
108
+ importedPaths.Add(childPath);
109
+ RecordReimport(childPath);
110
+ }
111
+
112
+ return new Dictionary<string, object>
113
+ {
114
+ ["requestedPath"] = requestedPath,
115
+ ["assetPath"] = assetPath,
116
+ ["recursive"] = true,
117
+ ["requested"] = importedPaths.Count,
118
+ ["reimported"] = importedPaths.Count,
119
+ ["skipped"] = 0,
120
+ ["paths"] = new List<object>(importedPaths)
121
+ };
122
+ }
123
+
83
124
  public static Dictionary<string, object> SaveImporterSettings(string requestedPath, AssetImporter importer, bool noReimport)
84
125
  {
85
126
  if (importer == null)
@@ -1,5 +1,9 @@
1
1
  using UnityEditor;
2
2
  using UnityEditor.Compilation;
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.IO;
6
+ using System.Text.RegularExpressions;
3
7
 
4
8
  namespace UCP.Bridge
5
9
  {
@@ -9,12 +13,15 @@ namespace UCP.Bridge
9
13
  {
10
14
  router.Register("compile", HandleCompile);
11
15
  router.Register("refresh-assets", HandleRefresh);
16
+ router.Register("script/doctor", HandleScriptDoctor);
12
17
  }
13
18
 
14
19
  private static object HandleCompile(string paramsJson)
15
20
  {
21
+ AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
16
22
  CompilationPipeline.RequestScriptCompilation();
17
- return new { status = "ok", message = "Compilation requested" };
23
+ TrySyncSolution();
24
+ return new { status = "ok", message = "Asset database refreshed and compilation requested" };
18
25
  }
19
26
 
20
27
  private static object HandleRefresh(string paramsJson)
@@ -22,5 +29,85 @@ namespace UCP.Bridge
22
29
  AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
23
30
  return new { status = "ok", message = "Asset database refreshed" };
24
31
  }
32
+
33
+ private static object HandleScriptDoctor(string paramsJson)
34
+ {
35
+ var p = MiniJson.Deserialize(paramsJson) as Dictionary<string, object>;
36
+ var fix = p != null && p.TryGetValue("fix", out var fixObj) && fixObj != null && Convert.ToBoolean(fixObj);
37
+ var projectRoot = Directory.GetParent(UnityEngine.Application.dataPath).FullName;
38
+ var projects = new List<object>();
39
+ var staleProjectCount = 0;
40
+ var missingFileCount = 0;
41
+ var deletedProjectCount = 0;
42
+
43
+ foreach (var csproj in Directory.GetFiles(projectRoot, "*.csproj", SearchOption.TopDirectoryOnly))
44
+ {
45
+ var missing = FindMissingCompileItems(projectRoot, csproj);
46
+ if (missing.Count > 0)
47
+ {
48
+ staleProjectCount++;
49
+ missingFileCount += missing.Count;
50
+ if (fix)
51
+ {
52
+ File.Delete(csproj);
53
+ deletedProjectCount++;
54
+ }
55
+ }
56
+
57
+ projects.Add(new Dictionary<string, object>
58
+ {
59
+ ["path"] = csproj,
60
+ ["missingCompileItems"] = missing.ConvertAll<object>(item => item),
61
+ ["stale"] = missing.Count > 0
62
+ });
63
+ }
64
+
65
+ if (fix)
66
+ {
67
+ AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
68
+ TrySyncSolution();
69
+ }
70
+
71
+ return new Dictionary<string, object>
72
+ {
73
+ ["status"] = "ok",
74
+ ["projectRoot"] = projectRoot,
75
+ ["projectCount"] = projects.Count,
76
+ ["staleProjectCount"] = staleProjectCount,
77
+ ["missingFileCount"] = missingFileCount,
78
+ ["deletedProjectCount"] = deletedProjectCount,
79
+ ["fixed"] = fix,
80
+ ["projects"] = projects
81
+ };
82
+ }
83
+
84
+ private static List<string> FindMissingCompileItems(string projectRoot, string csproj)
85
+ {
86
+ var missing = new List<string>();
87
+ var content = File.ReadAllText(csproj);
88
+ foreach (Match match in Regex.Matches(content, "<Compile Include=\"([^\"]+\\.cs)\""))
89
+ {
90
+ var include = match.Groups[1].Value.Replace('\\', Path.DirectorySeparatorChar);
91
+ var fullPath = Path.GetFullPath(Path.Combine(projectRoot, include));
92
+ if (!File.Exists(fullPath))
93
+ missing.Add(include.Replace('\\', '/'));
94
+ }
95
+
96
+ return missing;
97
+ }
98
+
99
+ private static void TrySyncSolution()
100
+ {
101
+ try
102
+ {
103
+ var syncVs = typeof(Editor).Assembly.GetType("UnityEditor.SyncVS");
104
+ var method = syncVs?.GetMethod("SyncSolution", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic, null, Type.EmptyTypes, null);
105
+ method?.Invoke(null, null);
106
+ }
107
+ catch
108
+ {
109
+ // Best-effort only; Unity may regenerate solution files asynchronously.
110
+ }
111
+ }
25
112
  }
26
113
  }
@@ -18,7 +18,10 @@ namespace UCP.Bridge
18
18
  {
19
19
  var parameters = ParseParameters(paramsJson);
20
20
  var requestedPath = RequirePath(parameters);
21
- return AssetImportSupport.Reimport(requestedPath);
21
+ var recursive = TryGetOptionalBool(parameters, "recursive");
22
+ return recursive
23
+ ? AssetImportSupport.ReimportRecursive(requestedPath)
24
+ : AssetImportSupport.Reimport(requestedPath);
22
25
  }
23
26
 
24
27
  private static object HandleRead(string paramsJson)