Hi all
I have a class that manages my UI, which is attached to the hierarchy and inherits from MonoBehaviour. I’m finding the class is starting to get rather large so I wanted to split out some of the functionality into several smaller classes. However, my helper classes do not inherit from MonoBehaviour (I want to create them using the ‘new’ keyword and I don’t want to attach them too the scene), but some of the code calls things like “Instantiate” or “Destroy”.
Is there a way I can pass an instance of MonoBehaviour to the helper classes? If I pass ‘this’ through in the method and call “Instantiate” it gives me some access errors saying it can’t access a static method in a non-static context. The only way I could figure out was to make the UI manager class contain wrapper functions that can be called from ‘this’ in the helper classes (So I have a method called “InstatiateWrapper” that calls Instantiate), but obviously that’s creates some really weird dependencies (Class-A creates new instance of Class-B, Class-B calls method in Class-A which is a wrapper for static method in Class-Z).
Or I make all my helper classes inherit from MonoBehaviour too, but then I have to drag a whole boat load of classes onto the hierarchy (which makes refactoring and execution order difficult)
Any advice on how to handle this?