private void InitResources()
    {
        //加载方块背景类型资源
        for (int i = 0; i < gridBaseTypeId.Length; i++)
        {
            Sprite sprite = new Sprite();
            sprite = Resources.Load <Sprite>(gridBaseTypeId[i]) as Sprite;
            baseSprites.Add(sprite);
        }

        //加载方块背景类型资源
        for (int i = 0; i < resourcesId.Length; i++)
        {
            Sprite sprite = new Sprite();
            sprite = Resources.Load <Sprite>(resourcesId[i]) as Sprite;
            allSprites.Add(sprite);
        }
        GridUIAttributeManager.GetInstance().allSprites = allSprites;

        //加载方块背景类型资源
        for (int i = 0; i < specialGrids.Length; i++)
        {
            Sprite sprite = new Sprite();
            sprite = Resources.Load <Sprite>(specialGrids[i]) as Sprite;
            specialSprites.Add(sprite);
        }
        GridUIAttributeManager.GetInstance().specialSprites = specialSprites;
    }
Beispiel #2
0
 /// <summary>
 /// 接收GridUI的对象和数据
 /// </summary>
 private void InitGridUIAttribute()
 {
     mEditorData          = GridUIAttributeManager.GetInstance().editorData;
     mSprites             = GridUIAttributeManager.GetInstance().allSprites;
     mGridListManager     = GridUIAttributeManager.GetInstance().gridListManager;
     mGridBaseListManager = GridUIAttributeManager.GetInstance().gridBaseListManager;
     mGameBackground      = GridUIAttributeManager.GetInstance().GameBackground;
     mGridBg         = GridUIAttributeManager.GetInstance().GridBg;
     mGrid           = GridUIAttributeManager.GetInstance().Grid;
     mGridDataList   = GridUIAttributeManager.GetInstance().gridDataList;
     mDoorDataList   = GridUIAttributeManager.GetInstance().doorDataList;
     mIceDataList    = GridUIAttributeManager.GetInstance().iceDataList;
     mBasketDataList = GridUIAttributeManager.GetInstance().basketDataList;
     mTimboDataList  = GridUIAttributeManager.GetInstance().timboDataList;
 }
Beispiel #3
0
 /// <summary>
 /// 初始化GridUI中的对象和变量
 /// </summary>
 public static void InitGridUIAttribute()
 {
     mGameData            = GridUIAttributeManager.GetInstance().gameData;
     mGridListManager     = GridUIAttributeManager.GetInstance().gridListManager;
     mInterval            = GridUIAttributeManager.GetInstance().interval;
     mGridDropList        = GridUIAttributeManager.GetInstance().gridDropList;
     mGrid                = GridUIAttributeManager.GetInstance().Grid;
     mAllSprites          = GridUIAttributeManager.GetInstance().allSprites;
     mGridSize            = GridUIAttributeManager.GetInstance().gridSize;
     mGridBaseListManager = GridUIAttributeManager.GetInstance().gridBaseListManager;
     mDoorDataList        = GridUIAttributeManager.GetInstance().doorDataList;
     mBasketDataList      = GridUIAttributeManager.GetInstance().basketDataList;
     mGridOfBeanPodList   = GridUIAttributeManager.GetInstance().gridOfBeanPodList;
     mDeleteCounts        = GridUIAttributeManager.GetInstance().deleteCounts;
 }
