private static void CopyToEditor() { ClipItem item = new ClipItem(ContentType.File); foreach (var guiD in Selection.assetGUIDs) { string path = AssetDatabase.GUIDToAssetPath(guiD); item.Values.Add(AssetPath2FullPath(path)); } CopyClipboardItem(item); Debug.Log("已复制" + Selection.assetGUIDs.Length + "条数据,可在其他 Unity 编辑器里粘贴!"); }
public static void CopyClipboardItem(ClipItem item) { BinaryFormatter formatter = new BinaryFormatter(); using (MemoryStream stream = new MemoryStream()) { formatter.Serialize(stream, item); TextEditor te = new TextEditor { text = Convert.ToBase64String(stream.ToArray()) }; te.OnFocus(); te.Copy(); } }
private static void CopyAsPackage() { string[] assetPaths = new string[Selection.assetGUIDs.Length]; for (int i = 0; i < Selection.assetGUIDs.Length; i++) { assetPaths[i] = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[i]); } string outPath = Path.Combine(Application.temporaryCachePath, Random.Range(0, 1024) + ".unitypackage"); AssetDatabase.ExportPackage(assetPaths, outPath, ExportPackageOptions.Recurse | ExportPackageOptions.IncludeDependencies); ClipItem item = new ClipItem(ContentType.Package); item.Values.Add(outPath); CopyClipboardItem(item); Debug.Log("已导出选中资源!可直接粘贴至任意Assets目录!"); }