Depends on what exactly you want.
So I’ll show you how I deal with the fact that System.Guid is not serializable by default. I wrote a struct that mirrors the shape of System.Guid exactly:
[System.Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct SerializableGuid
{
#region Fields
[SerializeField]
public int a;
[SerializeField]
public short b;
[SerializeField]
public short c;
[SerializeField]
public byte d;
[SerializeField]
public byte e;
[SerializeField]
public byte f;
[SerializeField]
public byte g;
[SerializeField]
public byte h;
[SerializeField]
public byte i;
[SerializeField]
public byte j;
[SerializeField]
public byte k;
#endregion
Yes it’s a bit more code that converting it to a string, but I don’t care. It means I don’t have to do any parsing or what not… which in terms of deserializing a prefab or a scene isn’t all that difference in cost. But if say you’re using netcode for gameobjects this actually is much more beneficial when transmitting remotely.
Now I can easily cast to a System.Guid by calling the constructor that accepts these same values:
public System.Guid ToGuid() => new System.Guid(a, b, c, d, e, f, g, h, i, j, k);
But importantly I can cast from a System.Guid to this SerializableGuid by using unsafe C# allowing me to get the address of the guid, cast it to a SerializableGuid pointer, then dereference that pointer:
public unsafe static implicit operator SerializableGuid(System.Guid guid)
{
return *(SerializableGuid*)&guid;
}
(note - &guid is getting the address of the variable ‘guid’, (SerializableGuid*) is casting it to our pointer, then the leading * on the front is the dereference… you read this logic right to left)
I have other various simple method associated with it and you can find it all in here:
https://github.com/lordofduct/spacepuppy-unity-framework-4.0/blob/master/Framework/com.spacepuppy.core/Runtime/src/SerializableGuid.cs
Now of course we will also need a PropertyDrawer… and this is where it gets a little complicated but also gets to your question of “generating a guid”.
So before I get to the PropertyDrawer I will note in the SerializableGuid I have an attribute you can use called ConfigAttribute:
public class ConfigAttribute : System.Attribute
{
public bool AllowZero;
/// <summary>
/// Attempts to make the guid match the guid associated with the asset this is on.
/// Note this only works if it's on an asset that exists on disk (ScriptableObject, Prefab).
/// Also it means guids will match across all scripts that are on a prefab with this flagged. (since the prefab only has one guid)
/// Really... this should be mainly done with ScriptableObjects only, Prefab's are just a
/// sort of bonus but with caveats.
///
/// New instances created via 'Instantiate' or 'CreateInstance' will not get anything.
/// This is editor time only for assets on disk!
/// </summary>
public bool LinkToAsset;
/// <summary>
/// Attempts to make the guid match the targetObjectId & targetPrefabId of the GlobalObjectId from the object
/// for the upper and lower portions of the guid respectively. If LinkToAsset is true, that takes precedance to this.
/// </summary>
public bool LinkToGlobalObjectId;
/// <summary>
/// The guid will be displayed as an object reference field showing the asset related to the guid.
/// Dragging an object onto said field will update its value unless any LinkTo* is true.
/// </summary>
public bool ObjectRefField;
}
This allows me to on the fly decorate my editor for it and have different ways to generate the guid.
public class zTest01 : MonoBehaviour
{
public SerializableGuid PlaneGuid; //yes - I am noticing now that I typed plane instead of plain... no point in changing it now. This is what happens when I quickly write up stuff on the spot
[SerializableGuid.Config(AllowZero = true)]
public SerializableGuid AllowZeroGuid;
[SerializableGuid.Config(LinkToAsset = true)]
public SerializableGuid LinkToAssetGuid;
[SerializableGuid.Config(LinkToGlobalObjectId = true)]
public SerializableGuid LinkToGlobalObjectIdGuid;
[SerializableGuid.Config(ObjectRefField = true)]
public SerializableGuid ObjRefGuid;
[SerializableGuid.Config(ObjectRefField = true, LinkToAsset = true)]
public SerializableGuid ObjRefLinkedGuid;
}

Note the slight difference in each configuration when drawn.
Plain Guid by default ALWAYS is non-zero and automatically generates a guid for you (random-ish via System.Guid.NewGuid). There is a button the generate a new one.
Allowing a zero-guid defaults it to zero, but still gives you a ‘New Id’ button.
Link to asset guid sets the guid to the guid of the asset this script is attached to (in this case it’s on a prefab named ‘Test’. This guid is what would be found in the Test.prefab.meta file. This is the same guid that Addressables uses for generating its guids for your prefabs). Note because it relies on the asset guid… this option only works if it’s attached to an asset… think Prefab, ScriptableObject, the sort.
LinkToGlobalObjectId links it to… the GlobalObjectId. This can be useful for in scene objects since the asset id of an object in the scene will be the scene’s asset id (that’s that asset in which the script exists), this will be more unique as its the global object id as returned by GlobalObjectId.GetGlobalObjectIdSlow:
https://docs.unity3d.com/ScriptReference/GlobalObjectId.GetGlobalObjectIdSlow.html
Lastly there is the ‘ObjRefGuid’ which sets the guid to the asset guid, but displays it as an object ref field. This one may seem a little weird but I created it before I got into Addressables and it allows me to reference an asset without loading the asset. Then I’d have a factory somewhere that allowed me to load up the asset by said guid (basically what addressables does, but not as feature rich). And it’s convenient to display such things as an object ref field rather than as the guid itself.
…
But yeah, that’s a lot of different ways to “generate” a guid based on various aspects of your target.
The PropertyDrawer… mind you… it’s a lot. This isn’t trivial stuff that you’re going to grok right off the top of your head. I’m sort of jerking the Unity API around a bit to get this all (also it only works at editor time, this auto generation is all editor based).
Aside from its dependency on my TypeUtil and EditorHelper classes (which are mostly self-explanatory in what they do when you see them) it doesn’t have any major dependencies outside of itself:
https://github.com/lordofduct/spacepuppy-unity-framework-4.0/blob/master/Framework/com.spacepuppy.core/Editor/src/Core/SerializableGuidPropertyDrawer.cs
Honestly, I use this thing a LOT. I love using guids to uniquely identify objects… I don’t know why. And when I first got into Addressables and learned they too tied everything to the asset guid as well it was perfect as it meant my entire system I’d been using up to that point immediately worked with Addressables (as long as it’s in guid mode, addressables is very configurable).
Anyways… figured I’d drop that all here to show how you could definitely have generated guids through the editor if only with a bit of leg work.