场景:
导出资源包unity
方法一
操作步骤:
1、在Project界面中选择想要导出的资源
2、右键,选择Export Package…选项
3、选择Export…选项
4、选择路径,保存
方法二
代码
using UnityEngine;
using UnityEditor;
public class ExporPackage : EditorWindow
{
string savePath = ""; //文件保存路径
[MenuItem("Tools/导出资源包", false, -1)]
static void ShowWindow()
{
EditorWindow.GetWindow(typeof(ExporPackage));
}
void OnGUI()
{
UnityEngine.Object[] objects = Selection.objects; //选中的所有对象
string[] objectsPath = new string[objects.Length]; //存放所有选中对象的路径
for(int i = 0; i < objects.Length; i++)
{
objectsPath[i] = AssetDatabase.GetAssetPath(objects[i]);
}
objectsPath = AssetDatabase.GetDependencies(objectsPath);
GUILayout.BeginVertical();
GUILayout.Label("导出资源包", "WarningOverlay");
if(GUILayout.Button("导出"))
{
savePath = EditorUtility.SaveFilePanel("请选择路径", "", "", "unitypackage");
if(savePath == "") //如果选择取消,则路径为空
{
return;
}
AssetDatabase.ExportPackage(objectsPath, savePath);
}
GUILayout.EndVertical();
}
}