Beispiel #4
0
    private void GetStartGrid()
    {
        //[1]隐藏目标完成后的对象
        mGreat.SetActive(false);

        float gameBgWith = mGameBackground.GetComponent <RectTransform>().rect.width;
        float leaveSize  = GridUIAttributeManager.GetInstance().leaveSize;

        //[2]计算格子所在边界,x为左边界,y为上边界
        y = Screen.height * 0.75f;
        if (Screen.height >= Screen.width)
        {
            x = leaveSize / 2;
        }
        else
        {
            x = Screen.width / 2 - gameBgWith / 2 + leaveSize / 2;
        }
        float intervalPx = 1.0f;

        //[3]鼠标点中格子区域才会响应,记录初次点中的方块信息
        if (Input.mousePosition.x > x && Input.mousePosition.x < (x + mGridSize * mGameData.vertical + intervalPx * (mGameData.vertical - 1)) && Input.mousePosition.y < y && Input.mousePosition.y > (y - ((mGameData.horizontal * mGridSize + intervalPx * (mGameData.horizontal - 1)))))
        {
            startVertical   = (int)((Input.mousePosition.x - x) / (mGridSize + intervalPx));
            startHorizontal = startListIndex = (int)((y - Input.mousePosition.y) / (mGridSize + intervalPx));
            int startSpriteIndex = mGridBaseListManager[startVertical][startHorizontal].spriteIndex;
            if (mGridBaseListManager[startVertical][startHorizontal].isHasGrid && startSpriteIndex != -1 && !(startSpriteIndex >= 15 && startSpriteIndex <= 20))
            {
                //判断startVertical该列上没有方块
                for (int h = startHorizontal - 1; h >= 0; h--)
                {
                    if (!mGridBaseListManager[startVertical][h].isHasGrid)
                    {
                        startListIndex--;
                    }
                }

                if (mGridListManager[startVertical][startListIndex].spriteIndex != -1)
                {
                    startPoint = mGridListManager[startVertical][startListIndex].gridObject.GetComponent <RectTransform>().position;
                    lineConnectGridList.Add(mGridListManager[startVertical][startListIndex]);
                }
            }
        }
    }
    public void InitFinishPlayLevel()
    {
        great = new GameObject();
        GridUIAttributeManager.GetInstance().great = great;
        great.name = "win";
        great.AddComponent <Image>();
        great.GetComponent <RectTransform>().SetParent(mainCanvas.transform);
        Sprite sprite_great = new Sprite();

        sprite_great = Resources.Load("great_text", sprite_great.GetType()) as Sprite;
        great.GetComponent <Image>().sprite            = sprite_great;
        great.GetComponent <RectTransform>().sizeDelta = new Vector2(gameBgWith / 2, gameBgWith / 2);
        if (Screen.height / Screen.width >= gameBgHeight / gameBgWith)
        {
            great.GetComponent <RectTransform>().position = new Vector3(gameBgWith / 2, gameBgHeight / 2, 0.0f);
        }
        else
        {
            great.GetComponent <RectTransform>().position = new Vector3(Screen.width / 2, gameBgHeight / 2, 0.0f);
        }
        great.SetActive(false);
    }
