-
-
Save li5414/0476a869106fa90f74a15c0577c89a50 to your computer and use it in GitHub Desktop.
Folder to package.tgz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #if UNITY_EDITOR | |
| using System.IO; | |
| using UnityEditor; | |
| using UnityEditor.PackageManager; | |
| using UnityEditor.PackageManager.Requests; | |
| public static class PackageCreator | |
| { | |
| public static void CreateTgzPackage(string packagePath, string sourcePath) | |
| { | |
| PackRequest packRequest = Client.Pack(sourcePath, packagePath); | |
| // | |
| while (!packRequest.IsCompleted) System.Threading.Thread.Sleep(10); | |
| // Check for errors | |
| if (packRequest.Status == StatusCode.Failure) | |
| { | |
| UnityEngine.Debug.LogError($"Failed to create package. Error: {packRequest.Error.message}"); | |
| throw new IOException($"Failed to create package. Error: {packRequest.Error.message}"); | |
| } | |
| } | |
| [MenuItem("Assets/Create package.tgz", false, 0)] private static void CustomOption() | |
| { | |
| DefaultAsset selectedFolder = Selection.activeObject as DefaultAsset; | |
| if (selectedFolder != null) | |
| { | |
| string folderPath = AssetDatabase.GetAssetPath(selectedFolder); | |
| string targetFolder = EditorUtility.OpenFolderPanel("Select target folder", "", ""); | |
| if (!string.IsNullOrEmpty(targetFolder)) | |
| { | |
| CreateTgzPackage(targetFolder, folderPath); | |
| AssetDatabase.Refresh(); | |
| } | |
| } | |
| } | |
| [MenuItem("Assets/Create .tgz", true)] private static bool ValidateCustomOption() =>Selection.activeObject is DefaultAsset; | |
| } | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment