private bool ValidatePush(Vector3 v3Direction) { int index = MMUtils.MatrixIndexesToListIndex(v3CurrentPosition + v3Direction, gameController.GetCurrentLevel().MaxSize); return(MMUtils.IsPushableObject(gameController.scenarioObjects[index].GetComponent <ScenarioObject>().tTileType) && gameController.scenarioObjects[index].GetComponent <MovementObject>().bEnableMovement); }
public void GenerateLevelFromLevelData() { DeleteLevel(); iTileSize = lvlExit.MaxSize; BuildLevelTiles(lvlExit.MaxSize); string[] sLevelData = lvlExit.levelBuild.Split(MMConstants.LEVEL_SEPARATOR); int iColorObjectIdx = 0, iRotationIdx = 0, iObjMoveIdx = 0; for (int i = 0; i < sLevelData.Length; i++) { tiles[i].GetComponent <Tile>().ttTile = (MMEnums.TileType) int.Parse(sLevelData[i]); if (MMUtils.IsColorObject(tiles[i].GetComponent <Tile>().ttTile)) { tiles[i].GetComponent <Tile>().clrObject = lvlExit.objColor[iColorObjectIdx]; iColorObjectIdx++; } if (MMUtils.IsScenarioObject(tiles[i].GetComponent <Tile>().ttTile)) { tiles[i].transform.rotation = Quaternion.Euler(lvlExit.objRotation[iRotationIdx]); iRotationIdx++; } if (MMUtils.IsPushableObject(tiles[i].GetComponent <Tile>().ttTile)) { tiles[i].GetComponent <Tile>().bMovementOn = lvlExit.objMovementEnabled[iObjMoveIdx]; iObjMoveIdx++; } } RefreshTiles(); }
public void GetLevelData() { lvlExit.levelBuild = ""; Vector3[] v3ObjectsRotations = new Vector3[iNumberOfObjects]; Color[] clrObjects = new Color[iNumberOfColors]; bool[] bMovementObjects = new bool[iNumberOfMovementObjects]; int iObjIndex = 0, iClrIndex = 0, iObjMoveIndex = 0; for (int i = 0; i < tiles.Length; i++) { lvlExit.levelBuild += ((int)tiles[i].GetComponent <Tile>().ttTile).ToString() + MMConstants.LEVEL_SEPARATOR; if (MMUtils.IsScenarioObject(tiles[i].GetComponent <Tile>().ttTile)) { v3ObjectsRotations[iObjIndex] = tiles[i].transform.rotation.eulerAngles; iObjIndex++; } if (MMUtils.IsColorObject(tiles[i].GetComponent <Tile>().ttTile)) { clrObjects[iClrIndex] = tiles[i].GetComponent <Tile>().clrObject; iClrIndex++; } if (MMUtils.IsPushableObject(tiles[i].GetComponent <Tile>().ttTile)) { bMovementObjects[iObjMoveIndex] = tiles[i].GetComponent <Tile>().bMovementOn; iObjMoveIndex++; } } lvlExit.objColor = new Color[iNumberOfColors]; lvlExit.objColor = (Color[])clrObjects.Clone(); lvlExit.objRotation = new Vector3[iNumberOfObjects]; lvlExit.objRotation = (Vector3[])v3ObjectsRotations.Clone(); lvlExit.objMovementEnabled = new bool[iNumberOfMovementObjects]; lvlExit.objMovementEnabled = (bool[])bMovementObjects.Clone(); lvlExit.levelBuild = lvlExit.levelBuild.Substring(0, lvlExit.levelBuild.Length - 1); lvlExit.MaxSize = iTileSize; #if UNITY_EDITOR AssetDatabase.SaveAssets(); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); EditorUtility.SetDirty(lvlExit); #endif print("DATA GENERATED!"); }
public void GenerateBaseLevel(LevelData curLevel) { int iObjectPlacementNumber = 0; int iObjectMovementNumber = 0; int iObjectColorNumber = 0; string[] sLevelObjects = curLevel.levelBuild.Split(MMConstants.LEVEL_SEPARATOR); gameController.scenarioObjects = new GameObject[sLevelObjects.Length]; for (int x = 0; x < curLevel.MaxSize; x++) { for (int z = 0; z < curLevel.MaxSize; z++) { GameObject goNewTile = Instantiate(goTile, new Vector3(x, 0.4f, z), Quaternion.identity); goNewTile.transform.SetParent(this.transform); int index = MMUtils.MatrixIndexesToListIndex(x, z, curLevel.MaxSize); if ((MMEnums.TileType) int.Parse(sLevelObjects[index]) == MMEnums.TileType.NONE) { goNewTile.SetActive(false); } if (index == (curLevel.MaxSize * curLevel.MaxSize) / 2) { cameraManager.PlaceCamera(curLevel.MaxSize, goNewTile); } GameObject goToInstantiate = null; switch ((MMEnums.TileType) int.Parse(sLevelObjects[index])) { case MMEnums.TileType.MIRROR: goToInstantiate = goMirror; break; case MMEnums.TileType.LASER: goToInstantiate = goLaser; break; case MMEnums.TileType.RECEIVER: goToInstantiate = goReceiver; break; case MMEnums.TileType.SPLITTER: goToInstantiate = goSplitter; break; case MMEnums.TileType.ROCKS: goToInstantiate = goRocks; break; case MMEnums.TileType.CHARACTER: goToInstantiate = goCharacter; break; case MMEnums.TileType.MERGER: goToInstantiate = goMerger; break; case MMEnums.TileType.BIG_ROCK: goToInstantiate = goBigRock; break; case MMEnums.TileType.DUPLICATOR: goToInstantiate = goDuplicator; break; } if (goToInstantiate != null) { GameObject goNewObj = Instantiate(goToInstantiate, new Vector3(x, 1, z) + goToInstantiate.GetComponent <ScenarioObject>().v3Offset, Quaternion.identity); goNewObj.transform.SetParent(this.transform); goNewObj.GetComponent <ScenarioObject>().SetLevelReference(gameController); gameController.scenarioObjects[index] = goNewObj; if (goToInstantiate != goRocks && goToInstantiate != goBigRock) { goNewObj.transform.rotation = Quaternion.Euler(curLevel.objRotation[iObjectPlacementNumber]); goNewObj.name += iObjectPlacementNumber; iObjectPlacementNumber++; if (goToInstantiate == goLaser) { goNewObj.GetComponent <RayLaser>().UpdateRayColor(curLevel.objColor[iObjectColorNumber]); iObjectColorNumber++; } else if (goToInstantiate == goReceiver) { goNewObj.GetComponent <Receiver>().UpdateColorSolution(curLevel.objColor[iObjectColorNumber]); iObjectColorNumber++; } } if (MMUtils.IsPushableObject(goToInstantiate.GetComponent <ScenarioObject>().tTileType)) { goNewObj.GetComponent <MovementObject>().bEnableMovement = curLevel.objMovementEnabled[iObjectMovementNumber]; iObjectMovementNumber++; } } else if (!goNewTile.activeInHierarchy) { gameController.scenarioObjects[index] = goNewTile; } else { gameController.scenarioObjects[index] = goNewTile; } } } }
public void RefreshTiles() { for (int i = 0; i < tiles.Length; i++) { if (tiles[i].GetComponent <Tile>().HasChangedValue()) { MMUtils.DeleteAllChildrenWithException(tiles[i].transform, "Tile"); tiles[i].GetComponent <Tile>().SetNewTile(); if (tiles[i].GetComponent <Tile>().ttTile == MMEnums.TileType.NONE) { tiles[i].GetComponent <Tile>().goTile.SetActive(false); } else { tiles[i].GetComponent <Tile>().goTile.SetActive(true); GameObject goToInstantiate = null; switch (tiles[i].GetComponent <Tile>().ttTile) { case MMEnums.TileType.MIRROR: goToInstantiate = prefMirror; break; case MMEnums.TileType.LASER: goToInstantiate = prefLaser; break; case MMEnums.TileType.RECEIVER: goToInstantiate = prefReceiver; break; case MMEnums.TileType.SPLITTER: goToInstantiate = prefSplitter; break; case MMEnums.TileType.ROCKS: goToInstantiate = prefRocks; break; case MMEnums.TileType.CHARACTER: goToInstantiate = prefCharacter; break; case MMEnums.TileType.MERGER: goToInstantiate = prefMerger; break; case MMEnums.TileType.BIG_ROCK: goToInstantiate = prefBigRock; break; case MMEnums.TileType.DUPLICATOR: goToInstantiate = prefDuplicator; break; } if (goToInstantiate != null) { GameObject goNewObj = Instantiate(goToInstantiate, Vector3.zero, Quaternion.identity); //tiles[i].GetComponent<Tile>().bMovementOn = goToInstantiate.GetComponent<ScenarioObject>(). goNewObj.transform.SetParent(tiles[i].transform); goNewObj.transform.localPosition = new Vector3(0, 0.2f, 0) + goToInstantiate.GetComponent <ScenarioObject>().v3Offset; goNewObj.transform.localRotation = Quaternion.identity; if (tiles[i].GetComponent <Tile>().ttTile != MMEnums.TileType.ROCKS && tiles[i].GetComponent <Tile>().ttTile != MMEnums.TileType.BIG_ROCK) { iNumberOfObjects++; } if (MMUtils.IsPushableObject(tiles[i].GetComponent <Tile>().ttTile)) { iNumberOfMovementObjects++; } if (MMUtils.IsColorObject(tiles[i].GetComponent <Tile>().ttTile)) { if (tiles[i].GetComponent <Tile>().ttTile == MMEnums.TileType.LASER) { tiles[i].GetComponentInChildren <LineRenderer>().startColor = tiles[i].GetComponent <Tile>().clrObject; tiles[i].GetComponentInChildren <LineRenderer>().endColor = tiles[i].GetComponent <Tile>().clrObject; Renderer recRenderer = tiles[i].GetComponentInChildren <LineRenderer>().GetComponentsInChildren <Renderer>()[1]; recRenderer.material.SetColor("_Color", tiles[i].GetComponent <Tile>().clrObject); } else if (tiles[i].GetComponent <Tile>().ttTile == MMEnums.TileType.RECEIVER) { Renderer recRenderer = tiles[i].GetComponentInChildren <Receiver>().GetComponentsInChildren <Renderer>()[2]; recRenderer.materials[0].SetColor("_Color", tiles[i].GetComponent <Tile>().clrObject); } iNumberOfColors++; } } } } } }