x


Programmatically Exporting an Asset Package

I would like to save the currently open scene file and all it's dependencies to a Unity Asset Package (.unitypackage) file from an Editor script.

It seems that this topic has been previously broached at http://answers.unity3d.com/questions/3237/export-files-to-a-unitypackage-file-from-c , but I am posting anew to include some more ideas on the subject.

Here's a screenshot from MonoDevelop which shows some interesting functions in Unity's dll file: http://img72.imageshack.us/img72/3380/screenshot20100501at556.png

And here's some code I wrote that serves to illustrate my purpose:

var guids : String[] = Array(AssetDatabase.AssetPathToGUID(EditorApplication.currentScene)).ToBuiltin(String);
UnityEditor.AssetServer.ExportPackage(guids, "/");

The code currently returns an "'AssetServer' is not a member of 'UnityEditor'" error when compiling.

Mike_Mac said that this was because the function I need to call is a private one, internal to Unity - but that I might be able to access it through reflection.

Anyone have some ideas on how this could be accomplished?

more ▼

asked May 02 '10 at 01:47 AM

Aubrey Falconer gravatar image

Aubrey Falconer
657 45 53 68

@Aubrey, remember to upvote good answers (and checkmark the correct one).

May 06 '10 at 01:01 AM Cyclops

Hi, doing so would be very interesting! Have you ever managed to implement it?

Aug 13 '10 at 04:07 PM mlapin

Allright ladies and gentlemen ~ Unity 3 has come, and it has disabled reflection and added cool new API tools. I a more interested than ever in creating asset packages programatically, so please have at the bounty!

Dec 24 '10 at 07:15 AM Aubrey Falconer

Bounty ends tomorrow, everyone's suggestions are welcome

Dec 30 '10 at 06:32 AM Aubrey Falconer

this is still only possible with the PRO editions of Unity3D, right?

Aug 07 '11 at 10:17 PM BerggreenDK
(comments are locked)
10|3000 characters needed characters left

2 answers: sort newest

Internal things in UnityEditor/UnityEngine are internal for one of a few reasons: - it doesn't work - it only works if you use it in a very obscure way - we want to be able to change it later without breaking your game - it has some sort of security risk - we didn't realize you might actually want it

That said, you can use reflection to try to call it, but you'd be walking on very thin ice.

more ▼

answered May 02 '10 at 09:56 PM

Lucas Meijer 1 gravatar image

Lucas Meijer 1 ♦♦
7.9k 19 43 85

Thanks for your reply! I wouldn't at all mind Unity breaking my code some time in the future - this will be a nothing more than a component of an easy-to-distribute Editor plugin, and obscurity doesn't scare me :) I have no idea how to go about using reflection, so I may have to give up on the idea for now - but if anyone would like to point my researches in the right direction, I would be most grateful.

May 03 '10 at 03:58 PM Aubrey Falconer
(comments are locked)
10|3000 characters needed characters left

This might be cheesy, but what if you used Windows API functions (SendMessage and such)? Get the window handle and send the menu code that simulates you choosing the menu item.

more ▼

answered Dec 31 '10 at 05:00 AM

Art 1 gravatar image

Art 1
147 2 3 10

It brings me great pain that something as powerful as the Unity editor would have to be controlled through windows API scripting - but you're right, this may indeed be our only option at this time.

Dec 31 '10 at 06:54 AM Aubrey Falconer
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5070
x419
x349
x348

asked: May 02 '10 at 01:47 AM

Seen: 2205 times

Last Updated: Aug 07 '11 at 10:23 PM