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.
I've got a blog post on the subject here: Downloading the hydra. The trick is basically this:
- Compile the external scripts to a .net assembly (the example I provide in the blog post also shows how to have this use UnityEngine functionality).
- Download this via the WWW class.
- Load the bytes of it into the runtime as an assembly.
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.
Any reason to suppose that AngryAnts solution for downloading compiled scripts also work on iphone and android apps?
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.