Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        UIGridLevel = GameObject.Find("UIGridLevel");
        int i = 0;

        foreach (UILabel LevelButton in UIGridLevel.GetComponentsInChildren <UILabel>())
        {
            i++;
            LevelButtonList.Add(LevelButton.gameObject);
            LevelButton.gameObject.name = "Level" + i.ToString();
            LevelButton.text            = i.ToString();
        }


        UIGridChapter = GameObject.Find("UIGridChapter");
        i             = 0;
        foreach (BoxCollider ChapterButton in UIGridChapter.GetComponentsInChildren <BoxCollider>())
        {
            i++;
            ChapterButtonList.Add(ChapterButton.gameObject);
            ChapterButton.gameObject.name = "Chapter" + i.ToString();

            ChapterCache chaptercache = new ChapterCache();
            chaptercache.Setup(ChapterButton.gameObject);
            ChapterCacheDictionaty.Add(ChapterButton.gameObject, chaptercache);
        }


        if (Application.loadedLevel != 0 || GameSetting.Instance.mCurrentChapterLevel.mGameType == GAMETYPE.NOSELECTED)
        {
            HideLevelSelector();
        }
        else
        {
            ShowLevelSelector();
        }

        UICenterOnChapter             = UIGridChapter.GetComponent <UICenterOnChild> ();
        UICenterOnChapter.onFinished += UpdateChapterInCenter;
    }
Esempio n. 2
0
    public void ShowLevelSelector()
    {
        gameObject.SetActive(true);

        ChapterButtonDictionary = new Dictionary <GameObject, int> ();
        ChapterList             = new List <ChapterData>();
        ChapterDataDictionary   = new Dictionary <int, ChapterData> ();

        foreach (GameObject ChapterButton in ChapterButtonList)
        {
            ChapterButton.transform.parent = UIGridChapter.transform;
        }

        Object[] bindata = Resources.LoadAll("Levels");
        Debug.Log("Loading map all");
        foreach (TextAsset thisone in bindata)
        {
            Debug.Log("Loading map name" + thisone.name);
            Debug.Log("Loading map text" + thisone.text);
            Stream s = new MemoryStream(thisone.bytes);
            //ChapterData cd = GameSetting.Instance.LoadChapter(s);
            ChapterData cd = new ChapterData();
            cd.LoadDataFromMemory(s);
//			if(cd.GameType == GameSetting.Instance.mCurrentChapterLevel.mGameType){
            ChapterList.Add(cd);
            ChapterDataDictionary.Add(cd.ID, cd);
//			}
        }

        ChapterList = ChapterList.OrderBy(Chapter => Chapter.ID).ToList();

        while (ChapterList.Count > ChapterButtonList.Count)
        {
            GameObject newButton = NGUITools.AddChild(UIGridChapter, ObjectChapter);
            ChapterButtonList.Add(newButton);
            newButton.name = "Chapter" + ChapterButtonList.Count.ToString();

            ChapterCache chaptercache = new ChapterCache();
            chaptercache.Setup(newButton);
            ChapterCacheDictionaty.Add(newButton, chaptercache);

            UIGridChapter.GetComponent <UIGrid>().Reposition();
        }

        int i = 0;

        foreach (ChapterData mChapterData in ChapterList)
        {
            ChapterButtonList[i].SetActive(true);
            ChapterCache chaptercache;
            if (!ChapterCacheDictionaty.TryGetValue(ChapterButtonList[i], out chaptercache))
            {
                Debug.Log("ChapterCacheDictionaty.TryGetValue die");
            }
            chaptercache.NAME.text = mChapterData.Name;

            ChapterLevel mChapterLevel = new ChapterLevel(mChapterData.GameType, mChapterData.ID, 1);
            if (GameSetting.Instance.mLevelResults.ContainsKey(mChapterLevel))
            {
                chaptercache.NEW.SetActive(false);
            }
            else
            {
                chaptercache.NEW.SetActive(true);
            }

            if (mChapterLevel.iChapter == GameSetting.Instance.mCurrentChapterLevel.iChapter)
            {
                Debug.Log("CenterOn please");
                UICenterOnChapter.CenterOn(ChapterButtonList[i].transform);
            }

            ChapterButtonDictionary.Add(ChapterButtonList[i], mChapterData.ID);
            i++;
        }

        while (i < ChapterButtonList.Count)
        {
            ChapterButtonList[i].SetActive(false);
            ChapterButtonList[i].transform.parent = this.transform;
            i++;
        }

        //UIGridChapter.GetComponent<UIGrid>().Reposition();
        //UICenterOnChapter.Recenter ();

        UpdateChapterInCenter();
    }