#if UNITY_EDITOR using System; using UnityEditor; using UnityEngine; using Object = UnityEngine.Object; using PackageInfo = UnityEditor.PackageManager.PackageInfo; namespace DTT.Utils.EditorUtilities { /// /// Provides utility methods for interacting with packages in Unity's 'Packages' folder. /// public static class PackageUtility { /// /// Returns the package info of an asset. /// /// The asset to get the package info for. /// The package info. public static PackageInfo GetPackageInfo(this Object asset) { if (asset == null) throw new ArgumentNullException(nameof(asset)); string assetPath = AssetDatabase.GetAssetPath(asset); if (string.IsNullOrEmpty(assetPath)) { Debug.LogWarning($"Asset {asset.name} was not found in the asset database. Make sure it references an actual asset."); return null; } PackageInfo info = PackageInfo.FindForAssetPath(assetPath); if (info == null) Debug.LogWarning($"No package info was found for asset {asset.name}. Make sure it is inside a package folder."); return info; } } } #endif