Let's say that I have three classes:
Task
- Derives MonoBehaviour.
- Holds variables and functions needed to perform a task.
- Variables may be dependent on scene/runtime data.
TaskContainer
- Derives MonoBehaviour.
- Holds a list of Task class instances.
Button
- Derives MonoBehaviour.
- Holds a TaskContainer class instance.
- When activated, runs all Task class instances within the TaskContainer class instance.
Current Procedure
Goal: Inject Button with a TaskContainer.
1.) Create multiple empty GameObjects and attach the Task script to each of them. Fill out fields through the inspector.
2.) Create an empty GameObject and attach the TaskContainer script.
3.) Fill out the TaskContainer script's list of Tasks by dragging the multiple Task GameObjects created earlier.
4.) Create an empty GameObject and attach the Button script. Drag the TaskContainer GameObject into the button script.
Thoughts
I don't like how this current situation works because:
- It feels messy instantiating so many GameObjects for each task.
- I don't like the idea of data classes being MonoBehaviour because they don't need to be actively running.
Possible Short Solutions
Storing Task scripts and TaskContainer scripts on the same GameObject.
- Petty Complaint: If I have a long list of Task scripts, maybe the process of dragging it up and down within the same Inspector is more tedious than dragging from the GameHierarchy to the Inspector.
Keep the objects MonoBehaviour and disable it so that it functions as a "normal" class.
- Complaint: It's kinda disturbing to make a class script MonoBehaviour just so it can be attached on a GameObject and hold runtime/scene dependent information.