I see in all demos that all classes inherits from MonoBehaviour but I don’t understand if (and why) this is mandatory.
Let’s say I need an entity class to represent a generic class, for example: “Table”. This class will never move, change or even displayed, but Table objects are attributes other objects.
Why should I need to inherit Table from MonoBehaviour?
As Piflik said, if you want the script to be addable to a gameobject, then it will need to derive from monobehaviour (or NetworkBehaviour). Model classes (i.e. classes specifically for holding data) don’t need to be Monobehaviour, but will need to have the [System.Serializable] attribute in order to appear in the inspector.
usually model classes are better off deriving from ScriptableObject which works nicely with the inspector when trying to drop said table into another class.
Also Unity can’t render abstract or generic classes so a
public class Table<T>:ScriptableObject where T:struct
won’t show up in the interface as you may expect, you’ll have to wrap those classes into ConcreteClasses
public abstract class Table<T>:ScriptableObject where T:struct
{
//stuff
}
public class IntTable:Table<int>{}
I wouldn’t say that MVC is directly adopted by the majority of users, however a large number do adhere to a number of its prinicpals, most just don’t call it MVC. in fact a lot of the Live tutorials (specifically the scriptable object ones) take the idea of MVC to heart. just again they just don’t call it MVC. Of all the Assets I’ve worked with StrangeIOC adheres to the MVC pattern the strongest. in fact it’s file hierarchy has folders for Models, Views, and Commands (i.e. Controllers). MVC can work beautifully in unity and its a great pattern for teaching separation of concerns.
if your just starting out I would recommend not working on building a solid code base. while good clean code is great, it takes a considerable amount of time and experience with the engine to come into fruition. the quality of your codebase should scale with the expectations of your audience. since you’re on your first project its more important to get a functioning prototype up and running than it is making easily manageable code.
I can speak from experience that you want to focus on fast, simple results for your first project. great code doesn’t happen overnight but usually over several months, even years and your project really can’t wait that long. if the game was something like Skyrim, then people would be much more patient with you making a solid code structure. however obscure projects can lose the audience’s interest fast.
Yep, I’m new to Unity but I’m a (web) developer from 16 years so I completely get what you mean and I’m agree. I was maybe curious about the most used approaches for development in Unity.