From b644fd86b73a20db3bc668e7a979df17c8c30c80 Mon Sep 17 00:00:00 2001 From: Artem Date: Thu, 3 Feb 2022 17:57:26 +0200 Subject: [PATCH] feat: Added AssetDatabaseHelper.GetUniqueGUID() method --- Editor/Helpers/AssetDatabaseHelper.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Editor/Helpers/AssetDatabaseHelper.cs b/Editor/Helpers/AssetDatabaseHelper.cs index 6c4a50b..1985665 100644 --- a/Editor/Helpers/AssetDatabaseHelper.cs +++ b/Editor/Helpers/AssetDatabaseHelper.cs @@ -24,6 +24,23 @@ public static Type GetTypeFromGUID(string guid) return script == null ? null : script.GetClassType(); } + + /// + /// Returns a unique GUID that is known to have no conflicts with the existing assets, so that you create a new asset manually. + /// + /// A unique asset GUID. + public static string GetUniqueGUID() + { + GUID newGUID; + + do + { + newGUID = GUID.Generate(); + } + while ( ! string.IsNullOrEmpty(AssetDatabase.GUIDToAssetPath(newGUID.ToString()))); + + return newGUID.ToString(); + } /// /// Completely prevents AssetDatabase from importing assets or refreshin.