SortedList <string, List <TextAsset> > Classify_Map(List <TextAsset> mapSources) { SortedList <string, List <TextAsset> > tempWorldList = new SortedList <string, List <TextAsset> > (); //파일 명: map-(대분류)-(소분류) //KeyValueSortedList 만들어서 쓰자 //맵들을 대분류에 맞게 분류한다. foreach (TextAsset mapSource in mapSources) { string World = MapFileUtil.mapWorld(mapSource); if (tempWorldList.ContainsKey(World)) { tempWorldList [World].Add(mapSource); } else { List <TextAsset> temp = new List <TextAsset> (); temp.Add(mapSource); tempWorldList.Add(World, temp); } } return(tempWorldList); }
private void genStageButtons() { foreach (var p in WorldDict) { var world = p.Key; var sources = p.Value; var i = WorldDict.IndexOfKey(world); sortSources(sources); var stageNames = sources.Select(s => MapFileUtil.mapTitleOfFile(s)).ToList(); var parent = worldButtons [i]; for (int j = 0; j < stageNames.Count(); j++) { var button = GameObject.Instantiate(Resources.Load <GameObject> ("prefabs/StagePanel")); button.transform.parent = parent.transform; var stageName = stageNames [j]; var text = GameObject.Instantiate(Resources.Load <GameObject> ("prefabs/StageText")); text.GetComponent <Text> ().text = stageName; text.transform.parent = button.transform; text.GetComponent <RectTransform> ().anchoredPosition = new Vector2(stageTextXOffset, 0f); offsetMap [button] = -j * stagePanelMargin + stagePanelMarginOffset; button.GetComponent <RectTransform> ().anchoredPosition = new Vector2(0f, stagePanelInitOffset); button.SetActive(false); int ind = j; button.GetComponent <Button> ().onClick.AddListener(() => { StartStage(sources, ind); }); } parent.GetComponent <Button> ().onClick.AddListener(() => { OnClick_WorldButton(world); }); } }
void StartStage(List <TextAsset> selection, int index) { Configuration.Instance.activatedMapSource = selection[index]; Configuration.List = selection; Configuration.Instance.mapName = MapFileUtil.mapTitleOfFile(selection[index]); TitleMusicScript.Instance.StopMusic(); SceneManager.LoadScene("GameplayScene"); }
public void onNextStage() { int CurrentIndex = Configuration.List.IndexOf(Configuration.Instance.activatedMapSource); if (CurrentIndex < Configuration.List.Count() - 1) { Configuration.Instance.mapName = MapFileUtil.mapTitleOfFile(Configuration.List [CurrentIndex + 1]); Configuration.Instance.activatedMapSource = Configuration.List [CurrentIndex + 1]; StageScript.Cleared = false; SceneManager.LoadScene("GameplayScene"); } else { onGotoStageSelect(); } }
void Start() { tutorialGameObject = GameObject.Find("WorldButton1"); world1GameObject = GameObject.Find("WorldButton2"); world2GameObject = GameObject.Find("WorldButton3"); world3GameObject = GameObject.Find("WorldButton4"); Protector = GameObject.Find("Protector"); worldButtons = new List <GameObject> () { tutorialGameObject, world1GameObject, world2GameObject, world3GameObject }; Protector.SetActive(false); List <TextAsset> mapSources = MapFileUtil.GetAllMapSources(); WorldDict = Classify_Map(mapSources); genStageButtons(); Protector.GetComponent <Button> ().onClick.AddListener(() => { StopAllCoroutines(); RestoreButtonPositions(); }); }
private void sortSources(List <TextAsset> sources) { sources.Sort((t1, t2) => { var title1 = MapFileUtil.mapTitleOfFile(t1); var title2 = MapFileUtil.mapTitleOfFile(t2); Func <String, KeyValuePair <int, int> > extract = (title) => { var regex = @"(World\s(\d+)-(\d+))|(Tutorial (\d+))"; var match = Regex.Match(title, regex); if (match.Groups [1].Success) { return(new KeyValuePair <int, int> (int.Parse(match.Groups [2].Value), int.Parse(match.Groups [3].Value))); } else { return(new KeyValuePair <int, int> (0, int.Parse(match.Groups [5].Value))); } }; var p1 = extract(title1); var p2 = extract(title2); var world1 = p1.Key; var world2 = p2.Key; var stage1 = p1.Value; var stage2 = p2.Value; if (world1 != world2) { return(world1.CompareTo(world2)); } else { return(stage1.CompareTo(stage2)); } }); }