public void RemoveOldestPiece() { LevelPiece oldestPiece = pieces[0]; pieces.Remove(oldestPiece); Destroy(oldestPiece.gameObject); }
private void Start() { if (fallbackLevelMaterial == null) { Debug.LogError("Fallback Level Material CAN NOT BE NULL!"); return; } foreach (Transform child in transform) { GameObject go = child.gameObject; ProBuilderMesh mainMesh = go.GetComponent <ProBuilderMesh>(); ArrayPacker[] faces = new ArrayPacker[mainMesh.faces.Count]; for (int i = 0; i < faces.Length; i++) { int[] faceVerts = new int[mainMesh.faces[i].indexes.Count]; mainMesh.faces[i].indexes.CopyTo(faceVerts, 0); faces[i] = new ArrayPacker(faceVerts); } Vector3[] vertices = new Vector3[mainMesh.positions.Count]; for (int i = 0; i < mainMesh.positions.Count; i++) { vertices[i] = mainMesh.positions[i]; } ArrayPacker[] sharedVertices = new ArrayPacker[mainMesh.sharedVertices.Count]; for (int i = 0; i < mainMesh.sharedVertices.Count; i++) { int[] sharedVertex = new int[mainMesh.sharedVertices[i].Count]; mainMesh.sharedVertices[i].CopyTo(sharedVertex, 0); sharedVertices[i] = new ArrayPacker(sharedVertex); } LevelPiece piece = new LevelPiece(go.transform.position, go.transform.rotation, vertices, faces, sharedVertices); Renderer renderer = go.GetComponent <Renderer>(); MaterialMapping mapping = MaterialMapping.GetMaterialMappingFromMaterial(levelMaterials, renderer.sharedMaterial); if (mapping != null) { piece.materialName = mapping.materialName; } else { piece.materialName = Constants.ERROR_NO_MATERIAL; } levelPieces.Add(piece); } // Was for testing to see duplicated data if (isTesting) { StartCoroutine(spawnBack()); } }
public void AddPiece() { LevelPiece piece = new LevelPiece(); piece = (LevelPiece)Instantiate(levelPrefabs[pieceCount]); piece.transform.SetParent(this.transform, false); Vector3 spawnPosition = Vector3.zero; Vector3 offset = new Vector3(0, 0, 12); if (pieces.Count == 0) { spawnPosition = levelStartPoint.position; } else { spawnPosition = pieces[pieces.Count - 1].exitPoint.position + offset; } piece.transform.position = spawnPosition; pieces.Add(piece); pieceCount++; if (pieceCount >= 4) { pieceCount = 0; } }
public void AddPiece() { //pick the random number int randomIndex = Random.Range(0, levelPrefabs.Count); //Instantiate copy of random level prefab and store it in piece variable LevelPiece piece = (LevelPiece)Instantiate(levelPrefabs[randomIndex]); piece.transform.SetParent(this.transform, false); Vector3 spawnPosition = Vector3.zero; //position if (pieces.Count == 0) { //first piece spawnPosition = levelStartPoint.position; } else { //take exit point from last piece as a spawn point to new piece spawnPosition = pieces[pieces.Count - 1].exitPoint.position; } piece.transform.position = spawnPosition; pieces.Add(piece); }
public void AddNew() { LevelPiece newPiece = new LevelPiece("Piece" + (pieces.Count + 1)); pieces.Add(newPiece); UpdateView(); }
private void spawnPrefab(LevelPiece type, int x, int y) { GameObject prefab = getPrefab(type); if (prefab == null) { return; } GameObject piece = (GameObject) Instantiate( prefab, LevelPositioner.PositionPiece(x, y), Quaternion.identity ); setParent(piece); if (type == LevelPiece.Ground) { LevelController.Instance.GroundHeight = piece.transform.position.y; } else if (type == LevelPiece.Collectible) { Debug.Log("Setting this phrase to something"); Phrase phraseController = piece.GetComponent<Phrase>(); phraseController.Initialize(); int index = phraseController.GetIndex(); phraseController.SetPhrase(PhraseController.Instance.GetPhrase(index)); } }
private void UpdateCurrentPieceInstance(PaletteItem item, Texture2D preview) { _itemSelected = item; _itemPreview = preview; _pieceSelected = (LevelPiece)item.GetComponent <LevelPiece>(); Repaint(); }
public void AddPiece() { //pick the random number int randomIndex = Random.Range(0, levelPrefabs.Count); //Instantiate copy of random level prefab and store it in piece variable LevelPiece piece = (LevelPiece)Instantiate(levelPrefabs[randomIndex]); piece.transform.SetParent(this.transform, false); Vector3 spawnPosition = Vector3.zero; /* * //Generate Coins * //get all collectables in piece and put into an array * Collectable[] c = piece.GetComponentsInChildren<Collectable>(); * * //Hides all coins * foreach (var cx in c) { * cx.Hide(); * } * //shows some coins. Freq controls frequency of coins. * foreach (var cx in c) { * float freq = 0.65f; * bool boolean = (Random.value > freq); * if(boolean) * cx.Show(); * }*/ if (pieces.Count == 0) { //first piece spawnPosition = levelStartPoint.position; } else { //take exit point from last piece as a spawn point to new piece spawnPosition = pieces[pieces.Count - 1].exitPoint.position; } piece.transform.position = spawnPosition; /* * int coins = GameManager.instance.collectedCoins; * * if (coins >= 10) { * Debug.Log ("LEVEL OFFICIALLY OVER."); * //Call UI here * * PlayerController.instance.animator.SetBool("isAlive", false); * * //If a killtrigger exists, turn it off. * if(piece.GetComponentInChildren<KillTrigger>()) * piece.GetComponentInChildren<KillTrigger>().turnOffTrigger(); * * GameManager.instance.newLevel(); * Time.timeScale = 0.0f; * } */ pieces.Add(piece); }
public void AddPiece() { // Picks a random number for the level piece prefab array int randomIndex = Random.Range(0, levelPrefabs.Count); // Instantiate a random copy of a level prefab and stores it in piece variable LevelPiece piece = (LevelPiece)Instantiate(levelPrefabs[randomIndex]); piece.transform.SetParent(this.transform, false); Vector3 spawnPosition = Vector3.zero; if (pieces.Count == 0) { spawnPosition = levelStartPoint.position; } else { // Takes exit point from last piece as a spawn point for the new piece spawnPosition = pieces[pieces.Count - 1].exitPoint.position; } piece.transform.position = spawnPosition; pieces.Add(piece); }
private void ResizeLevel() { LevelPiece[] newPieces = new LevelPiece[_newTotalColumns * _newTotalRows]; for (int col = 0; col < _level.TotalColumns; ++col) { for (int row = 0; row < _level.TotalRows; ++row) { if (col < _newTotalColumns && row < _newTotalRows) { newPieces[col + row * _newTotalColumns] = _level.Pieces[col + row * _level.TotalColumns]; } else { LevelPiece piece = _level.Pieces[col + row * _level.TotalColumns]; if (piece != null) { DestroyImmediate(piece.gameObject); } } } } _level.Pieces = newPieces; _level.TotalColumns = _newTotalColumns; _level.TotalRows = _newTotalRows; }
//allows prefab moving in level designer. //only works in edit mode public void Move() { Vector3 gridPoint = targetLevel.WorldToGridCoordinates(paletteItemInspected.transform.position); int col = (int)gridPoint.x; int row = (int)gridPoint.y; //at same positon do nothing if (col == originalPosX && row == originalPosY) { return; } //continue; int index = renderedLevelGrid[col][row]; LevelPiece validPiece = index > -1 ? prefabList [index] : null; //if in point or a valid prefab. if (!targetLevel.IsInsideGridBounds(col, row) || validPiece != null) { //return to original location paletteItemInspected.transform.position = targetLevel.GridToWorldCoordinates(originalPosX, originalPosY); } else { //move the prefab paletteItemInspected.transform.position = targetLevel.GridToWorldCoordinates(originalPosX, originalPosY); //update the jaggedArray renderedLevelGrid [originalPosX] [originalPosY] = -1; renderedLevelGrid [col] [row] = index; paletteItemInspected.transform.position = targetLevel.GridToWorldCoordinates(col, row); } }
public void AddPiece() { // 난수를 선택한다. int randomIndex = Random.Range(0, levelPrefabs.Count); // levelPrefabs에서 임의의 레벨 조각의 복사본을 인스턴스화해서 // piece 변수에 저장한다 LevelPiece piece = (LevelPiece)Instantiate(levelPrefabs [randomIndex]); piece.transform.SetParent(this.transform, false); Vector3 spawnPosition = Vector3.zero; if (pieces.Count == 0) { spawnPosition = levelStartPoint.position; } else { spawnPosition = pieces[pieces.Count - 1].exitPoint.position; } piece.transform.position = spawnPosition; pieces.Add(piece); }
public void AddPiece() { int randomIndex = Random.Range(0, levelPrefabs.Count); Debug.Log("randomIndex:" + randomIndex); Debug.Log("levelPrefabs:" + levelPrefabs.Count); float myRandom = Random.value; // Debug.Log(myRandom); // if(myRandom > holeProbability) // { // return; // } // Instantiate -> making a copy od an object LevelPiece piece = (LevelPiece)Instantiate(levelPrefabs[randomIndex]); piece.transform.SetParent(this.transform, false); Vector3 spawnPosition = Vector3.zero; if (pieces.Count == 0) { spawnPosition = levelStartPoint.position; } else { spawnPosition = pieces[pieces.Count - 1].exitPoint.position; } piece.transform.position = spawnPosition; pieces.Add(piece); }
private void ResizeLevel() { LevelPiece[] newPieces = new LevelPiece[_newTotalColumns * _newTotalRows]; for (int col = 0; col < _myTarget.TotalColumns; ++col) { for (int row = 0; row < _myTarget.TotalRows; ++row) { if (col < _newTotalColumns && row < _newTotalRows) { newPieces[col + row * _newTotalColumns] = _myTarget.Pieces[col + row * _myTarget.TotalColumns]; } else { LevelPiece piece = _myTarget.Pieces[col + row * _myTarget.TotalColumns]; if (piece != null) { // we must to use DestroyImmediate in a Editor context Object.DestroyImmediate(piece.gameObject); } } } } _myTarget.Pieces = newPieces; _myTarget.TotalColumns = _newTotalColumns; _myTarget.TotalRows = _newTotalRows; }
public static void SpawnLevelPiece(int toClient, LevelPiece levelPiece) { using (Packet packet = new Packet((int)ServerPackets.levelPieceSpawned)) { packet.Write(levelPiece.position); packet.Write(levelPiece.rotation); // Write the amount of vectors, then the vertices packet.Write(levelPiece.vertices.Length); foreach (Vector3 vector in levelPiece.vertices) { packet.Write(vector); } packet.Write(levelPiece.faces.Length); foreach (ArrayPacker packer in levelPiece.faces) { packet.Write(packer); } packet.Write(levelPiece.sharedVertices.Length); foreach (ArrayPacker packer in levelPiece.sharedVertices) { packet.Write(packer); } packet.Write(levelPiece.materialName); SendTCPData(toClient, packet); } }
private void LevelPieceOnHidden(LevelPiece levelPiece) { if (this.levelPiece == levelPiece) { //TODO: Return it to pool instead of destruction Destroy(gameObject); } }
public override bool Equals(DesignElement other) { LevelPiece otherLP = (LevelPiece)other; return( //position == otherLP.position rotation == otherLP.rotation && type == otherLP.type); }
private void LevelPieceOnHidden(LevelPiece levelPiece) { if (this.levelPiece != levelPiece) { return; } bonusesController.ReturnToPool(this); }
// Check if LevelPiece // is already used. private bool isActivePiece(LevelPiece Piece) { for (int i = 0; i < ActiveLevelPieces.Length; i++) { if (Piece == ActiveLevelPieces[ i ]) { return true; } } return false; }
private LevelPiece FindOtherLevelPiece(LevelPiece CurrentLevelPiece) { for (int i = 0; i < ActiveLevelPieces.Length; i++) { if (ActiveLevelPieces[ i ] != CurrentLevelPiece) { return ActiveLevelPieces[ i ]; } } return null; }
private bool IsActivePiece(LevelPiece piece) { for (int i = 0; i < activeLevelPieces.Length; i++) { if (piece == activeLevelPieces [i]) { return(true); } } return(false); }
// get the other LevelPiece from the levelPieces array private LevelPiece FindOtherLevelPiece(LevelPiece currentLevelPiece) { for (int i = 0; i < activeLevelPieces.Length; i++) { if (activeLevelPieces [i] != currentLevelPiece) { return(activeLevelPieces [i]); } } return(null); }
public void PlaceAnoterPiece(string name, bool forward) { bool continuePlacement = !false; int temp = 0; if (pieces.Count > 1) { if (pieces.ContainsKey(name)) { pieces[name].Conected(forward); while (continuePlacement) { temp = Random.Range(0, pieces.Count); upcoming = pieces[pieces.Keys.ElementAt(temp)]; if (upcoming != pieces[name]) { continuePlacement = !true; } else { continuePlacement = !false; } } if (forward) { pieces[name].Conected(forward); upcoming.Conected(!forward); upcoming.PlacePiece(pieces[name].outPoint.position, forward); } else { pieces[name].Conected(!forward); upcoming.Conected(forward); upcoming.PlacePiece(pieces[name].inPoint.position, forward); } } else { Debug.LogWarning("Attempting to place a unregistered level piece"); } } else { Debug.LogWarning("Not enough level pieces!!!"); } }
//array to store all prefabs in the level. public LevelPiece setLevelPiece(int col = -1, int row = -1, LevelPiece value = null) { //do not process if (col == -1 || row == -1 || value == null) { return(null); } levelPieces.Add(value); //store index int index = levelPieces.IndexOf(value); LevelPieceGridPositions [col] [row] = index; return(levelPieces[index]); }
private void LevelPieceOnEntered(LevelPiece levelPiece) { var moveBackValue = player.transform.position.x; if (moveBackValue < _maxX) { return; } gameplayController.level.MovePiecesBack(moveBackValue); player.CheckDistance(); player.transform.position -= new Vector3(moveBackValue, 0, 0); player.ResetAfterRollback(); }
public static LevelPiece[,] ParseLevel(string [][] levelAsStrings) { int height = Util.MatrixHeight(levelAsStrings); LevelPiece [,] level = new LevelPiece[levelAsStrings.Length,height]; for (int x = 0; x < levelAsStrings.Length; x++) { for (int y = 0; y < height; y++) { level[x,y] = ParsePiece(levelAsStrings[x][y]); } } return level; }
// get random LevelPiece from levelPieces array private LevelPiece GetRandomLevelPiece() { LevelPiece returnPiece = null; while (returnPiece == null) { int randomIndex = Mathf.RoundToInt(Random.Range(0, levelPieces.Length)); if (!IsActivePiece(levelPieces[randomIndex])) { returnPiece = levelPieces [randomIndex]; Debug.Log("Level Piece " + randomIndex); } } return(returnPiece); }
public void ReloadLevelPiecesList() { levelPiecesDict = new Dictionary <string, GameObject>(); string[] assetsPaths = AssetDatabase.FindAssets("t:GameObject"); for (int assetIdx = 0; assetIdx < assetsPaths.Length; ++assetIdx) { GameObject newObject = AssetDatabase.LoadAssetAtPath <GameObject>(AssetDatabase.GUIDToAssetPath(assetsPaths[assetIdx])); LevelPiece levelPiece = newObject.GetComponentInChildren <LevelPiece>(); if (levelPiece != null) { levelPiecesList.Add(newObject); levelPiecesDict.Add(levelPiece.GetPieceName(), newObject); } } }
private GameObject getPrefab(LevelPiece type) { switch (type) { case LevelPiece.Collectible: return CollectiblePrefab; case LevelPiece.Player: return PlayerPrefab; case LevelPiece.Finish: return FinishPrefab; case LevelPiece.Ground: return GroundPrefab; case LevelPiece.Platform: return PlatformPrefab; default: return null; } }
private void LevelPieceOnPlaced(LevelPiece levelPiece) { if (!levelPiece.bonusPoint.IsAssigned()) { return; } var chance = Random.Range(0f, 1f); if (chance > settings.bonusChance) { return; } var bonusPickable = GetPickableFromPool(bonusesDBEntries.RandomItem()); bonusPickable.AttackToLevelPiece(levelPiece); }
///<summary> ///For the given column erase the rows ///</summary> public void unsetRowsForColumn(int colIndex = -1) { //TODO removeAt from list, and remove from LevelPieceGridPositions if (colIndex != -1) { for (int r = 0; r < TotalRows; r++) { int index = LevelPieceGridPositions [colIndex] [r]; LevelPiece piece = levelPieces[index]; if (piece) { UnityEngine.Object.DestroyImmediate(piece.gameObject); levelPieces[index] = null; LevelPieceGridPositions [colIndex] [r] = -1; } } } }
void MutateLevelPiece(LevelPiece levelPiece, int i) { // Select random room type int roomType = Random.Range(0, 16); // Keep changing piece until it's different while ((LevelPiece.Type)roomType == levelPiece.type) { roomType = Random.Range(0, 16); } // No traps allowed on start and end of level if (i == 0 || i == genomeLength - 1) { roomType = Random.Range(0, 8); } levelPiece.type = (LevelPiece.Type)roomType; }
public void Load(LevelPiece level) { FillGrid(COLS, ROWS); data = level; List <LevelPiece.Item> items = level.GetItems(); int size = items.Count; LevelPiece.Item item; Button cell; for (int i = 0; i < size; i++) { item = items[i]; cell = grid.GetChild(item.x + item.y * COLS).GetComponent <Button>(); AddItemToCell(cell.transform, item.type, item.rotation); } currentCell = grid.GetChild(0); }
// Update is called once per frame void Update() { // loops through both active level pieces to move them together for (int i = 0; i < activeLevelPieces.Length; i++) { // adjust piece x location according to the move rate // get piece current location Vector3 newLocation = activeLevelPieces [i].transform.position; // update location based on time elapsed since last frame newLocation.x -= levelPiecesMoveRate * Time.deltaTime; // move to updated location activeLevelPieces [i].transform.position = newLocation; // if it has passed the bounds of the LevelPieceManager if (activeLevelPieces [i].endLocation.transform.position.x < transform.position.x) { if (isGameRunning) { // and it's the beginning piece if (activeLevelPieces [i] == startingLevelPiece) { // remove it from our reusable pieces activeLevelPieces [i].gameObject.SetActive(false); } // reset used piece location to initial spawn location activeLevelPieces [i].transform.position = activeLevelPieces [i].GetInitialLocation(); // get a new level piece that is not currently in use activeLevelPieces [i] = GetRandomLevelPiece(); // set its location to the end location of the other active piece activeLevelPieces [i].transform.position = FindOtherLevelPiece(activeLevelPieces [i]).endLocation.position; activeLevelPieces [i].ResetAllChildrenCoins(); } else { // if game is paused, recycle the two level pieces over and over LevelPiece nextLevelPiece = (i == 0) ? activeLevelPieces [1] : activeLevelPieces [0]; activeLevelPieces [i].transform.position = nextLevelPiece.endLocation.position; } } } }
public void Edit(int col, int row) { // we were general to get to this function, but don't want to handle drag when editing. if (targetLevel.IsInsideGridBounds(col, row)) { //in bounds.. int cacheIndex = renderedLevelGrid [col] [row]; LevelPiece validPiece = cacheIndex > -1 ? prefabList [cacheIndex] : null; if (validPiece != null) { paletteItemInspected = prefabList [cacheIndex].GetComponent <PaletteItem> () as PaletteItem; } } else { paletteItemInspected = null; } Repaint(); }
private void LoadPossibleLevelPieces() { GameObject[] p; // p = Resources.LoadAll<LevelPiece>("Prefabs/LevelPieces/"); //allPossibleLevelPieces = p.ToList<LevelPiece>(); levelPiecesParent.SetActive(true); p = GameObject.FindGameObjectsWithTag("LevelPiece"); foreach(GameObject piece in p) { allPossibleLevelPieces.Add(piece.GetComponent<LevelPiece>()); piece.gameObject.SetActive(false); } //startingPiece = Resources.Load<LevelPiece>("Prefabs/StartPiece"); startingPiece = GameObject.FindGameObjectWithTag("StartPiece").GetComponent<LevelPiece>(); startingPiece.gameObject.SetActive(false); tutorialPiece = GameObject.FindGameObjectWithTag("TutorialPiece").GetComponent<LevelPiece>(); tutorialPiece.gameObject.SetActive(false); }
// Sets an individual piece public void SetLevelPiece(int x, int y, LevelPiece type) { this.levelPieces[x,y] = type; }
private void ResizeLevel() { LevelPiece[] newPieces = new LevelPiece[_newTotalColumns * _newTotalRows]; for (int column = 0; column < _myTarget.TotalColumns; ++column) { for (int row = 0; row < _myTarget.TotalRows; ++row) { if (column < _newTotalColumns && row < _newTotalRows) { newPieces[column + row*_newTotalColumns] = _myTarget.Pieces[column + row*_myTarget.TotalColumns]; } else { LevelPiece piece = _myTarget.Pieces[column + row*_myTarget.TotalColumns]; if (piece != null) { DestroyImmediate(piece.gameObject); } } } } _myTarget.Pieces = newPieces; _myTarget.TotalColumns = _newTotalColumns; _myTarget.TotalRows = _newTotalRows; }
private void UpdateCurrentPieceInstance(PaletteWindow.PaletteItemSelection itemSelectionEvent) { _itemSelected = itemSelectionEvent.Item; _itemPreview = itemSelectionEvent.Preview; _pieceSelected = (LevelPiece) _itemSelected.GetComponent<LevelPiece>(); Repaint(); }
// Creates level from the pieces public Level(LevelPiece[,] levelPieces) { this.levelPieces = levelPieces; }