how can i put components in external dlls and store dlls in asset bundles

i want to store my components in assemblies that i define and then put them in asset bundles. in this way, new functionality can be added to games. complete patches are easily possible. so can i create a car mesh and a car.dll assembly and make an asset bundle of them and then download it from my game and use it with it's new scripts?

there is not any info about components in external assemblies nowhere. where should i put the dll? where should i put that for web players. where unity looks for external components. for example if i say

CarScript s = new CarScript();

this is not real code.

where unity looks for the component?

now it's possible to put components in dlls and use them. unity will recognize them in the editor. also i think from 3.2 we can add components from assemblies loaded in runtime as macfanpro answewred here. reflection is not needed anymore and you just need to use AddComponent with the type that is in the dll.

This is a quite complicated question, for a couple of reasons. First, Unity was not really intended for run-time modification of behaviors from external sources, and as such, you cannot really use, for instance, MonoBehavior from a outside DLL. However, there is a way around this, and that is to use your own behaviour class that exposes the same virtual functions as MonoBehavior and load those using C# reflection from a external DLL.

What you could do is make a class like this:

public abstract class ExtBehavior {
    public virtual void Initialize()
    public virtual void Update()

Then extend it like this

public class TstBehaviour : ExtBehavior {
    public override void Initialize()
    public override Update()

You will need to put the external DLL containing ExtBehavior into Library/Frameworks, under the Unity folder. This is so the compiler can resolve the type of ExtBehavior.

Then load the behaviors like this

Assembly assem = Assembly.LoadFrom("nameOfDLL.dll");
IEnumerable<Type> behaviors =assem.GetTypes()

Now, when you need a component, you just iterate through this array of Types until you find the one you need, construct it, cast it, then use it. I recommend creating a normal MonoBehavior that takes the name of the component that is loaded, as well as a Dictionary that takes parameters, then loads this dictionary into the external behavior through a protected constructor in ExtBehavior.

I won't say you can't store it but I think the problem is that how do you get the unadulterated DLL bits out of the bundle? We tried this with other binary formats and the rather ugly workaround was to Zip compress then Base64 encode the bits as a text asset. Bad, bad, bad... but it was right before the release. It blew the game size up like a balloon. If you could figure out a way to say "Get this blob as raw bits" you could load the DLL internally and use it with some C# trickery.

If you figure out how to do this with a DLL I would love to know... I'll update the community page.

Hey there people,
I have actually created an external DLL, and have it working with MonoDevelop,
and Unity3D. Check out my video at Unity3D, MonoDevelop, C#, and created a DLL - YouTube
I will be creating a tutorial video on how to do this soon.