Hello, I've been working on improving my Dissertation Project from University.
This game creates a bunch of rooms, so ive been implementing Coroutines to create the map over time, rather than just in methods executed from the Start method.
Problem is majority of the time, all the map is created; dandy.
However sometimes only a percentage of it is, and its different each time.
**Here is my output:**
Not Desktop Application
MapModeManager.start
About to run CoR - createBlankMap
Creating Blank Room: 0, 0
Creating Blank Room: 0, 1
...
Creating Blank Room: 8, 9
Finished creating Blank Rooms
About to run CoR - createMap
About to read from File :
/storage/emulated/0/Android/data/com.IFaBb.ModularZombieSurvival/files/SaveFiles/Blarg.txt
Not new File (skipping dims)
Loop Spawn Rooms; 9, 10
roomScript.roomConfig(DifferentRooms[0], ID:0, Rot:0, X:0, Z:0);
Finished Configuring Room: 0, 0
roomScript.roomConfig(DifferentRooms[0], ID:0, Rot:0, X:0, Z:1);
...
Finished Configuring Room: 6, 0
roomScript.roomConfig(DifferentRooms[0], ID:0, Rot:0, X:6, Z:1);
Finished Configuring Room: 6, 1
roomScript.roomConfig(DifferentRooms[0], ID:0, Rot:0, X:6, Z:2);
**End of Output**
So the problem here, is that all the Blank Root rooms are created, but the program stopped at Room 6,1 when giving each the appropriate room.
I either need advice on how to sort out the code concept below, which is to spawn all the roots, then the rooms, and then config them.
AND/OR
A way to do sequential CoR excutions, that each one is able to perform 2 for loops, and stop itself and then resume at the end of each, ie:
for(){
for(){
//do stuff
}
//jump out for now (yield) and resume next time CoR runs
}
**CODE (unimportant content removed)**
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class MapModeManager : MonoBehaviour {
//Variables
//==============================================================================================================
/*Use this for initialization
*/
void Start () {
MyDebug.log("MapModeManager.start");
StartCoroutine( coStart() );
}//Start
//==============================================================================================================
IEnumerator coStart(){
MyDebug.log("About to run CoR - createBlankMap");
yield return StartCoroutine( createBlankMap() );
MyDebug.log("About to run CoR - createMap");
yield return StartCoroutine( createMap() );
MyDebug.log("About to run CoR - activateNMs");
yield return StartCoroutine( activateNMs() );
if( !SaveMemory.isEditMode() ){
MyDebug.log("Activating AI Manager");
gameObject.transform.GetComponent().enabled = true;//enable AI script
gameObject.transform.GetComponent().activate();//run startup stuff
}else{
MyDebug.log("Not, Activating AI Manager");
}
yield return null;
}
//==============================================================================================================
IEnumerator createBlankMap(){
for(int x=0; x();
if( !SaveMemory.isNewFile() ){
string Temp = (sr.ReadLine()).ToString();
//Debug.Log("First Reading as String is :"+Temp);
roomID = int.Parse( Temp );
Temp = (sr.ReadLine()).ToString();
//Debug.Log("First Reading as String is :"+Temp);
roomRot= int.Parse( Temp );
MyDebug.log("roomScript.roomConfig(DifferentRooms["+roomID+"], ID:"+roomID+", Rot:"+roomRot+", X:"+x+", Z:"+z+");");
roomScript.roomConfig(DifferentRooms[roomID],roomID,roomRot, x, z);
}else{
MyDebug.log( "Creating Basic Room" );
roomScript.roomConfig(DifferentRooms[0],0,0, x, z);
}
}//for
yield return null;
//Debug.Log("Row :"+x);
}//for
}//using
MyDebug.log("CoR createMap, Finished");
finishedSpawning = true;
yield return null;
}//IE createMap
//==============================================================================================================
IEnumerator activateNMs(){
bool activateFinished = false;
for(int x=0; x().activateNM();
}
yield return null;
}//for
MyDebug.log("About to Spawn Player Model");
if( editMode ){
if( DesktopApplication ){
Instantiate( EditorPlayer, spawnPlayerPos.transform.position, Quaternion.identity);
}else
{
Instantiate( EditorPlayerMobile, spawnPlayerPos.transform.position, Quaternion.identity);
}
}else{
if( DesktopApplication ){
Instantiate( CombatPlayer, spawnPlayerPos.transform.position, Quaternion.identity);
}else
{
Instantiate( CombatPlayerMobile, spawnPlayerPos.transform.position, Quaternion.identity);
}
}//editMode
Destroy(tempCamera);
MyDebug.log("Have spawned Player");
yield return null;
}//activateNMs
//==============================================================================================================
// Update is called once per frame
void Update () {
}//Update
}//CLASS
**CODE Ends**
Any and all help is welcome, and I will answer any and all questions if there are any.
↧