Currently in order to add a script to a scene object, the process is as follows:
- Upload a single .cs file or download one from the store into inventory
- Drag .cs file from inventory to a scene object to attach it
- Repeat for each object, even if you're re-using the same script for multiple objects.
This has some drawbacks:
- What if I want to sell a large script in the Sansar store, with a library of different behaviors. This is not possible. I have to separate each behavior into their own script.
- Sharing code between behavior scripts involves error prone copy/paste of large blobs of code into every script file, which I'm assuming ends up being duplicated in the experience.
- See https://help.sansar.com/hc/en-us/community/posts/115018674343-Suggestion-Multi-source-script-bundles-script-assemblies?input_string=Scripting%3A%20attach - The file-based script attachment model doesn't fit well when you're uploading assemblies or bundles of scripts, which is something I still would love to see happen.
From my past experience with Second Life scripting, it seems like this file-based model is somewhat of a holdover from that era, only instead of linden script files it's C# files. But this has some limitations, and causes some friction with more complicated scenes.
So how to improve? I think first of all, we need to switch from a file-based script attachment model to a class based model. Instead of dragging the script from your inventory to an object, you would instead add the script to the scene itself, as a kind of shared asset. Then, once the script file is an asset, you can attach a class (as long as it derives from one of the core script behavior base classes) from any script in the experience's assets to any object. One script file, multiple behaviors, multiple objects.
Than as a bonus, make it so all scripts in an experience's assets can automatically reference each other. And bingo, shared library of common functionality is now very simple. No reflection needed. No huge copy/pasted glob of code in every script file. Just add the common code library as script files in an experience's assets, and then just reference the common library code directly from any other script in the scene's assets.