protected override void OnOpen() { foreach (LevelSelectButton button in levelButtons) { Destroy(button.gameObject); } levelButtons = new List <LevelSelectButton> (); bool hasFourMaps = currentWorld.maps.Length == 4; string but = hasFourMaps ? "LevelSelectButton" : "LevelSelectButtonSmall"; foreach (Text label in titleLabels) { label.text = currentWorld.displayName.ToUpper(); } string nextKey = ""; for (int i = 0; i < currentWorld.maps.Length; i++) { currentWorld.maps [i].currentIndex = i; currentWorld.maps [i].keyID = nextKey; nextKey = currentWorld.maps [i].name; if (i == currentWorld.maps.Length - 1) { currentWorld.maps [i].isFinalLevel = true; } GameObject obj = Instantiate(Resources.Load(but)) as GameObject; LevelSelectButton button = obj.GetComponent <LevelSelectButton> (); button.Init(currentWorld.maps [i]); button.transform.parent = anchor; if (hasFourMaps) { button.transform.localPosition = new Vector3(i * 200f - 300f, 0f, 0f); } else { button.transform.localPosition = new Vector3(i * 100f - 350f, 25f - (i % 2) * 50f, 0f); } button.transform.localScale = Vector3.one; levelButtons.Add(button); } foreach (Text levelNameLabel in levelNameLabels) { levelNameLabel.text = currentWorld.displayName; } levelInfoBg.CrossFadeAlpha(0f, 0f, true); Image[] images = levelInfoBg.GetComponentsInChildren <Image> (); foreach (Image image in images) { image.CrossFadeAlpha(0f, 0f, true); } Text[] texts = levelInfoBg.GetComponentsInChildren <Text> (); foreach (Text text in texts) { text.CrossFadeAlpha(0f, 0f, true); } }
void Awake() { WorldSelectedTilePosition = new Vector2(0f, 3f * tileWidth - 1); WorldPositions = new[] { new Vector2(-2f * tileWidth, 2f * tileWidth - 1), new Vector2(0f * tileWidth, 2f * tileWidth - 1), new Vector2(2f * tileWidth, 2f * tileWidth - 1), new Vector2(-2f * tileWidth, 0f * tileWidth - 1), new Vector2(0f * tileWidth, 0f * tileWidth - 1), new Vector2(2f * tileWidth, 0f * tileWidth - 1), new Vector2(-2f * tileWidth, -2f * tileWidth - 1), new Vector2(0f * tileWidth, -2f * tileWidth - 1), new Vector2(2f * tileWidth, -2f * tileWidth - 1), new Vector2(-2f * tileWidth, -4f * tileWidth - 1), new Vector2(0f * tileWidth, -4f * tileWidth - 1), new Vector2(2f * tileWidth, -4f * tileWidth - 1) }; LevelPositions = new [] { new Vector2(2f * tileWidth, 2f * tileWidth - 1), new Vector2(-2f * tileWidth, 0f * tileWidth - 1), new Vector2(0f * tileWidth, 0f * tileWidth - 1), new Vector2(2f * tileWidth, 0f * tileWidth - 1), new Vector2(-2f * tileWidth, -2f * tileWidth - 1), new Vector2(0f * tileWidth, -2f * tileWidth - 1), new Vector2(2f * tileWidth, -2f * tileWidth - 1), new Vector2(-2f * tileWidth, -4f * tileWidth - 1), new Vector2(0f * tileWidth, -4f * tileWidth - 1), new Vector2(2f * tileWidth, -4f * tileWidth - 1), //garbage Vector2.zero, Vector2.zero }; int highest = GameManager.Instance.HighestUnlockedLevel; SceneHelpers.GetWorldAndLevelFromBuildIndex(highest, out highestUnlockedWorld, out highestUnlockedLevel); levelData = GameManager.Instance.SaveData.LevelData; NumberedLevelButtons = GetComponentsInChildren <NumberedLevelSelectButton>().ToArray(); // 1 - 12 for (int i = 0; i < NumberedLevelButtons.Length; i++) { NumberedLevelSelectButton b = NumberedLevelButtons[i]; b.Init(i + 1); SetLevelSelectButton(b); b.TryEnableInteractable(); } Back.Init(); if (LevelSelectOpen) { NumberedLevelSelectButton b = NumberedLevelButtons[WorldSelected - 1]; SetLevelSelectButton(b); if (SelectedWorldComplete) { b.Interactable = true; b.SetOnClick(SwitchToWorldCompleteScene); } else { b.Interactable = false; } Back.transform.localScale = Vector3.one; } else { Back.SetHidden(true, null, true); } }