public void spawnObjects(bool up = false) { meshF = gameObject.GetComponent(typeof(MeshFilter)) as MeshFilter; transToUse = gameObject.transform; spawnedObjsInfo = new List <ObjectInfo> (); spawnedGameObjects = new List <GameObject> (); if (doTrees) { os = new ObjSpawningHelper[regionArray.Length]; for (int i = 0; i < os.Length; i++) { os [i] = new ObjSpawningHelper(); os [i].updatePositions(meshF.mesh, colors, regionArray [i].specificColor); } //Debug.Log ("Lenght: " + colors.Length.ToString() + " " + colors [1].ToString ()); for (int e = 0; e < os.Length; e++) { Vector3[] possiblePos = os [e].getAvalPos(); for (int i = 0; i < possiblePos.Length; i++) { int random = UnityEngine.Random.Range(0, 100); for (int r = 0; r < regionArray [e].objectArray.Length; r++) { if (regionArray [e].objectArray [r].percent >= random) { Vector3 rotationVar = regionArray [e].objectArray [r].rotOffVar * UnityEngine.Random.Range(-1f, 1f); //Getting randomized rotation Quaternion rotation = Quaternion.LookRotation(transToUse.TransformPoint(possiblePos [i]) - planetT.transform.position); if (up) { rotation = Quaternion.Euler(-90, 0, 0); } GameObject spawnedInstance = os [e].spawnObject(regionArray [e].objectArray [r].obj, transToUse, i, (rotation.eulerAngles + regionArray [e].objectArray [r].rotOffset + rotationVar)); if (areChildren) { spawnedInstance.transform.parent = gameObject.transform; } spawnedInstance.transform.localScale = new Vector3(treeScale, treeScale, treeScale); spawnedInstance.SetActive(false); spawnedGameObjects.Add(spawnedInstance); //Populating the info for networking ObjectInfo objInfo = new ObjectInfo(); objInfo.objType = IDDictionary [regionArray [e].objectArray [r].obj]; objInfo.position = spawnedInstance.transform.position; objInfo.rotation = spawnedInstance.transform.rotation; spawnedObjsInfo.Add(objInfo); break; } } } } } }
public void Initialize(Color[] colorsLocal) { colors = colorsLocal; meshF = gameObject.GetComponent(typeof(MeshFilter)) as MeshFilter; transToUse = gameObject.transform; //making and updating AvailablePositions for the player, while transforming from local space to world space ObjSpawningHelper playerOS = new ObjSpawningHelper(); playerOS.updatePositions(meshF.sharedMesh, colors, spawnColor); Vector3[] spawnPositions = playerOS.getAvalPos(); Vector3[] spawnDirections = playerOS.getNormals(); //DebugConsole.Log ("numPositions:" + spawnPositions.Length.ToString ()); spawnPoints = new SpawningInfo[spawnPositions.Length]; for (int i = 0; i < spawnPoints.Length; i++) { spawnPoints [i].trans = transToUse; spawnPoints [i].position = spawnPositions [i]; spawnPoints [i].rotation = spawnDirections [i]; } }