Answer the question
In order to leave comments, you need to log in
How to properly organize the process of loading a complex scene in unity3d?
Hello. There is a space game with a rather complex main scene (more precisely, with a constantly growing number of actions in the development process). At the moment, the loading process consists mainly of creating and initializing various GOs (star, planets, ships, asteroid fields, etc.). Now the LevelBuilder script is responsible for this, in which the Start method contains a footcloth for a hundred lines of code. As part of a big refactoring, I need to rework this, I'm trying to understand how such things are done in normal projects.
In fact, I need something like a pipeline in which I can add / change stages in isolation. In general, we need advice on how best to do this - maybe there is some generally accepted technique, maybe at events or something else.
To understand the scale of the disaster - here is the current LevelBuilder(you can not talk about obvious violations of naming rules, OOP principles, etc. - I'm working on this).
Answer the question
In order to leave comments, you need to log in
You can move planets, asteroids, etc. into separate controllers, like this:
public class AsteroidsController : MonoBehaviour
{
public GameObject asteroidFieldPrefab;
private GameObject[] asteroids;
public void SpawnAsteroids(GameObject star, AsteroidBelt[] asteroidBelts)
{
asteroids = new GameObject[asteroidBelts.Length];
for (int i = 0; i < asteroids.Length; i++)
{
AsteroidBelt ast = asteroidBelts[i];
asteroids[i] = (GameObject) Instantiate(asteroidFieldPrefab, new Vector3(0, 0, 0), Quaternion.identity);
//Поскольку система изначально имеет радиус 1, она начинает спавнить астероиды внутри звезды. Не надо так
asteroids[i].SetActive(false);
asteroids[i].name = ast.name;
asteroids[i].transform.localScale *= Units_class.MetersToUnityUnits(ast.radius);
//А теперь надо
asteroids[i].SetActive(true);
AsteroidFieldOrbiter_script orbScript = asteroids[i].GetComponent<AsteroidFieldOrbiter_script>();
orbScript.astdField = ast;
orbScript.star = star;
orbScript.SetStartPosit();
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question