// *LevelStart Instantation* private void LevelStart_init(int l) { // Read the json file into a local string string json = maps[l]; // Build json string into an object //levelActive = JsonUtility.FromJson<LevelStatic>(json); levelRandom = JsonUtility.FromJson <LevelRandom>(json); // Sets the main camera to the same size at the levelActive height CameraMain.orthographicSize = (float)levelRandom.height * 5 / 6; // Shifts the grid postion when a map had odd width. UIGrid.localPosition = new Vector3(-ScreenMain.GetComponent <RectTransform>().rect.width / 2, -ScreenMain.GetComponent <RectTransform>().rect.height / 2, 0); if (levelRandom.width % 2 == 1) { UIGrid.localPosition = new Vector3(-ScreenMain.GetComponent <RectTransform>().rect.width / 2 - 0.5f, -ScreenMain.GetComponent <RectTransform>().rect.height / 2 - 0.5f, 0); } childLevelStart.LevelGenerate(levelRandom); //childLevelStart.LevelLoad(levelActive); }
public uint PickRandomLevel() { uint levelReturn = 0; if (randomLevels.Count == 0) { randomLevels = new List <uint>() { 0, 1, 2, 3 }; } int idx = LevelRandom.Range(0, randomLevels.Count); levelReturn = randomLevels[idx]; randomLevels.RemoveAt(idx); return(levelReturn); }
void Start() { // Current level set default is 0 levelNumber_current = 0; maps = new String[4]; maps[0] = mapRandom1.text; maps[1] = mapRandom2.text; maps[2] = mapRandom3.text; maps[3] = mapRandom4.text; /*maps[0] = map1.text; * maps[1] = map2.text; * maps[2] = map3.text; * maps[3] = map4.text; * maps[4] = map5.text; * maps[5] = map6.text; * maps[6] = map7.text; * maps[7] = map8.text; * maps[8] = map9.text; * maps[9] = map10.text; * maps[10] = map11.text; * maps[11] = map12.text; * maps[12] = map13.text; * maps[13] = map14.text; * maps[14] = map15.text;*/ script = new string[2]; //mapDirectory.GetFiles(); // Main menu button listeners UIButtonMaintoStart.onClick.AddListener(delegate { LevelStart_init(levelNumber_current); gameState = GameState.Game; menuState = MenuState.Game; runState = RunState.Transition; dialogueState = DialogueState.Open; }); UIButtonMaintoSelect.onClick.AddListener(delegate { gameState = GameState.Menu;; menuState = MenuState.Select; runState = RunState.Transition; }); // Select level menu button listeners for (int i = 0; i < maps.Length; i++) { // Encapsulate the level number to break dependency int l = i; // Read the json file into a local string string json = maps[l]; // Build json string into an object levelRandom = JsonUtility.FromJson <LevelRandom>(json); // Prefab button added to the select menu panel GameObject goButton = Instantiate(UIButtonSelect, UIMenuSelectPanel); Button btn = goButton.GetComponent <Button>(); btn.GetComponentInChildren <Text>().text = levelRandom.name; btn.GetComponentInChildren <TextMeshProUGUI>().text = (l + 1).ToString(); btn.onClick.AddListener(delegate { levelNumber_current = l; LevelStart_init(l); gameState = GameState.Game; menuState = MenuState.Game; runState = RunState.Transition; }); } UIButtonLeveltoMain.onClick.AddListener(delegate { gameState = GameState.Menu; menuState = MenuState.Main; runState = RunState.Transition; }); // Popup menu button listeners //UIButtonPopuptoStart.onClick.AddListener(delegate { levelNumber_current += 1; LevelStart_init(levelNumber_current); }); UIButtonPopuptoStart.onClick.AddListener(delegate { LevelStart_init(levelNumber_current); gameState = GameState.Game; menuState = MenuState.Game; runState = RunState.Transition; }); UIButtonPopuptoMain.onClick.AddListener(delegate { gameState = GameState.Menu; menuState = MenuState.Main; runState = RunState.Transition; }); UIButtonPopuptoSelect.onClick.AddListener(delegate { gameState = GameState.Menu; menuState = MenuState.Select; runState = RunState.Transition; }); // Ingame menu UIButtonGametoMain.onClick.AddListener(delegate { gameState = GameState.Menu; menuState = MenuState.Main; runState = RunState.Transition; }); UIButtonDialoguePanel.onClick.AddListener(delegate { dialogueState = DialogueState.Next; }); // Set states gameState = GameState.Menu; runState = RunState.Transition; mouseState = 0; }