Skip to content

Commit

Permalink
feat: Added AssetDatabaseHelper.GetUniqueGUID() method
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidAlloy committed Feb 3, 2022
1 parent 3b30b54 commit b644fd8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Editor/Helpers/AssetDatabaseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ public static Type GetTypeFromGUID(string guid)

return script == null ? null : script.GetClassType();
}

/// <summary>
/// Returns a unique GUID that is known to have no conflicts with the existing assets, so that you create a new asset manually.
/// </summary>
/// <returns>A unique asset GUID.</returns>
public static string GetUniqueGUID()
{
GUID newGUID;

do
{
newGUID = GUID.Generate();
}
while ( ! string.IsNullOrEmpty(AssetDatabase.GUIDToAssetPath(newGUID.ToString())));

return newGUID.ToString();
}

/// <summary>
/// Completely prevents AssetDatabase from importing assets or refreshin.
Expand Down

0 comments on commit b644fd8

Please sign in to comment.