public void SetWorldMap(DataTransfer data)
        {
            m_LevelMapRect = m_LevelMap.GetComponent <RectTransform>();
            m_LevelMapRect.anchoredPosition = Vector2.zero;
            Vector2 screenRect            = new Vector2(Screen.width, Screen.height);
            Vector2 uiRect                = new Vector2(Screen.width, 1136f * Screen.height / (float)Screen.width);
            Vector2 uiLeftAndTopPos       = new Vector2(uiRect.x / 2f, uiRect.y / 2f);
            Vector2 LevelMapLeftAndTopPos = m_LevelMapRect.anchoredPosition + new Vector2(m_LevelMapRect.rect.width / 2f, m_LevelMapRect.rect.height / 2f);
            Vector2 relativePos           = LevelMapLeftAndTopPos - uiLeftAndTopPos;

            m_LevelMapMin = m_LevelMapRect.anchoredPosition - relativePos;
            m_LevelMapMax = m_LevelMapRect.anchoredPosition + relativePos;

            m_LevelItemList = new List <UILevelItemView>();
            List <DataTransfer> levelList = data.GetData <List <DataTransfer> >(ConstDefine.UI_WorldMap_Content);
            bool isMatch           = false;
            int  maxCanPlayLevelId = data.GetData <int>(ConstDefine.UI_WorldMap_MaxCanPlayGameLevelId);

            for (int i = 0; i < levelList.Count; i++)
            {
                GameObject go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.UIWindowChild, "LevelItem", isCache: true);
                if (go != null)
                {
                    go.transform.SetParent(m_LevelMap);
                    go.transform.localPosition = Vector2.zero;
                    go.transform.localScale    = Vector3.one;
                    UILevelItemView view = go.GetComponent <UILevelItemView>();
                    if (view != null)
                    {
                        int     levelId   = levelList[i].GetData <int>(ConstDefine.UI_WorldMap_LevelId);
                        int     grade     = levelList[i].GetData <int>(ConstDefine.UI_WorldMap_LevelGrade);
                        string  levelName = levelList[i].GetData <string>(ConstDefine.UI_WorldMap_LevelName);
                        string  levelIcon = levelList[i].GetData <string>(ConstDefine.UI_WorldMap_LevelIcon);
                        Vector2 levelPos  = levelList[i].GetData <Vector2>(ConstDefine.UI_WorldMap_LevelPos);
                        bool    canPlay   = levelList[i].GetData <bool>(ConstDefine.UI_WorldMap_CanPlay);
                        view.SetUI(levelId, grade, canPlay, levelName, levelIcon, levelPos);
                        view.OnClick += OnClickGameLevelItemCallBack;
                        if (maxCanPlayLevelId == -1001 && !isMatch)//未通关上一难度,从第一关开始
                        {
                            MatchPassGameLevel(levelPos);
                            isMatch = true;
                        }
                        else if (!isMatch)
                        {
                            if (maxCanPlayLevelId == levelId)
                            {
                                MatchPassGameLevel(levelPos);
                                isMatch = true;
                            }
                        }
                    }
                }
            }
            if (!isMatch)
            {
                Debug.LogError("错误:没有找到匹配的关卡");
            }
        }
Пример #2
0
        private IEnumerator SetUIIE(DataTransfer data)
        {
            m_Count           = (int)(m_RowAnCol.x * m_RowAnCol.y);
            m_LevelViewList   = new List <UILevelItemView>();
            m_TweenList       = new List <Tween>();
            m_GridLayoutGroup = m_Grid.GetComponent <GridLayoutGroup>();
            float heightScale = Screen.height / (Screen.width * (852 / 1136f));

            m_GridLayoutGroup.cellSize    *= heightScale;
            m_GridLayoutGroup.spacing     *= heightScale;
            m_BtnLeft.sizeDelta           *= heightScale;
            m_BtnRight.sizeDelta          *= heightScale;
            m_BtnLeft.anchoredPosition3D  *= heightScale;
            m_BtnRight.anchoredPosition3D *= heightScale;
            for (int i = 0; i < m_Count; i++)
            {
                GameObject go = ResourcesMrg.Instance.Load(ResourcesMrg.ResourceType.UIWindowChild, "LevelItem", isCache: true);
                go.transform.SetParent(m_Grid);
                go.transform.localScale    = Vector3.one;
                go.transform.localPosition = Vector3.zero;
                UILevelItemView view = go.GetComponent <UILevelItemView>();
                view.OnClickBtn += OnClickGameLevelItemBtn;
                m_LevelViewList.Add(view);
            }
            m_MaxPassLevel = data.GetData <int>(ConstDefine.MaxCanPlay);
            m_MaxLevel     = data.GetData <int>(ConstDefine.MaxLevel);
            m_StarInfo     = data.GetData <List <int> >(ConstDefine.StarInfo);
            yield return(null);

            bool isRun = true;

            m_Index = 1;
            while (isRun)
            {
                int index = m_Index;
                index += m_Count;
                if (index <= m_MaxPassLevel)
                {
                    m_Index += m_Count;
                }
                else
                {
                    m_Index += m_Count;
                    isRun    = false;
                }
            }
            Refresh(true);
        }