AssetGuid.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Copyright(c) Live2D Inc. All rights reserved.
  3. *
  4. * Use of this source code is governed by the Live2D Open Software license
  5. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
  6. */
  7. using UnityEditor;
  8. using Object = UnityEngine.Object;
  9. namespace Live2D.Cubism.Editor.Importers
  10. {
  11. /// <summary>
  12. /// Provides helper methods for working with Unity assets.
  13. /// </summary>
  14. internal static class AssetGuid
  15. {
  16. /// <summary>
  17. /// Loads an asset by Guid.
  18. /// </summary>
  19. /// <typeparam name="T">The type of asset to load.</typeparam>
  20. /// <param name="guid">The guid to query for.</param>
  21. /// <returns>The loaded asset on </returns>
  22. public static T LoadAsset<T>(string guid) where T : Object
  23. {
  24. return AssetDatabase.LoadAssetAtPath<T>(AssetDatabase.GUIDToAssetPath(guid));
  25. }
  26. /// <summary>
  27. /// Gets the Guid of an asset.
  28. /// </summary>
  29. /// <param name="asset"></param>
  30. /// <returns></returns>
  31. public static string GetGuid<T>(T asset) where T : Object
  32. {
  33. return AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(asset));
  34. }
  35. }
  36. }