2025-10-11 15:18:09 +08:00
|
|
|
using System;
|
2026-03-18 15:01:36 +08:00
|
|
|
using UnityEngine;
|
2025-10-11 15:18:09 +08:00
|
|
|
|
|
|
|
|
namespace AlicizaX
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates a Unique ID that can be used to identify scripts when saving/loading script state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Serializable]
|
|
|
|
|
public sealed class UniqueID
|
|
|
|
|
{
|
|
|
|
|
public string Id;
|
|
|
|
|
|
|
|
|
|
public UniqueID()
|
|
|
|
|
{
|
|
|
|
|
GenerateIfEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generate an ID only if it's missing.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void GenerateIfEmpty()
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(Id))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Generate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Assign a new random ID and overwrite the previous.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Generate()
|
|
|
|
|
{
|
2026-03-23 19:10:57 +08:00
|
|
|
Id = Utility.IdGenerator.GetGuid();
|
2025-10-11 15:18:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator string(UniqueID uniqueID)
|
|
|
|
|
{
|
|
|
|
|
return uniqueID.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() => Id;
|
|
|
|
|
}
|
|
|
|
|
}
|