// Use this for initialization void Awake() { GameObject go = GameObject.Find("LevelSelector"); GameObject levelDLObj = GameObject.Find("LevelDownloader"); DownloadLevels levelDownloader = null; if (levelDLObj != null) { levelDownloader = levelDLObj.GetComponent <DownloadLevels>(); } if (go != null) { levelSelection = GameObject.Find("LevelSelector").GetComponent <LevelIdentity>(); prefab = levelDownloader.Levels[levelSelection.GetIndex()]; } else { GameObject selector = new GameObject("LevelSelector"); selector.AddComponent <LevelIdentity>(); levelSelection = selector.GetComponent <LevelIdentity>(); levelSelection.SetID(0); DontDestroyOnLoad(selector); if (levelDLObj != null) { prefab = levelDownloader.Levels[levelSelection.GetIndex()]; } } levelGameObject = Instantiate(prefab); ConfigHandler.LoadConfig(); ConfigHandler.Config.SetField("Progress", levelSelection.GetIndex()); ConfigHandler.SaveConfig(); ObjectiveHandler.OnObjectiveActivated += ObjectiveActivated; ObjectiveHandler.OnObjectiveDeactivated += ObjectiveDeactivated; }
// Use this for initialization void Awake() { GameObject go = GameObject.Find("LevelSelector"); GameObject levelDLObj = GameObject.Find("LevelDownloader"); DownloadLevels levelDownloader = null; if (levelDLObj != null) { levelDownloader = levelDLObj.GetComponent<DownloadLevels>(); } if (go != null) { levelSelection = GameObject.Find("LevelSelector").GetComponent<LevelIdentity>(); prefab = levelDownloader.Levels[levelSelection.GetIndex()]; } else { GameObject selector = new GameObject("LevelSelector"); selector.AddComponent<LevelIdentity>(); levelSelection = selector.GetComponent<LevelIdentity>(); levelSelection.SetID(0); DontDestroyOnLoad(selector); if (levelDLObj != null) { prefab = levelDownloader.Levels[levelSelection.GetIndex()]; } } levelGameObject = Instantiate(prefab); ConfigHandler.LoadConfig(); ConfigHandler.Config.SetField("Progress", levelSelection.GetIndex()); ConfigHandler.SaveConfig(); ObjectiveHandler.OnObjectiveActivated += ObjectiveActivated; ObjectiveHandler.OnObjectiveDeactivated += ObjectiveDeactivated; }
IEnumerator LoadNextLevel() { yield return(new WaitForSeconds(2f)); levelSelection.SetID(levelSelection.GetIndex() + 1); //yield return null; Application.LoadLevel("PrefabScene"); // Instantiate a new prefab }
void Start() { Image[] images = GetComponentsInChildren <Image>(); int numberOfLevels = levelDownloader.Levels.Length; int remainder; int result = Math.DivRem(numberOfLevels, 4, out remainder); if (numberOfLevels < 4) { totalPages = 0; } else if (result > 0 && remainder == 0) { totalPages = result - 1; } else if (remainder != 0) { totalPages = result; } pageCounter.text = (currentPage + 1) + "/" + (totalPages + 1); for (int t = 0; t < totalPages; t++) { for (int i = 0; i < images.Length; i++) { if (images[i].name == "ToMainMenu") { continue; } GameObject go = Instantiate(prefab) as GameObject; go.transform.SetParent(paren.transform); go.GetComponent <Image>().enabled = true; go.transform.position = new Vector3(images[i].transform.position.x, images[i].transform.position.y - (OFFSET * (t + 1))); go.transform.localScale = new Vector3(1f, 1f, 1f); } } images = GetComponentsInChildren <Image>(); JSONObject progress = ConfigHandler.IsLoaded ? ConfigHandler.Config : ConfigHandler.LoadConfig(); for (int i = 0; i < images.Length; i++) { if (images[i].name == "ToMainMenu") { continue; } if (i <= progress["Progress"].n) { Image image = images[i]; Texture2D tex2d = new Texture2D(800, 600); try { image.sprite = Sprite.Create(levelDownloader.Thumbnails[i], new Rect(0, 0, tex2d.width, tex2d.height), image.sprite.pivot); } catch (Exception) { image.sprite = unknown.sprite; image.color = unknown.color; } image.enabled = true; Text txt = image.GetComponentInChildren <Text>(); txt.text = "Level " + (i + 1); txt.enabled = false; LevelIdentity id = image.gameObject.AddComponent <LevelIdentity>(); id.SetID(i); id.SetCanClick(true); } else { Image image = images[i]; image.sprite = unknown.sprite; image.color = unknown.color; image.enabled = true; Text txt = image.GetComponentInChildren <Text>(); txt.text = "?"; txt.enabled = false; LevelIdentity id = image.gameObject.AddComponent <LevelIdentity>(); id.SetCanClick(false); } } }