/// <summary> /// Unit Test function /// </summary> public void LoadSectionTest(int sectionNum = 0) { LoadedSection = false; // section # is always 1 less then the scene index. SectionNum = sectionNum; sectionLoader = new SectionLoader(transform.position, SectionNum, FindObjectOfType <ObjectPooler>()); // initialize an empty grid. sectionGrid = sectionLoader.InitGrid(); // init the section and its GameObjects. sectionLoader.InitSection(sectionGrid); StartCoroutine(sectionLoader.LoadSectionCo(sectionGrid, () => LoadedSection = true)); //sectionLoader.LoadSectionVoid(sectionGrid, () => LoadedSection = true); }
/// <summary> /// Attempts to load a section on scene change /// </summary> /// <param name="scene">The scene being loaded</param> /// <param name="mode">The mode the scene is being loaded</param> private void LoadSectionOnSceneLoad(Scene scene, LoadSceneMode mode) { LoadedSection = false; // if the scene is a test scene the section # = 0 otherwise it is always scene index - 1. SectionNum = scene.buildIndex == -1 ? 0 : scene.buildIndex - 1; sectionLoader = new SectionLoader(transform.position, SectionNum, FindObjectOfType <ObjectPooler>()); // initialize an empty grid. sectionGrid = sectionLoader.InitGrid(); // if the scene is not a section scene as per the scene to section rule if (scene.buildIndex == 0 || scene.buildIndex - 1 >= sectionLoader.WorldMaxX / SECTION_SIZE_X) { // if the scene does not need loading don't load. Debug.Log("no need to load this sections grid."); return; } // init the section and its GameObjects. sectionLoader.InitSection(sectionGrid); StartCoroutine(sectionLoader.LoadSectionCo(sectionGrid, () => LoadedSection = true)); }