Closed nrgill28 closed 4 years ago
You have correctly come to the conclusion that my organization is completely terrible, and I really do appreciate the efforts in trying to piece it into something that isn't quite as idiotic. The only problem with that is it nukes backwards compatibility. If these changes are pushed out, old levels stop working. Monobehaviour FileIDs are generated like this. If you break that mapping by changing a class name or namespace, loading an old scene produces missing components and everything breaks.
If I'd internalized that a bit better when I was puking out classes, maybe I would've spent a bit more time actually organizing things properly. Ah well. Breaking changes like this were the kind of things I was hoping to save for when Anton inevitably breaks the whole mod with the release of the second TNH map.
I'm a big fan of ComponentProxy. I'd planned something similar as I watched the Loader class bloat, it was just a matter of sitting down and porting everything. I'm perfectly happy to merge that in alongside your PointableButton proxy. ObjectReferences, too. That's a cool shortcut, I'm a fan. All that will help clean things up.
Yeah I was aware this would break existing maps, they just outright crash the game when loading with these changes. That could be something to look into, not letting the player load a map that isn't compatible just in case.
As for all the other changes, did you want me to open a different PR with just the ComponentProxy, PointableButton and ObjectReference classes in the meantime?
Yeah, I'll gladly merge those files, and then I'll get around to porting existing proxies hopefully soon.
Moved the other changes to another branch. This PR now has only the desired classes.
Overview:
AllMonoBehaviour
components related to proxying in-game components now reside inMappingComponents/
Editor scripts are in theEditor/
directoryScripts that execute in-game are in theRuntime/
directoryRenamed the 'Generic' level type to 'Sandbox' (Including the namespace for it's mapping components)ComponentProxy
class that makes it easier to create new component proxies.PointableButton
)ObjectReferences
)Component Proxy: This is a simple abstract class that enables the code to
GetComponentsInChildren()
and let the derived class resolve the proxy in it's own class. See the new button class for an example. Additionally, it has an virtualOnExport()
method that can be used for one time calculations right before the map is exported (Some proxied components have Editor functions that can be emulated here instead of at run-time)ObjectReferences: This class will find static fields with the
ObjectReference
attribute and searches the scene for a GameObject that matches the name filter and the component type. The search is the first thing that happens when a scene is loaded to make sure nothing gets deleted before a reference can be taken. For example:This is very useful when proxying components since we usually need to borrow values from existing game objects or components, so being able to automatically search for these references makes getting those values much easier.