Since it has nothing to do with Unity, it was easy for me to successfully craft a procedurally generated universe.
What is NOT easy, and is giving me a lot of trouble, is understanding how UNITY wants me to do this. Anytime I try to do it “My Way” I usually contradict whatever framework/engine I am trying to use. My way, My thoughts, always get me in trouble. I need help understanding how Unity prefers developers to work.
I really want to use Unity to make my life easier, but my thoughts keep beckoning me to just make my own engine. However, I figured it is easier to learn Unity’s “Way” than it is to learn a ton of low level API like OpenGL +/- ES.
I have a string which is used to create a procedural galaxy or “SpaceExpanse” which is composed of a 10x10 grid of 256x256 squares or “SpaceAreas”, which are composed of a collection of stars/planets or SpaceSystems, which hold the individual stars/planets, and the planets holding PlanetAreas, and so forth, etc.
Something like this:
It is composed of the following primary classes:
SpaceExpanse
SpaceArea
[TypeOf]System
None of them are Monobehavior. They’re just plain C# scripts that would work 100% without Unity.
Now, one of the ‘best practices’ tips is to make everything a Prefab, and Unity loves Gameobjects.
This coincides well with the fact I have to render this, allow for interface usability, etc.
I am FINALLY getting a feel for Unity’s favoring of component-based design. I also am FINALLY beginning to understand component-based design (coming from OOP practices).
For now, it would be simplest and most efficient for me to have the following gameobjects and object parenting.
SpaceExpanse
---SpaceArea
------System
---SpaceArea
------System
---SpaceArea
------System
---SpaceArea
------System
This would allow me to take a component-based approach to the primary gameplay which revolves around the System.
Add a few scripts like: Pickable (Clickable Interface), TooltipGUI (OnMouseHover), give the gameobject its own Sprite (while rendering everything else in a different way), etc.
Question: How should I go about creating a prefab or components from my game data, from my non-monobehavior Classes?
Right now I just have an empty prefab of a gameobject named “SpaceExpanse”, and I assume I would create “SpaceArea” prefabs inside the ‘SpaceArea’ script, and then parent all of them to the ‘SpaceExpanse’ Prefab which instantiated in the Scene first.
Is that it? It is as simple as adjusting the position of SpaceAreas (transform.translate) to form the grid?
Should I create a new class, or just implement it inside of SpaceExpanse.cs, SpaceArea.cs, etc.
Even more, should I attach these scripts TO the game objects themselves? Right now there doesn’t seem to be a need for attaching them because once the objects are instantiated, they are never altered.
This is a bit confusing, because I am already working backwards. Having already created the galaxy without Unity, and now wanting to switch to a Unity-style approach. (Other approaches give me too many problems, like inaccurate translation of world coordinates, iffy translation points, and more annoying problems. I want to give Prefab/GameObject Component-Based design a try.)