void runCalc() { if (Selection.activeObject.GetType() == typeof(Texture2D)) { Debug.Log("We are going to generate the level from the image: " + Selection.activeObject.name); Texture2D levelImage = Selection.GetFiltered(typeof(Texture2D), SelectionMode.TopLevel)[0] as Texture2D; //levelStorage newLevel = new levelStorage() //levelStorage myLevelStorage = Selection.GetFiltered(typeof(levelStorage), SelectionMode.TopLevel)[0] as levelStorage; levelStorage newLevel = ScriptableObject.CreateInstance <levelStorage>(); //newLevel.levelImage = levelImage; newLevel.initialize(4, 1, 6, levelImage); AssetDatabase.CreateAsset(newLevel, "Assets/generatedLevels/" + Selection.activeObject.name + ".asset"); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = newLevel; //myLevelStorage.myVectorField = new vectorField(myLevelStorage.levelImage.width,myLevelStorage.levelImage.height,myLevelStorage.overSampling,myLevelStorage.vecHeight,myLevelStorage.wallRadius); //vectorFHelper myHelper = new vectorFHelper(myLevelStorage.myVectorField, myLevelStorage.wallRadius, myLevelStorage.vecHeight, myLevelStorage.overSampling, myLevelStorage.levelImage.width * myLevelStorage.overSampling, myLevelStorage.levelImage.height * myLevelStorage.overSampling); /* * for (int x=0;x<myLevelStorage.levelImage.width;x++){ * for (int y = 0; y < myLevelStorage.levelImage.height; y++) { * //Debug.Log(tex.GetPixel(x, y)); * if (myLevelStorage.levelImage.GetPixel(x, y) == new Color(0, 0, 0)) { * myLevelStorage.myVectorField.addWIC(x, y, myHelper); * } * } * * * } * myHelper.start(); * Debug.Log(myLevelStorage.myVectorField.tiles.Length + "Length of the tiles"); * Debug.Log(myLevelStorage.myVectorField.wallMem.Count + "Count of the Walls"); * * * myHelper.halt(); * //myHelper.stop();/// we need to tell the thread to stop calulating */ } }
public void assignData(levelStorage loadedStorage_) { loadedStorage = loadedStorage_; myVectorField = loadedStorage.myVectorField; gates = loadedStorage.gates; myVectorField.loadValues(); int wallCount = myVectorField.wallMem.Count; int minimumX = 0; int minimumZ = 0; int maximumX = 0; int maximumZ = 0; int wallID = 0; int emergencyCounter = 0; Vector2Int[] wallMemory; Vector2Int[] toBeDeleted while (wallCount > 0) { emergencyCounter++; Debug.Log("This wallId should go nothing but up and jump in between" + wallID); if (wallID < myVectorField.wallMem.Count) { minimumX = Mathf.RoundToInt(myVectorField.wallMem[wallID].x); minimumZ = Mathf.RoundToInt(myVectorField.wallMem[wallID].y); maximumX = minimumX; maximumZ = minimumZ; } else { Debug.Log("Breaking since we are moving out of the bounds"); break; } int targetX = minimumX; bool firstRun = true; bool borderFound = false; while (myVectorField.wallMem.Contains(new Vector2(targetX, maximumZ))) { while (myVectorField.wallMem.Contains(new Vector2(targetX, maximumZ))) { //Debug.Log("TargetX" + targetX + "maximumZ" + maximumZ); targetX++; if (!firstRun && targetX >= maximumX) { borderFound = true; break; } } if (firstRun) { firstRun = false; maximumX = targetX - 1; targetX = minimumX; } else if (borderFound) { borderFound = false; targetX = minimumX; maximumZ++; } else { break; } } Debug.Log("Blub new wall..." + maximumX + " z: " + maximumZ); //maximumX--; maximumZ--; Debug.Log("Wall Id retrieved from the last wall" + myVectorField.wallMem.FindIndex(v => maximumX == v.x && maximumZ == v.y)); wallID = myVectorField.wallMem.IndexOf(new Vector2(maximumX, maximumZ)); wallID++; GameObject newWall = GameObject.CreatePrimitive(PrimitiveType.Cube) as GameObject; newWall.transform.localScale = new Vector3(maximumX - minimumX, 2, maximumZ - minimumZ) / myVectorField.overSampling; newWall.transform.position = myVectorField.aSTWS((minimumX + (maximumX / 2)), (minimumZ + (maximumZ / 2)), transform.GetChild(0).gameObject); if (emergencyCounter > myVectorField.wallMem.Count) { Debug.Log("Pulling the emergency break this should not happen"); break; } } }