private static void Register(GameObject obj) { if (PrefabUtility.GetPrefabAssetType(obj) != PrefabAssetType.NotAPrefab) { Debug.LogWarning(obj.name + " is a prefab asset.", obj); return; } // Whether obj is GameLevelObject or not GameLevelObject levelObject = obj.GetComponent <GameLevelObject>(); if (levelObject == null) { Debug.LogWarning(obj.name + "isn't a game level object", obj); } foreach (GameObject rootObject in obj.scene.GetRootGameObjects()) { GameLevel gameLevel = rootObject.GetComponent <GameLevel>(); if (gameLevel != null) { if (gameLevel.HasLevelObject(levelObject)) { Debug.LogWarning(obj.name + " is already registered", obj); return; } Undo.RecordObject(gameLevel, "Register Level Object."); gameLevel.RegisterLevelObject(levelObject); Debug.Log(obj.name + " registered to game level " + gameLevel.name + " in scene" + obj.scene.name + " . ", obj); return; } } }
public void RefreshMemory() { for (int i = 0; i < gameTiles.Length; i++) { if (!gameTiles[i]) //already destroyed { continue; } else { Destroy(gameTiles[i]); } } Bar.SetActive(false); currentLevel = null; gameTiles = null; bar = null; histoire = null; coin = 0; star = 3; AlreadyLost = false; AlreadyWon = false; AlreadyFirstMatch = false; CurrentLevel = 1; //world = 0; level = 0; //UI variables }
public void RegisterLevelObject(GameLevelObject obj) { // Only Invoke Register Object when not in play mode if (Application.isPlaying) { Debug.LogError("Do not invoke in play mode"); return; } if (HasLevelObject(obj)) { return; } if (levelObjects == null) { levelObjects = new GameLevelObject[] { obj } } ; else { System.Array.Resize(ref levelObjects, levelObjects.Length + 1); levelObjects[levelObjects.Length - 1] = obj; // Add Obj to the last position } }
public static GameLevelObject ReadGameLevelFromAsset(int level) { GameLevelObject result = new GameLevelObject(); result.level = level; //Load a text file (Assets/Resources/MapConfigs/1.txt) TextAsset textFile = Resources.Load <TextAsset>("MapConfigs/" + level); string line = textFile.text; result.pos = JsonUtility.FromJson <Level>(line); List <int> t = line.AllIndexesOf("t"); t.Add(line.Length - 1); for (int i = 0; i < t.Count - 1; i++) //one layer at a time { List <TilePosition> tiles = new List <TilePosition>(); List <int> comas = line.Substring(t[i], t[i + 1] - t[i]).AllIndexesOf("],["); if (comas.Count == 0) //layer only has 1 tile { int mono = line.Substring(t[i] + 4).IndexOf("]]"); AddToPositionTemp(line.Substring(t[i] + 4, mono + 1), result.pos.l[i].p, result.pos.p, tiles); result.tiles.Add(new TilePosition(tiles[0].x, tiles[0].y, tiles[0].z)); continue; } AddToPositionTemp(line.Substring(t[i] + 4, comas[0] - 3), result.pos.l[i].p, result.pos.p, tiles); for (int j = 0; j < comas.Count - 1; j++) { AddToPositionTemp(line.Substring(t[i] + comas[j] + 2, comas[j + 1] - comas[j] - 1), result.pos.l[i].p, result.pos.p, tiles); } int end = line.Substring(t[i], t[i + 1] - t[i]).IndexOf("]]"); AddToPositionTemp(line.Substring(t[i] + comas[comas.Count - 1] + 2, end - comas[comas.Count - 1] - 1), result.pos.l[i].p, result.pos.p, tiles); SortTile(tiles); for (int a = 0; a < tiles.Count; a++) { result.tiles.Add(new TilePosition(tiles[a].x, tiles[a].y, tiles[a].z + a)); } } // make sure the number of tiles can be divided by 3 int residual = result.tiles.Count % 3; for (int i = 0; i < residual; i++) { result.tiles.RemoveAt(0); } return(result); }
public bool HasLevelObject(GameLevelObject o) { if (levelObjects != null) { for (int i = 0; i < levelObjects.Length; i++) { if (levelObjects[i] == o) { return(true); } } } return(false); }
public bool HasLevelObject(GameLevelObject o) // Checks if an object is part of a level { if (levelObjects != null) { for (int i = 0; i < levelObjects.Length; i++) { if (levelObjects[i] == o) { return true; } } } return false; }
public bool HasLevelObject(GameLevelObject obj) { if (levelObjects != null) { for (int i = 0; i != levelObjects.Length; ++i) { if (levelObjects[i] == obj) { return(true); } } } return(false); }
public bool HasLevelObject(GameLevelObject o) { if (levelObjects != null) { foreach (var item in levelObjects) { if (item == o) { return(true); } } } return(false); }
static void Register(GameObject o) { //GameObject o = Selection.activeGameObject; //if (o == null) //{ // Debug.LogWarning("No level object selected."); // return; //} if (PrefabUtility.GetPrefabType(o) == PrefabType.Prefab) { Debug.LogWarning(o.name + " is a prefab asset.", o); return; } GameLevelObject levelObject = o.GetComponent <GameLevelObject>(); if (levelObject == null) { Debug.LogWarning(o.name + " isn't a game level object.", o); return; } foreach (GameObject rootObject in o.scene.GetRootGameObjects()) { GameLevel gameLevel = rootObject.GetComponent <GameLevel>(); if (gameLevel != null) { if (gameLevel.HasLevelObject(levelObject)) { Debug.LogWarning(o.name + " is already registered.", o); return; } Undo.RecordObject(gameLevel, "Redister Level Object."); gameLevel.RegisterLevelObject(levelObject); Debug.Log(o.name + " redistered to game level " + gameLevel.name + " in scene " + o.scene.name + ".", o); return; } } Debug.LogWarning(o.name + " isn't part of a game level.", o); }
public void RegisterLevelObject(GameLevelObject o) { if (Application.isPlaying) { Debug.LogError("Do not invoke in play mode!"); return; } if (HasLevelObject(o)) { return; } if (levelObjects == null) { levelObjects = new GameLevelObject[] { o }; } else { System.Array.Resize(ref levelObjects, levelObjects.Length + 1); levelObjects[levelObjects.Length - 1] = o; } }
public void StartNewGame(int Level) { if (Level <= 0 || Level >= totalLevel) { return; } Bar.SetActive(true); CurrentLevel = Level; currentLevel = Utility.ReadGameLevelFromAsset(Level); // level time and number of tiles GameEventSystem.current.SetTimeBar(300f, 60f, 150f, 240f); GameEventSystem.current.TimeControl(1); characters.Clear(); characters = all_characters.GetRange(0, SpriteInUse(Level)); // bar = new StackInBoard(); histoire = new List <Record>(); CreateBoard(); }