Created
October 25, 2019 07:14
-
-
Save liortal53/be2596c9572c82c0b59b291bfdcb733e to your computer and use it in GitHub Desktop.
This file contains 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
using System.IO; | |
using UnityEditor.PackageManager; | |
using UnityEngine; | |
namespace UnityEditor.Extensions | |
{ | |
/// <summary> | |
/// Editor extension for embedding packages as a local copy in the project. | |
/// This can be useful in case you want to modify the package's source code. | |
/// </summary> | |
public static class EmbedPackage | |
{ | |
[MenuItem("Assets/Embed Package", false, 1000000)] | |
private static void EmbedPackageMenuItem() | |
{ | |
var selection = Selection.activeObject; | |
var packageName = Path.GetFileName(AssetDatabase.GetAssetPath(selection)); | |
Debug.Log($"Embedding package '{packageName}' into the project."); | |
Client.Embed(packageName); | |
AssetDatabase.Refresh(); | |
} | |
[MenuItem("Assets/Embed Package", true)] | |
private static bool EmbedPackageValidation() | |
{ | |
var selection = Selection.activeObject; | |
if (selection == null) | |
{ | |
return false; | |
} | |
var path = AssetDatabase.GetAssetPath(selection); | |
var folder = Path.GetDirectoryName(path); | |
// We only deal with direct folders under Packages/ | |
return folder == "Packages"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment