0

I creating the game using Unity engine and want powerful plugin system.

  1. Plugin authors can add new assets to the game using Unity Asset Bundle
  2. Plugin authors can add new code to the game, using C# runtime, or I even can use such addons from Asset Store like ModTool or UMod
  3. Plugin authors event can use and extends code from my game if I compile it to separate .dll file

But...

How can plugin authors reuse resources from my game (like specific shaders, materials, textures or prefabs) without duplicating them?

Imagine, that author wants to create specific scene and use a lot of existing objects in my library, or just add some unique shaders to their items. The only way, that I see now is import to plugin full game as Asset Bundle, remove all redundant parts and export as plugin Asset Bundle, but in that case all that items will be duplicated, batching will be broken and size of plugins will be inflated.

The main problem with this part, that a lot of features (everything, except Core: e.g. units, buildings, etc) I wanna see as separate plugins, which reuse some Core code and Core resources.

Shock
  • 501
  • 2
  • 9

1 Answers1

1

First off i'd like to point out one thing, which you might know. But just to make sure.

scripts in an assetbundle will be a textAsset, and as such not executed as a script If you want your assetbundle to have executable code it needs to be pre-compiled into an assembly first and then loaded using mono reflection. Do keep in mind that this makes your application vulnerable to malicious code aswel. And due to this loading scripts from asset bundles is not supported on Windows Store Apps and Windows Phone at all, and reflection is not available on IOS, limiting the platforms you could target.

Reusing resources that is already in the base game is not an issue as long as there is already a public reference to said resource in the scene that you can access from your assetbundles code. You could leverage this by having some sort of "master" component that holds a reference to all public resources.

Another option would be to have all resources you want plugins to have acces to be in the StreamingAssets folder Do take note that Assets in the StreamingAssets folder will be available to everyone though, and can thus be edited by everyone aswel.

Unity documentation:

Compiling:

Remy
  • 4,843
  • 5
  • 30
  • 60
  • Yep, I've heard about that, but thank you! _ Streaming Assets is not real reuse, doesn't it? E.G. materials and textures should be created for each plugin, so batching will not work and memory will be used a lot. _ Explain about public reference, please. For example, plugin author wanna add car models from the core game to his parking building in the plugin. How can he do this? He has his Unity project with parking building opened and has compiled game, which has a lot of car models. He want to – Shock Aug 10 '18 at 16:13
  • I'll try to write this out with the example of parking building. Say you got a GameObject with a script called `AllCars` which holds an array of GameObjects filled with a prefab for every car: `public GameObject[] carPrefabs;` you can acces this array (because it is public) from your assetbundle's script to instantiate a new car, using the resources referenced in your AllCars script, which is in your base game. for example: `GameObject newCar = Instantiate(FindObjectOfType().carPrefabs[0], position, rotation);` would then instantiate a GO with the model of the first car in your array – Remy Aug 10 '18 at 17:00
  • Do you mean launch-time (during the game)? What about editor-time? Can plugin's author see this car objects in his editor on his bildings without launching game? – Shock Aug 10 '18 at 18:12
  • Yeah that would be during launch time. I was under the assumption that is what you were looking for, apologies if i misunderstood! I wouldn't know how to make it visible in editor i'm afraid. – Remy Aug 10 '18 at 20:28
  • That's okey. This is the best solution now. It's not ideal, but its solution. Thank you. If someone has another ideas - it would be great. – Shock Aug 10 '18 at 20:34