diff --git a/Assets/YooAsset/Editor/SBPPackageImporter.cs b/Assets/YooAsset/Editor/SBPPackageImporter.cs new file mode 100644 index 00000000..7d16f6d7 --- /dev/null +++ b/Assets/YooAsset/Editor/SBPPackageImporter.cs @@ -0,0 +1,36 @@ +using UnityEditor; +using UnityEditor.PackageManager; +using UnityEngine; + +namespace YooAsset.Editor +{ + /// + /// 自动导入SBP依赖类 + /// + [InitializeOnLoad] + public static class SBPPackageImporter + { + static SBPPackageImporter() + { + InstallPackage("com.unity.scriptablebuildpipeline"); + } + + private static bool IsPackageInstalled(string packageName) + { + return UnityEditor.PackageManager.PackageInfo.FindForAssetPath($"Packages/{packageName}") != null; + } + + public static bool InstallPackage(string packageName) + { + if (IsPackageInstalled(packageName)) + { + return false; + } + Debug.Log($"Install...{packageName}"); + var request = Client.Add(packageName); + while (!request.IsCompleted) { }; + if (request.Error != null) Debug.LogError(request.Error.message); + return request.Error == null; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/SBPPackageImporter.cs.meta b/Assets/YooAsset/Editor/SBPPackageImporter.cs.meta new file mode 100644 index 00000000..33995e98 --- /dev/null +++ b/Assets/YooAsset/Editor/SBPPackageImporter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7bed458456c04424bcee443f2eecb6ad +timeCreated: 1712647319 \ No newline at end of file