|
My company is using Unity to create an MMO. If possible I'd like to split the game up into self contained blocks (with occasional dependancies on each other if necessary) containing assets and code, that can be downloaded by the users. The game can then load the blocks at run time and assemble the world. I've managed this quite well for the assets using asset bundles and LoadLevelAdditive(), but I can't find a way to do the same with scripts. How can one distribute and dynamically load scripts without using the one monolithic DLL that Unity builds? Edit: I'm using the standalone Windows player.
(comments are locked)
|
|
I've got a blog post on the subject here: Downloading the hydra. The trick is basically this:
Thanks, AngryAnt. :-) I'll work through this, but this looks to be exactly what I had in mind. I'll post feedback tomorrow.
Jan 05 '10 at 09:41 AM
Nerosis
I got the compilation working by downloading and installing Mono as you suggest in the blog post, and managed to execute the external script. I haven't managed to get it working with the Mono framework that ships with Unity, but that's not a train smash. Thank you. :-)
Jan 06 '10 at 09:32 AM
Nerosis
you have to be careful so no one injects harmful code in your assembly. you should encrypt and sign the packages.
Jun 30 '11 at 11:45 PM
pragmascript
Legendary AngryAnt, thanks for sharing this!
Mar 08 '12 at 12:06 PM
save
(comments are locked)
|
|
Any reason to suppose that AngryAnts solution for downloading compiled scripts also work on iphone and android apps? For me it worked on Android without problems, but iOS made some problems yesterday. However, there were native exceptions, coming from semaphores. Not sure why (I didn't use any threading explicitly), but I hope I can investigate this further today.
Mar 08 '12 at 12:02 PM
Mene
This will not work on iOS as the platform license prohibits execution of arbitrary code. Additionally, because of that restriction, we actually do not have a running JIT compiler, but in stead AOT compile everything. Therefore it would also be technically not feasible.
Aug 30 '12 at 08:53 AM
AngryAnt ♦♦
Hi AngryAnt. I'm sure you understand this better than me, but could you get mono to compile AOT to a .so file (http://www.mono-project.com/AOT) and then use the so instead of a dll?
Oct 12 '12 at 04:47 PM
nosignal
Hi again AngryAnt. Has this iOS restriction changed now that Apple offers In-App Purchases? According to https://developer.apple.com/news/pdf/in_app_purchase.pdf "In-App Purchase will allow you to sell: ... Additional game levels". Does that mean the In-App Purchase can introduce new functionality by introducing new code? Or is it only able to unlock existing code?
Oct 12 '12 at 05:05 PM
nosignal
(comments are locked)
|
|
If you have a standalone executable, you should be able to download dlls to disk, and dynamically load functions from them using the usual .NET/mono methods (don't actually know what those are, but google should find the answer to that). If you are using a web player, then why do you need to do this in the first place? You can always just change the code for the main web player when you need to. Yes, i can still see some valid reasons - code download size, or changing code dynamically while playing or possibly the setup of your build pipeline - but if you describe your situation more detailed, maybe that would help coming up with solutions or workarounds. I should have specified that I'm using the standalone Windows player - I've edited the question. :-) Loading DLLs at runtime should work well. I'm not sure how to compile only a subset of the Unity scripts in the project into a DLL - I'm not sure how to compile for Mono, and what parameters to pass to the compiler, or what other steps Unity goes through to create the DLL.
Jan 05 '10 at 07:43 AM
Nerosis
(comments are locked)
|
|
you can create an assetbundle containing all of your scripts. then you can get all of them from your assetbundles. you can seporate them by their names. it's a better way because can be used with web player too. i am waiting for angryant's solution but it can work for you. also i should mention scenes contain scripts too. even you can run codes generated at runtime by using a class in mon called "C# compiler as a service" this class can execute C# code strings. the class is about 3MB and can be downloaded from mono's web site. The asset bundles do not contain the source, but rather the code is already compiled into your build.
Jan 05 '10 at 09:16 AM
AngryAnt ♦♦
It seems from the forums and my experimentation that asset bundles only contain references to the compiled scripts. The actual script is stored on the project itself. If I add a prefab that references a script to an asset bundle, and then delete the script from the project, the script no longer executes when I import the asset bundle (although the rest of the prefab is there). The same applies to scripts in scenes. I looked at Mono's "compiler as a service" - it could work, but it's going to require a lot of jumping through hoops. I would rather compile a DLL when the asset bundle is created.
Jan 05 '10 at 09:22 AM
Nerosis
(comments are locked)
|

I've actually had an example of how to do this lying around for some time - intended for blogging. I'll dust it off, upload it and link it here later.
That would be much appreciated, AngryAnt!