Hey, I can see there’s an opportunity here to talk a bit more in depth about why your GUIDs get lost when you use a DLL instead of the C# scripts.
Since each C# script has a corresponding .meta file, there will be a GUID associated to it.
For example, if I have a Prefab with a reference to a MonoBehaviour called Foo01, it will generate the following:
Foo01GO.prefab
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &363824360130945602
GameObject:
...
--- !u!4 &331547713739031506
Transform:
...
--- !u!114 &8569672213745730772
MonoBehaviour:
...
m_Script: {fileID: 11500000, guid: 5e003a5623c777545aadc493adfc4ef5, type: 3}
...
Foo01.cs.meta:
fileFormatVersion: 2
guid: 5e003a5623c777545aadc493adfc4ef5
If we then compile Foo01 into a DLL (via an Assembly Definition), then Foo01 would live inside the DLL (and get compiled into $project/Library/ScriptAssemblies/AssemblyTesting.dll in this case)
If you notice on the Project Browser, the DLL actually has “Assets” which look like scripts.
Note: Having the source code & the assembly in the same project will throw an error:
Plugin ‘Assets/Testing/Assembly/AssemblyTesting.dll’ has the same filename as Assembly Definition File ‘Assets/Testing/Scripts/AssemblyTesting.asmdef’. Rename the assemblies to avoid hard to diagnose issues and crashes.
Next, assign Foo01 from the DLL into your Prefab, and now your Prefab would refer to another GUID and a different fileId:
Foo01GO.prefab:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &363824360130945602
GameObject:
...
--- !u!4 &331547713739031506
Transform:
...
--- !u!114 &8569672213745730772
MonoBehaviour:
...
m_Script: {fileID: -7776210, guid: b51bcd74f73a4e44c8c4a24a6fc1cab9, type: 3}
...
In this case, guid: b51bcd74f73a4e44c8c4a24a6fc1cab9 refers to AssemblyTesting.dll that you’ve added to the project.
So, that’s how you’d do it manually.
If you want to automate it, you could do the following:
Use AssetDatabase.LoadAllAssetsAtPath, for the DLL you’ll get a list of assets, which are MonoScripts that you can then extract the class from.
[MenuItem("AssetDatabase/LoadAllAssets")]
public static void LoadAllAssets()
{
var path = "Assets/Testing/Assembly/AssemblyTesting.dll";
var assets = AssetDatabase.LoadAllAssetsAtPath(path);
foreach (var asset in assets)
{
var monoScript = asset as MonoScript;
AssetDatabase.TryGetGUIDAndLocalFileIdentifier(asset, out var guid, out var localId);
Debug.Log($"Name: {asset.name}, GUID: {guid}, ID: {localId}, type: {asset.GetType()}, class: {monoScript.GetClass().FullName}");
}
}
Output:
Name: Foo02, GUID: b51bcd74f73a4e44c8c4a24a6fc1cab9, ID: 1441409801, type: UnityEditor.MonoScript, class: AssemblyTesting.Foo02
Name: Foo01, GUID: b51bcd74f73a4e44c8c4a24a6fc1cab9, ID: -7776210, type: UnityEditor.MonoScript, class: AssemblyTesting.Foo01
After you have that, you could do something similar to what TextMeshPro does, and create a remapping table (you’ll need the original GUID & fileIds aswell), such that you can update the GUID and fileId in your .meta files and automate this. You’ll need need to patch up the .meta files so you can overwrite the old references with the new ones.
Note: Since the .meta fie for the C# scripts doesn’t contain a fileId, you should be able to rely on fileId:11500000 being the fileId that refers to scripts.
All in all, this should let you get started on writing a conversion tool and then ship a project with a DLL version of your code 