0

Scripting: change from a file-based model to a class-based model

Currently in order to add a script to a scene object, the process is as follows:

  1. Upload a single .cs file or download one from the store into inventory
  2. Drag .cs file from inventory to a scene object to attach it
  3. Repeat for each object, even if you're re-using the same script for multiple objects.

This has some drawbacks:

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.

 

7 comments

Please sign in to leave a comment.