Skip to content

Commit db8d52b

Browse files
committed
Proxy script step
1 parent 8bae5f0 commit db8d52b

File tree

5 files changed

+125
-6
lines changed

5 files changed

+125
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 1.1.3
22

33
- Fixed issue with unsafe code enabling not restarting the editor
4+
- Proxy script step
45

56
# 1.1.2
67

Editor/AssetScrubber.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,27 @@ private static bool HasValidAssociationExtension(string assetPath) {
991991

992992
return true;
993993
}
994+
995+
public static string GetMetaGuid(string fullAssetPath) {
996+
var fullMetaPath = $"{fullAssetPath}.meta";
997+
if (!File.Exists(fullMetaPath)) {
998+
Debug.LogWarning($"Could not find \"{fullMetaPath}\"");
999+
return null;
1000+
}
1001+
1002+
var contents = File.ReadAllText(fullMetaPath);
1003+
var match = GuidPattern.Match(contents);
1004+
if (!match.Success) return null;
1005+
1006+
return match.Groups["guid"].Value;
1007+
}
9941008

9951009
public static void ReplaceMetaGuid(string rootPath, AssetCatalogue.Entry entry, string guid) {
9961010
var fullAssetPath = Path.Combine(rootPath, entry.RelativePathToRoot);
1011+
ReplaceMetaGuid(fullAssetPath, guid);
1012+
}
1013+
1014+
public static void ReplaceMetaGuid(string fullAssetPath, string guid) {
9971015
var fullMetaPath = $"{fullAssetPath}.meta";
9981016
if (!File.Exists(fullMetaPath)) {
9991017
Debug.LogWarning($"Could not find \"{fullMetaPath}\"");
@@ -1010,6 +1028,19 @@ public static void ReplaceMetaGuid(string rootPath, AssetCatalogue.Entry entry,
10101028
Debug.Log($" - wrote to {fullMetaPath}");
10111029
}
10121030

1031+
public static void ReplaceAssetGuids(string fullAssetPath, string guid) {
1032+
if (!File.Exists(fullAssetPath)) {
1033+
Debug.LogWarning($"Could not find \"{fullAssetPath}\"");
1034+
return;
1035+
}
1036+
1037+
var contents = File.ReadAllText(fullAssetPath);
1038+
contents = GuidPattern.Replace(contents, $"guid: {guid}:");
1039+
File.WriteAllText(fullAssetPath, contents);
1040+
1041+
Debug.Log($" - wrote to {fullAssetPath}");
1042+
}
1043+
10131044
public static void ReplaceAssetGuids(UPPatcherSettings settings, string rootPath, AssetCatalogue.Entry entry, Dictionary<string, AssetCatalogue.Entry> entryMap) {
10141045
if (!HasValidAssociationExtension(entry.RelativePathToRoot)) {
10151046
return;

Editor/PatcherUtility.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,19 @@ public static void ExcludeDllFromLoading(string path) {
344344
}
345345
}
346346

347+
[MenuItem("CONTEXT/Object/Debug/Assembly Type Name")]
348+
[MenuItem("Edit/Test/Debug/Assembly Type Name")]
349+
public static void DebugAssemblyTypeName() {
350+
var selection = Selection.activeObject;
351+
if (!selection) return;
352+
353+
if (selection is MonoScript m) {
354+
Debug.Log(m.GetClass().AssemblyQualifiedName);
355+
} else {
356+
Debug.Log(selection.GetType().AssemblyQualifiedName);
357+
}
358+
}
359+
347360
[MenuItem("CONTEXT/Object/Debug/Guid")]
348361
[MenuItem("Edit/Test/Debug/Guid")]
349362
public static void DebugGuid() {
@@ -359,13 +372,21 @@ public static void DebugGuid() {
359372
return;
360373
}
361374

362-
var instance = AssetDatabase.LoadMainAssetAtPath(path);
363-
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(instance, out guid, out long fileId)) {
364-
Debug.Log($"{guid} {fileId}");
365-
}
375+
var instances = AssetDatabase.LoadAllAssetsAtPath(path);
376+
foreach (var i in instances) {
377+
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(i, out guid, out long fileId)) {
378+
if (i is MonoScript s) {
379+
Debug.Log($"[{i.GetType().Name}] \"{s.GetClass()}\" -> {guid} {fileId}");
380+
// get name from guid and fileid
381+
382+
} else {
383+
Debug.Log($"[{i.GetType().Name}] \"{i}\" -> {guid} {fileId}");
384+
}
385+
}
366386

367-
var globalID = GlobalObjectId.GetGlobalObjectIdSlow(instance);
368-
Debug.Log(globalID);
387+
var globalID = GlobalObjectId.GetGlobalObjectIdSlow(i);
388+
Debug.Log(globalID);
389+
}
369390
}
370391

371392
[MenuItem("CONTEXT/Object/Debug/Local FileId")]
@@ -497,6 +518,16 @@ private static async Task ProcessAsync<TSource, TResult>(
497518
try { resultProcessor(item, result); }
498519
finally { oneAtATime.Release(); }
499520
}
521+
522+
public static bool HasDomainReloadingDisabled() {
523+
if (EditorSettings.enterPlayModeOptionsEnabled &&
524+
EditorSettings.enterPlayModeOptions.HasFlag(EnterPlayModeOptions.DisableDomainReload)) {
525+
Debug.LogWarning("Domain reloading is disabled!");
526+
return true;
527+
}
528+
529+
return false;
530+
}
500531

501532
// #if UNITY_EDITOR_WIN
502533
// [DllImport("user32.dll")]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.IO;
2+
using Cysharp.Threading.Tasks;
3+
using UnityEngine;
4+
5+
namespace Nomnom.UnityProjectPatcher.Editor.Steps {
6+
public readonly struct MakeProxyScriptsStep: IPatcherStep {
7+
private readonly Proxy[] _proxys;
8+
private const string CONTENT = @"
9+
namespace %NAMESPACE% {
10+
public class %TYPE%: global::%TYPE% { }
11+
}";
12+
13+
public MakeProxyScriptsStep(params Proxy[] proxys) {
14+
_proxys = proxys;
15+
}
16+
17+
public UniTask<StepResult> Run() {
18+
var settings = this.GetSettings();
19+
var arSettings = this.GetAssetRipperSettings();
20+
if (!arSettings.TryGetFolderMapping("Scripts", out var scriptsFolder, out var exclude) || exclude) {
21+
Debug.Log("Skipping MakeProxyScriptsStep because no scripts folder was found");
22+
return UniTask.FromResult(StepResult.Success);
23+
}
24+
25+
foreach (var proxy in _proxys) {
26+
var content = CONTENT
27+
.Replace("%NAMESPACE%", proxy.typeNamespace)
28+
.Replace("%TYPE%", proxy.typeName);
29+
30+
var path = Path.GetFullPath(Path.Combine(settings.ProjectGameAssetsPath, scriptsFolder, $"{proxy.typeName}.cs"));
31+
var folder = Path.GetDirectoryName(path);
32+
if (!Directory.Exists(folder)) {
33+
Directory.CreateDirectory(folder);
34+
}
35+
File.WriteAllText(path, content);
36+
}
37+
38+
return UniTask.FromResult(StepResult.Success);
39+
}
40+
41+
public void OnComplete(bool failed) { }
42+
43+
public readonly struct Proxy {
44+
public readonly string typeName;
45+
public readonly string typeNamespace;
46+
47+
public Proxy(string typeName, string typeNamespace) {
48+
this.typeName = typeName;
49+
this.typeNamespace = typeNamespace;
50+
}
51+
}
52+
}
53+
}

Editor/Steps/Processing/MakeProxyScriptsStep.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)