I creating the game using Unity engine and want powerful plugin system.
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: eg units, buildings, etc) I wanna see as separate plugins, which reuse some Core code and Core resources.
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.