Beispiel #6
0
 /// <summary>
 /// 初始化GridUI中的对象和变量
 /// </summary>
 public static void InitGridUIAttribute()
 {
     mEditorData          = GridUIAttributeManager.GetInstance().editorData;
     mGameData            = GridUIAttributeManager.GetInstance().gameData;
     mGridListManager     = GridUIAttributeManager.GetInstance().gridListManager;
     mGrid                = GridUIAttributeManager.GetInstance().Grid;
     mGameBackground      = GridUIAttributeManager.GetInstance().GameBackground;
     mAllSprites          = GridUIAttributeManager.GetInstance().allSprites;
     mGridSize            = GridUIAttributeManager.GetInstance().gridSize;
     mIntervalPx          = GridUIAttributeManager.GetInstance().intervalPx;
     mGridBaseListManager = GridUIAttributeManager.GetInstance().gridBaseListManager;
     mGridOfBeanPodList   = GridUIAttributeManager.GetInstance().gridOfBeanPodList;
     mTimboDataList       = GridUIAttributeManager.GetInstance().timboDataList;
     mIceDataList         = GridUIAttributeManager.GetInstance().iceDataList;
     mFrostingList        = GridUIAttributeManager.GetInstance().frostingList;
     mPoisonList          = GridUIAttributeManager.GetInstance().poisonList;
     mCreateBeanPodStep   = GridUIAttributeManager.GetInstance().createBeanPodStep;
     mIsCreateBeanPod     = GridUIAttributeManager.GetInstance().isCreateBeanPod;
     mGreat               = GridUIAttributeManager.GetInstance().great;
     mStepCounts          = GridUIAttributeManager.GetInstance().stepCounts;
     mTargetCount         = GridUIAttributeManager.GetInstance().targetCount;
     mSpecialSprites      = GridUIAttributeManager.GetInstance().specialSprites;
     deleteCounts         = GridUIAttributeManager.GetInstance().deleteCounts;
 }
    public void InitData()
    {
        //[0]读取配置,获取对象
        editorData = JsonUtil.GetEditorData(10);
        GridUIAttributeManager.GetInstance().editorData = editorData;

        //[1]获取格子内容信息
        if (!editorData.gridData.Equals(""))
        {
            string[] gridDatas = editorData.gridData.Split(',');
            gridDataList = new List <GridBean>();
            foreach (string grid in gridDatas)
            {
                if (!grid.Equals(""))
                {
                    string[] result   = grid.Split('|');
                    GridBean gridBean = new GridBean();
                    gridBean.vertical    = int.Parse(result[0]);
                    gridBean.horizontal  = int.Parse(result[1]);
                    gridBean.spriteIndex = int.Parse(result[2]);
                    gridDataList.Add(gridBean);
                }
            }
            GridUIAttributeManager.GetInstance().gridDataList = gridDataList;
        }

        //[2]获取传送门数据
        if (!editorData.doorData.Equals(""))
        {
            string[] doorDatas = editorData.doorData.Split(',');
            doorDataList = new List <DoorBean>();
            foreach (string door in doorDatas)
            {
                if (!door.Equals(""))
                {
                    string[] result   = door.Split('|');
                    DoorBean doorBean = new DoorBean();
                    doorBean.inVertical    = int.Parse(result[0]);
                    doorBean.inHorizontal  = int.Parse(result[1]);
                    doorBean.outVertical   = int.Parse(result[2]);
                    doorBean.outHorizontal = int.Parse(result[3]);
                    doorDataList.Add(doorBean);
                }
            }
            GridUIAttributeManager.GetInstance().doorDataList = doorDataList;
        }

        //[3]获取冰块数据
        if (!editorData.iceData.Equals(""))
        {
            string[] iceDatas = editorData.iceData.Split(',');
            iceDataList = new List <IceBean>();
            foreach (string ice in iceDatas)
            {
                if (!ice.Equals(""))
                {
                    string[] result  = ice.Split('|');
                    IceBean  iceBean = new IceBean();
                    iceBean.iceVertical   = int.Parse(result[0]);
                    iceBean.iceHorizontal = int.Parse(result[1]);
                    iceBean.iceLevel      = int.Parse(result[2]);
                    iceDataList.Add(iceBean);
                }
            }
            GridUIAttributeManager.GetInstance().iceDataList = iceDataList;
        }

        //获取金豆荚篮子数据
        if (!editorData.basketData.Equals(""))
        {
            string[] basketDatas = editorData.basketData.Split(',');
            basketDataList = new List <BasketBean>();
            foreach (string basket in basketDatas)
            {
                if (!basket.Equals(""))
                {
                    string[]   result     = basket.Split('|');
                    BasketBean basketBean = new BasketBean();
                    basketBean.basketVertical   = int.Parse(result[0]);
                    basketBean.basketHorizontal = int.Parse(result[1]);
                    basketDataList.Add(basketBean);
                }
            }
            GridUIAttributeManager.GetInstance().basketDataList = basketDataList;
        }

        //获取树藤数据
        if (!editorData.timboData.Equals(""))
        {
            string[] timboDatas = editorData.timboData.Split(',');
            timboDataList = new List <TimboBean>();
            foreach (string timbo in timboDatas)
            {
                if (!timbo.Equals(""))
                {
                    string[]  result    = timbo.Split('|');
                    TimboBean timboBean = new TimboBean();
                    timboBean.timboVertical   = int.Parse(result[0]);
                    timboBean.timboHorizontal = int.Parse(result[1]);
                    timboDataList.Add(timboBean);
                }
            }
            GridUIAttributeManager.GetInstance().timboDataList = timboDataList;
        }
    }
    public void InitGrid()
    {
        //[0]初始化父控件
        GridBg = new GameObject();
        Grid   = new GameObject();
        GridUIAttributeManager.GetInstance().Grid   = Grid;
        GridUIAttributeManager.GetInstance().GridBg = GridBg;

        GridBg.AddComponent <RectTransform>();
        Grid.AddComponent <RectTransform>();
        GridBg.name = "GridBg";
        Grid.name   = "Grid";
        GridBg.GetComponent <RectTransform>().SetParent(mainCanvas.transform);
        Grid.GetComponent <RectTransform>().SetParent(mainCanvas.transform);

        //[2]设置格子大小
        gameData            = new GameData();
        gameData.horizontal = 9;
        gameData.vertical   = 9;
        GridUIAttributeManager.GetInstance().gameData = gameData;
        leaveSize = 0;
        GridUIAttributeManager.GetInstance().leaveSize = leaveSize;
        intervalPx = 1.0f;
        if (Screen.height >= Screen.width)
        {
            if (gameData.vertical > 9)
            {
                gridSize = (Screen.width - leaveSize - (gameData.vertical - 1) * intervalPx) / gameData.vertical;
            }
            else
            {
                gridSize = (Screen.width - leaveSize - (9 - 1) * intervalPx) / 9;
            }
        }
        else
        {
            if (gameData.horizontal > 9)
            {
                gridSize = (gameBgWith - leaveSize - (gameData.horizontal - 1) * intervalPx) / gameData.horizontal;
            }
            else
            {
                gridSize = (gameBgWith - leaveSize - (9 - 1) * intervalPx) / 9;
            }
        }

        interval = gridSize + intervalPx;
        GridUIAttributeManager.GetInstance().intervalPx = intervalPx;
        GridUIAttributeManager.GetInstance().gridSize   = gridSize;
        GridUIAttributeManager.GetInstance().interval   = interval;
        //[3]动态创建方块
        //[3.1]设置每一列方块的初始位置 x
        if (Screen.height >= Screen.width)
        {
            x = leaveSize / 2 + gridSize / 2;
        }
        else
        {
            x = Screen.width / 2 - gameBgWith / 2 + leaveSize / 2 + gridSize / 2;
        }

        for (int vertical = 0; vertical < gameData.vertical; vertical++, x = x + interval)
        {
            //[3.2]设置第一行方块的初始位置 y
            y            = Screen.height * 0.75f - gridSize / 2 + interval;
            gridList     = new List <GridBean>();
            gridBaseList = new List <GridBaseBean>();
            for (int horizontal = 0; horizontal < gameData.horizontal + 1; horizontal++, y = y - interval)
            {
                //[3.3]生成场景
                if (horizontal != 0)
                {
                    GameObject gridbase = Instantiate(Resources.Load("prefabs/gridbase"), GridBg.transform) as GameObject;
                    Destroy(gridbase.GetComponent <SpriteRenderer>());
                    gridbase.name = "gridbase" + vertical.ToString() + (horizontal - 1).ToString();
                    gridbase.AddComponent <Image>();
                    gridbase.GetComponent <Image>().sprite            = baseSprites[0];
                    gridbase.GetComponent <RectTransform>().position  = new Vector3(x, y, 0);
                    gridbase.GetComponent <RectTransform>().sizeDelta = new Vector2(gridSize, gridSize);
                    GridBaseBean gridBaseBean = new GridBaseBean();
                    gridBaseBean.gridBase = gridbase;
                    gridBaseList.Add(gridBaseBean);
                }

                //[3.31]生成冰块
                if (iceDataList != null && horizontal != 0)
                {
                    foreach (IceBean iceBean in iceDataList)
                    {
                        if (iceBean.iceVertical == vertical && iceBean.iceHorizontal == horizontal - 1)
                        {
                            GameObject ice = Instantiate(Resources.Load("prefabs/gridbase"), GridBg.transform) as GameObject;
                            Destroy(ice.GetComponent <SpriteRenderer>());
                            ice.name = "ice" + iceBean.iceVertical.ToString() + iceBean.iceHorizontal.ToString();
                            ice.AddComponent <Image>();
                            ice.GetComponent <Image>().sprite            = allSprites[iceBean.iceLevel + 9];
                            ice.GetComponent <RectTransform>().position  = new Vector3(x, y, 0);
                            ice.GetComponent <RectTransform>().sizeDelta = new Vector2(gridSize, gridSize);
                            iceBean.ice = ice;
                            break;
                        }
                    }
                }

                //[3.32]生成金豆荚篮子
                if (basketDataList != null && horizontal != 0)
                {
                    foreach (BasketBean basketBean in basketDataList)
                    {
                        if (basketBean.basketVertical == vertical && basketBean.basketHorizontal == horizontal - 1)
                        {
                            GameObject basket = Instantiate(Resources.Load("prefabs/gridbase"), GridBg.transform) as GameObject;
                            Destroy(basket.GetComponent <SpriteRenderer>());
                            basket.name = "basket" + basketBean.basketVertical.ToString() + basketBean.basketHorizontal.ToString();
                            basket.AddComponent <Image>();
                            basket.GetComponent <Image>().sprite            = allSprites[14];
                            basket.GetComponent <RectTransform>().sizeDelta = new Vector2(gridSize * 0.9f, gridSize * 0.4f);
                            basket.GetComponent <RectTransform>().position  = new Vector3(x, y, 0) + new Vector3(0.0f, -gridSize / 2 - gridSize * 0.4f / 2, 0.0f);
                            basketBean.basket = basket;
                            break;
                        }
                    }
                }

                //[3.4]生成方块
                GameObject grid = Instantiate(Resources.Load("prefabs/grid"), Grid.transform) as GameObject;
                Destroy(grid.GetComponent <SpriteRenderer>());
                grid.AddComponent <Image>();
                GridBean gridBean = new GridBean();
                gridBean.specialTpye = -1;
                if (horizontal != 0)
                {
                    gridBaseList[horizontal - 1].gridBean = gridBean;
                }

                //遍历配置文件,若有对应固定的位置,则根据情况显示
                if (horizontal != 0)
                {
                    //默认随机
                    gridBean.spriteIndex = UnityEngine.Random.Range(2, 8);
                    gridBaseList[horizontal - 1].spriteIndex = gridBean.spriteIndex;
                    gridBaseList[horizontal - 1].isHasGrid   = true;
                    //如果配置数据为空,则默认随机
                    if (gridDataList != null)
                    {
                        foreach (GridBean gridData in gridDataList)
                        {
                            if (vertical == gridData.vertical && (horizontal - 1) == gridData.horizontal)
                            {
                                switch (gridData.spriteIndex)
                                {
                                case 1:    //不显示
                                    gridBaseList[horizontal - 1].spriteIndex = -1;
                                    gridBean.spriteIndex = gridData.spriteIndex;
                                    gridBaseList[horizontal - 1].gridBase.SetActive(false);
                                    grid.SetActive(false);
                                    break;

                                case 15:    //雪块
                                case 16:
                                case 17:
                                case 18:
                                case 19:
                                    gridBean.spriteIndex = gridData.spriteIndex;
                                    gridBaseList[horizontal - 1].spriteIndex = gridData.spriteIndex;
                                    frostingList.Add(gridBean);
                                    break;

                                case 20:
                                    gridBean.spriteIndex = gridData.spriteIndex;
                                    gridBaseList[horizontal - 1].spriteIndex = gridData.spriteIndex;
                                    poisonList.Add(gridBean);
                                    break;

                                default:    //默认根据ID显示对应资源
                                    gridBean.spriteIndex = gridData.spriteIndex;
                                    gridBaseList[horizontal - 1].spriteIndex = gridBean.spriteIndex;
                                    break;
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        //如果格子内容没有数据, 则默认为空
                        gridBean.spriteIndex = UnityEngine.Random.Range(2, 8);
                        gridBaseList[horizontal - 1].spriteIndex = gridBean.spriteIndex;
                        gridBaseList[horizontal - 1].isHasGrid   = true;
                    }
                }
                else
                {
                    //备用方块的资源
                    gridBean.spriteIndex = UnityEngine.Random.Range(2, 8);
                }

                //设置金豆荚位置
                if (beanPodList != null && horizontal != 0)
                {
                    foreach (BeanPod beanPod in beanPodList)
                    {
                        if (beanPod.beanPodVeritcal == vertical && beanPod.beanPodHorizontal == horizontal - 1)
                        {
                            gridBean.spriteIndex = 13;
                            gridOfBeanPodList.Add(gridBean);
                            break;
                        }
                    }
                }

                //生成树藤
                if (timboDataList != null && horizontal != 0)
                {
                    foreach (TimboBean timboBean in timboDataList)
                    {
                        if (timboBean.timboVertical == vertical && timboBean.timboHorizontal == horizontal - 1)
                        {
                            GameObject timbo = Instantiate(Resources.Load("prefabs/gridbase"), Grid.transform) as GameObject;
                            Destroy(timbo.GetComponent <SpriteRenderer>());
                            timbo.name = "timbo" + timboBean.timboVertical.ToString() + timboBean.timboHorizontal.ToString();
                            timbo.AddComponent <Image>();
                            timbo.GetComponent <Image>().sprite            = allSprites[21];
                            timbo.GetComponent <RectTransform>().sizeDelta = new Vector2(gridSize * 1.1f, gridSize * 1.1f);
                            timbo.GetComponent <RectTransform>().position  = new Vector3(x - gridSize * 0.05f, y, 0);
                            timboBean.timbo = timbo;
                            gridBaseList[horizontal - 1].spriteIndex = 21;
                            break;
                        }
                    }
                }

                if (gridBean.spriteIndex > 1)
                {
                    grid.GetComponent <Image>().sprite = allSprites[gridBean.spriteIndex];
                }
                grid.GetComponent <RectTransform>().position  = new Vector3(x, y, 0);
                grid.GetComponent <RectTransform>().sizeDelta = new Vector2(gridSize, gridSize);
                gridBean.gridObject     = grid;
                gridBean.moveHorizontal = 9;

                //[3.5]储存格子掉落信息
                if (horizontal == 0)
                {
                    gridBean.horizontal = horizontal;
                    gridBean.vertical   = vertical;
                    grid.name           = "grid" + gridBean.vertical.ToString() + gridBean.horizontal.ToString();
                    grid.SetActive(false);
                    gridBean.isTop = true;
                    gridDropList.Add(gridBean);
                }

                //[3.6]储存格式显示信息
                if (horizontal != 0)
                {
                    gridBean.horizontal = horizontal - 1;
                    gridBean.vertical   = vertical;
                    grid.name           = "grid" + gridBean.vertical.ToString() + gridBean.horizontal.ToString();
                    gridBean.isTop      = false;
                    gridList.Add(gridBean);
                }
            }
            gridBaseListManager.Add(gridBaseList);
            gridListManager.Add(gridList);
        }
        GridUIAttributeManager.GetInstance().gridDropList        = gridDropList;
        GridUIAttributeManager.GetInstance().gridListManager     = gridListManager;
        GridUIAttributeManager.GetInstance().gridBaseListManager = gridBaseListManager;
        if (gridOfBeanPodList != null)
        {
            GridUIAttributeManager.GetInstance().gridOfBeanPodList = gridOfBeanPodList;
        }
        if (frostingList != null)
        {
            GridUIAttributeManager.GetInstance().frostingList = frostingList;
        }
        if (poisonList != null)
        {
            GridUIAttributeManager.GetInstance().poisonList = poisonList;
        }

        //[4]生成传送门
        if (doorDataList != null)
        {
            foreach (DoorBean doorbean in doorDataList)
            {
                //入口
                GameObject indoor = Instantiate(Resources.Load("prefabs/gridbase"), GridBg.transform) as GameObject;
                Destroy(indoor.GetComponent <SpriteRenderer>());
                indoor.name = "indoor" + doorbean.inVertical.ToString() + doorbean.inHorizontal.ToString();
                indoor.AddComponent <Image>();
                indoor.GetComponent <Image>().sprite = allSprites[8];
                doorPoint = gridListManager[doorbean.inVertical][doorbean.inHorizontal].gridObject.GetComponent <RectTransform>().position;
                indoor.GetComponent <RectTransform>().position  = doorPoint + new Vector3(0.0f, -gridSize * 2 / 3, 0.0f);
                indoor.GetComponent <RectTransform>().sizeDelta = new Vector2(gridSize, gridSize);
                indoor.GetComponent <RectTransform>().Rotate(new Vector3(75, 0.0f, 0.0f));
                doorbean.indoor = indoor;

                //出口
                GameObject outdoor = Instantiate(Resources.Load("prefabs/gridbase"), GridBg.transform) as GameObject;
                Destroy(outdoor.GetComponent <SpriteRenderer>());
                outdoor.name = "outdoor" + doorbean.outVertical.ToString() + doorbean.outHorizontal.ToString();
                outdoor.AddComponent <Image>();
                outdoor.GetComponent <Image>().sprite = allSprites[9];
                doorPoint = gridListManager[doorbean.outVertical][doorbean.outHorizontal].gridObject.GetComponent <RectTransform>().position;
                outdoor.GetComponent <RectTransform>().position  = doorPoint + new Vector3(0.0f, gridSize * 2 / 3, 0.0f);
                outdoor.GetComponent <RectTransform>().sizeDelta = new Vector2(gridSize, gridSize);
                outdoor.GetComponent <RectTransform>().Rotate(new Vector3(75, 0.0f, 0.0f));
                doorbean.outdoor = outdoor;
            }
        }
    }
    private void InitPlayLevelMsg()
    {
        //[1]设置目标类型
        targetGrid      = Instantiate(Resources.Load("prefabs/grid"), targetBoard.transform) as GameObject;
        targetGrid.name = "targetGrid";
        Destroy(targetGrid.GetComponent <SpriteRenderer>());
        targetGrid.AddComponent <Image>();
        targetGrid.GetComponent <Image>().sprite            = allSprites[editorData.targetType];
        targetGrid.GetComponent <RectTransform>().sizeDelta = new Vector2(gameBgWith * 0.1f * 0.7f, gameBgWith * 0.1f * 0.7f);
        if (Screen.height / Screen.width >= gameBgHeight / gameBgWith)
        {
            targetGrid.GetComponent <RectTransform>().position = new Vector3(gameBgWith / 2 - gameBgWith * 0.1f * 0.7f * 1 / 3, gameBgHeight - gameBgHeight * 0.1f + gameBgHeight * 0.1f * 2 / 4, 0.0f);
        }
        else
        {
            targetGrid.GetComponent <RectTransform>().position = new Vector3(Screen.width / 2 - gameBgWith * 0.1f * 0.7f * 1 / 3, gameBgHeight - gameBgHeight * 0.1f + gameBgWith * 0.1f * 2 / 4, 0.0f);
        }

        //[1.1]判断通过目标是否金豆荚
        if (editorData.targetType == 13)
        {
            beanPodList = new List <BeanPod>();
            BeanPod beanPod = new BeanPod();
            beanPod.beanPodVeritcal   = UnityEngine.Random.Range(0, 9);
            beanPod.beanPodHorizontal = 0;
            beanPodList.Add(beanPod);

            //生成金豆荚的平均步数
            createBeanPodStep = editorData.stepCounts / editorData.targetCounts;
            isCreateBeanPod   = createBeanPodStep;
            GridUIAttributeManager.GetInstance().createBeanPodStep = createBeanPodStep;
            GridUIAttributeManager.GetInstance().isCreateBeanPod   = isCreateBeanPod;
        }

        //[1.2]设置目标数量
        targetCount = new GameObject();
        GridUIAttributeManager.GetInstance().targetCount = targetCount;
        targetCount.name = "targetCount";
        targetCount.AddComponent <Text>();
        targetCount.GetComponent <Text>().text      = "x" + editorData.targetCounts;
        targetCount.GetComponent <Text>().fontSize  = (int)(gameBgWith * 0.1f * 0.7f / 2);
        targetCount.GetComponent <Text>().fontStyle = FontStyle.Bold;
        targetCount.GetComponent <Text>().color     = Color.yellow;
        targetCount.GetComponent <Text>().font      = songTi;
        targetCount.transform.SetParent(targetBoard.transform);
        targetCount.GetComponent <RectTransform>().sizeDelta = new Vector2(gameBgWith * 0.1f * 0.8f, gameBgWith * 0.1f * 0.8f);
        if (Screen.height / Screen.width >= gameBgHeight / gameBgWith)
        {
            targetCount.GetComponent <RectTransform>().position = new Vector3(gameBgWith / 2 + gameBgWith * 0.1f * 0.7f * 1 * 2 / 3, gameBgHeight - gameBgHeight * 0.1f + gameBgHeight * 0.1f * 2 / 4 - gameBgWith * 0.1f * 0.5f, 0.0f);
        }
        else
        {
            targetCount.GetComponent <RectTransform>().position = new Vector3(Screen.width / 2 + gameBgWith * 0.1f * 0.7f * 1 * 2 / 3, gameBgHeight - gameBgHeight * 0.1f + gameBgHeight * 0.1f * 2 / 4 - gameBgWith * 0.1f * 0.5f, 0.0f);
        }
        editorData.targetTypeObj  = targetGrid;
        editorData.targetCountObj = targetCount;

        //[1.3]设置可用步数
        stepCounts = new GameObject();
        GridUIAttributeManager.GetInstance().stepCounts = stepCounts;
        stepCounts.name = "stepCounts";
        stepCounts.AddComponent <Text>();
        stepCounts.GetComponent <Text>().text      = editorData.stepCounts.ToString();
        stepCounts.GetComponent <Text>().fontSize  = (int)(gameBgWith * 0.1f);
        stepCounts.GetComponent <Text>().fontStyle = FontStyle.Bold;
        stepCounts.GetComponent <Text>().color     = Color.red;
        stepCounts.GetComponent <Text>().font      = songTi;
        stepCounts.transform.SetParent(stepBoard.transform);
        if (Screen.height / Screen.width >= gameBgHeight / gameBgWith)
        {
            stepCounts.GetComponent <RectTransform>().position = new Vector3(gameBgWith - gameBgWith * 0.2f / 2, gameBgHeight - gameBgWith * 0.2f / 2, 0.0f);
        }
        else
        {
            stepCounts.GetComponent <RectTransform>().position = new Vector3(Screen.width / 2 + gameBgWith / 2 - gameBgWith * 0.2f / 2, gameBgHeight - gameBgWith * 0.2f / 2, 0.0f);
        }
        editorData.stepCountsObj = stepCounts;
    }
Beispiel #10
0
    public void InitGameBg()
    {
        //[0]创建UI对象
        GameBackground = new GameObject();
        GridUIAttributeManager.GetInstance().GameBackground = GameBackground;
        GameObject branch = new GameObject();

        targetBoard = new GameObject();
        stepBoard   = new GameObject();

        //[1]给UI对象命名
        GameBackground.name = "gameBackground";
        branch.name         = "branch";
        targetBoard.name    = "targetBoard";
        stepBoard.name      = "stepBoard";

        //[2]添加对象组件
        GameBackground.AddComponent <Image>();
        branch.AddComponent <Image>();
        targetBoard.AddComponent <Image>();
        stepBoard.AddComponent <Image>();

        //[3]设置对象父对象
        GameBackground.GetComponent <RectTransform>().SetParent(mainCanvas.transform);
        branch.GetComponent <RectTransform>().SetParent(GameBackground.transform);
        targetBoard.GetComponent <RectTransform>().SetParent(GameBackground.transform);
        stepBoard.GetComponent <RectTransform>().SetParent(GameBackground.transform);

        //[4]加载UI所需Sprite
        Sprite sprite_gameBackground = new Sprite();
        Sprite sprite_branch         = new Sprite();
        Sprite sprite_targetBoard    = new Sprite();
        Sprite sprite_stepBoard      = new Sprite();

        sprite_gameBackground = Resources.Load("background_04", sprite_gameBackground.GetType()) as Sprite;
        sprite_branch         = Resources.Load("branch", sprite_branch.GetType()) as Sprite;
        sprite_targetBoard    = Resources.Load("target_board", sprite_targetBoard.GetType()) as Sprite;
        sprite_stepBoard      = Resources.Load("stepboard", sprite_stepBoard.GetType()) as Sprite;

        GameBackground.GetComponent <Image>().sprite = sprite_gameBackground;
        branch.GetComponent <Image>().sprite         = sprite_branch;
        targetBoard.GetComponent <Image>().sprite    = sprite_targetBoard;
        stepBoard.GetComponent <Image>().sprite      = sprite_stepBoard;

        //[5]设置对象position和大小
        GameBackground.GetComponent <Image>().SetNativeSize();
        gameBgWith   = GameBackground.GetComponent <RectTransform>().rect.width;
        gameBgHeight = GameBackground.GetComponent <RectTransform>().rect.height;
        //如果屏幕高宽比例大于背景高宽比,则使用屏幕宽度作为背景宽度,则反之
        if (Screen.height / Screen.width >= gameBgHeight / gameBgWith)
        {
            gameBgWith   = Screen.width;
            gameBgHeight = Screen.width * gameBgHeight / gameBgWith;
            GameBackground.GetComponent <RectTransform>().sizeDelta = new Vector2(gameBgWith, gameBgHeight);
            GameBackground.GetComponent <RectTransform>().position  = new Vector3(Screen.width / 2, gameBgHeight / 2, 0.0f);
        }
        else
        {
            gameBgWith   = Screen.height / (gameBgHeight / gameBgWith);
            gameBgHeight = Screen.height;
            GameBackground.GetComponent <RectTransform>().sizeDelta = new Vector2(gameBgWith, gameBgHeight);
            GameBackground.GetComponent <RectTransform>().position  = new Vector3(Screen.width / 2, Screen.height / 2, 0.0f);
        }
        // Debug.Log("gameBackground.position:" + gameBackground.GetComponent<RectTransform>().position);

        branch.GetComponent <RectTransform>().sizeDelta = new Vector2(gameBgWith * 0.75f, gameBgHeight * 0.2f);
        if (Screen.height / Screen.width >= gameBgHeight / gameBgWith)
        {
            branch.GetComponent <RectTransform>().position = new Vector3(gameBgWith * 0.75f / 2, gameBgHeight - gameBgHeight * 0.23f / 2, 0.0f);
        }
        else
        {
            branch.GetComponent <RectTransform>().position = new Vector3(Screen.width / 2 - gameBgWith * (0.5f - 0.75f / 2), gameBgHeight - gameBgHeight * 0.23f / 2, 0.0f);
        }

        targetBoard.GetComponent <RectTransform>().sizeDelta = new Vector2(gameBgWith * 0.18f, gameBgHeight * 0.13f);
        if (Screen.height / Screen.width >= gameBgHeight / gameBgWith)
        {
            targetBoard.GetComponent <RectTransform>().position = new Vector3(gameBgWith / 2, gameBgHeight - gameBgHeight * 0.1f / 2, 0.0f);
        }
        else
        {
            targetBoard.GetComponent <RectTransform>().position = new Vector3(Screen.width / 2, gameBgHeight - gameBgHeight * 0.1f / 2, 0.0f);
        }

        stepBoard.GetComponent <RectTransform>().sizeDelta = new Vector2(gameBgWith * 0.2f, gameBgWith * 0.2f);
        if (Screen.height / Screen.width >= gameBgHeight / gameBgWith)
        {
            stepBoard.GetComponent <RectTransform>().position = new Vector3(gameBgWith - gameBgWith * 0.2f / 2, gameBgHeight - gameBgWith * 0.2f / 2, 0.0f);
        }
        else
        {
            stepBoard.GetComponent <RectTransform>().position = new Vector3(Screen.width / 2 + gameBgWith / 2 - gameBgWith * 0.2f / 2, gameBgHeight - gameBgWith * 0.2f / 2, 0.0f);
        }
    }
Beispiel #11
0
 /// <summary>
 /// 初始化GridUI中的对象和变量
 /// </summary>
 public static void InitGridUIAttribute()
 {
     mGridListManager     = GridUIAttributeManager.GetInstance().gridListManager;
     mGridBaseListManager = GridUIAttributeManager.GetInstance().gridBaseListManager;
     mGrid = GridUIAttributeManager.GetInstance().Grid;
 }