Exemple #1
0
    private static void GenGrid(ToolMapArray config)
    {
        int total = config.FillTypeMap[m_StrSelect].Length;

        list.Clear();
        Rect rec = new Rect(50f, 150f, CellSize, CellSize);

        for (int i = 1; i <= total; i++)
        {
            list.Add(rec);
            if (i % config.WidthMap[m_StrSelect] == 0)
            {
                rec.y += (CellSize + CellOffset);
                rec.x  = rect.x;
            }
            else
            {
                rec.x += (CellSize + CellOffset);
            }
        }
    }
Exemple #2
0
    private static void OnTopTool2(MapEditor wind)
    {
        ToolMapArray tool = wind.Level_Data.Tools;

        GUILayout.BeginHorizontal();
        if (isAddMode)
        {
            bool isadd = GUILayout.Button("确定", GUILayout.Width(75));
            GUILayout.Label("格子数目", GUILayout.Width(75));
            tempSttr = GUILayout.TextField(tempSttr, GUILayout.Width(75));
            if (isadd)
            {
                int length = int.Parse(tempSttr);
                tool.SetTypeLength(length);
                isAddMode = false;
            }
        }
        if (!isAddMode)
        {
            if (GUILayout.Button("添加", GUILayout.Width(75)))
            {
                tempSttr  = tool.Length.ToString();
                isAddMode = true;
            }
            if (tool.Length == 0)
            {
                GUILayout.Label("需要添加工具格子", GUILayout.Width(100));
            }
            else
            {
                m_SelectIndex = (byte)EditorGUILayout.Popup(m_SelectIndex, tool.FillTypeArray, GUILayout.Width(100));
                if (isdirty)
                {
                    GenGrid(tool);
                    isdirty = false;
                }
            }
        }
        GUILayout.EndHorizontal();
    }
Exemple #3
0
    //private bool adPuzzleUseFlag = false;//没有用于实际判断,暂时注释


    public void InitPuzzleBar()
    {
        //FINISH:读入数据,获得界面下方的PuzzlePanel中要放的拼图的种类的信息
        uint      curLevelID   = LevelMgr.GetInstance().CurLevelID;
        LevelData curLevelData = LevelMgr.GetInstance().GetLevelConfig(curLevelID);

        Dictionary <string, int[]> FillTypeMap = new Dictionary <string, int[]>();
        Dictionary <string, int>   WidthMap    = new Dictionary <string, int>();

        Google.Protobuf.Collections.RepeatedField <string> usablePuzzleStrList = new Google.Protobuf.Collections.RepeatedField <string>();
        int adPuzzleAvailFlagInt = 0;

        if (curLevelData == null || curLevelData.Config == null)
        {
            //!模拟读入
            FillTypeMap = new Dictionary <string, int[]>()
            {
                { "0", new int[] { 0, 0, 1, 1, 1, 1 } },
                { "1", new int[] { 1, 1 } },
                { "2", new int[] { 1, 1, 0, 0 } },
                { "3", new int[] { 1 } },
            };

            WidthMap = new Dictionary <string, int>()
            {
                { "0", 3 },
                { "1", 2 },
                { "2", 2 },
                { "3", 1 },
            };
            usablePuzzleStrList = new Google.Protobuf.Collections.RepeatedField <string>()
            {
                "0", "1", "3"
            };
            adPuzzleAvailFlagInt = 1;
        }
        else
        {
            ToolMapArray toolMapArray = LevelMgr.GetInstance().GetToolMapArray();
            FillTypeMap          = toolMapArray.FillTypeMap;
            WidthMap             = toolMapArray.WidthMap;
            usablePuzzleStrList  = curLevelData.Config.LevelPixel;
            adPuzzleAvailFlagInt = curLevelData.Config.AdPuzzle;
        }



        //Debug.Log("usablePuzzleStrList.Count" + usablePuzzleStrList.Count);
        //FINISH:读入数据后,根据数据生成相应的若干PuzzleItem
        int i = 0;

        foreach (string usablePuzzleStr in usablePuzzleStrList)
        {
            int[] usablePuzzleLayout = new int[] { };
            if (FillTypeMap.TryGetValue(usablePuzzleStr, out usablePuzzleLayout))
            {
                int[] puzzleLayout = MatrixUtil.ArrayCopy(usablePuzzleLayout);

                int puzzleWidth = WidthMap[usablePuzzleStr];

                int puzzleHeight = puzzleLayout.Length / puzzleWidth;

                int puzzleCenterX = 0;
                int puzzleCenterY = 0;

                float puzzleCenterXFloor = Mathf.Floor((float)puzzleWidth / 2.0f);
                float puzzleCenterYFloor = Mathf.Floor((float)puzzleHeight / 2.0f);
                if ((float)puzzleWidth / 2.0f - puzzleCenterXFloor > 0.9f)
                {
                    puzzleCenterX = (int)puzzleCenterXFloor + 1;
                }
                else
                {
                    puzzleCenterX = (int)puzzleCenterXFloor;
                }
                if ((float)puzzleHeight / 2.0f - puzzleCenterYFloor > 0.9f)
                {
                    puzzleCenterY = (int)puzzleCenterYFloor + 1;
                }
                else
                {
                    puzzleCenterY = (int)puzzleCenterYFloor;
                }
                // Debug.Log("puzzleCenterX" + puzzleCenterX);
                // Debug.Log("puzzleCenterY" + puzzleCenterY);


                int[] puzzleCenter = new int[2] {
                    puzzleCenterX, puzzleCenterY
                };

                GameObject   puzzleItem   = GameObject.Instantiate(puzzleItemPrefab, this.transform);
                PuzzleItemUI puzzleItemUI = puzzleItem.GetComponent <PuzzleItemUI>();
                // puzzleItemUIList.Add(puzzleItemUI);
                // puzzleItemUI.InitComp(playFieldCamera, generalPanelUI, puzzleMoveTrans, dragControlMgr, canvasScaler);
                puzzleItemUI.InitComp(generalPanelUI, puzzleMoveTrans, dragController);
                puzzleItemUI.puzzleItemData.InitButtomPuzzleItemData(i, puzzleWidth, puzzleHeight, puzzleLayout, puzzleCenter);
                puzzleItemUI.InitButtomPuzzleItemUI();
                puzzleItemUI.ScaleRatioOfPanelGrid = scaleRatioOfPanelGrid;
                i++;
            }
            else
            {
                Debug.Log("NOT usablePuzzstr:" + usablePuzzleStr);
            }
        }

        //TODO:判断是否可用广告方块
        if (adPuzzleAvailFlagInt == 0)
        {
            //不可用广告方块
            if (puzzleBarForFreeLayoutTrans.childCount > 0)
            {
                Transform adButtonTrans = puzzleBarForFreeLayoutTrans.GetChild(0);
                adButtonTrans.gameObject.SetActive(false);
            }
        }
        else//adPuzzleAvailFlagInt==1
        {
            //可用广告方块
            //TODO:添加广告方块
            GameObject adPuzzle = AddAdPuzzle();
            //TODO:添加看广告按钮
            Transform adButtonTrans;
            if (puzzleBarForFreeLayoutTrans.childCount > 0)
            {
                adButtonTrans = puzzleBarForFreeLayoutTrans.GetChild(0);
            }
            else
            {
                GameObject adButton = GameObject.Instantiate(adButtonPrefab, puzzleBarForFreeLayoutTrans);
                adButtonTrans = adButton.transform;
            }
            //添加判断是否已经付费去广告
            if (XPlayerPrefs.GetInt(AdMgr.Pay2RemoveAD_Tag) == 1)
            {
                adButtonTrans.gameObject.SetActive(false);
                if (adPuzzleNum == 1)
                {
                    Transform      adPuzzleTrans = this.transform.GetChild(this.transform.childCount - 1);
                    PuzzleItemUI   adPuzzleUI    = adPuzzleTrans.GetComponent <PuzzleItemUI>();
                    PuzzleItemData adPuzzleData  = adPuzzleUI.puzzleItemData;
                    adPuzzleData.Plockstate = false;
                }
            }
            else
            {
                //TODO:设置按钮的方法
                Button adButtonComp = adButtonTrans.GetComponent <Button>();
                adButtonComp.onClick.RemoveAllListeners();
                adButtonComp.onClick.AddListener(() =>
                {
                    UnlockAdPuzzle();
                });

                //TODO:设置按钮位置,在协程中等待到当前帧的fixedupdate时进行,原因是adPuzzle的位置受horizontalLayout的影响会在fixedupdate时才生效
                StartCoroutine(SetAdButtonPos(adButtonTrans, adPuzzle));
            }
        }
    }
Exemple #4
0
    private static void OnTopTool(MapEditor wind)
    {
        Init(wind);
        ToolMapArray config = wind.Level_Data.Tools;

        GUILayout.BeginHorizontal();
        if (isEdit)
        {
            isEdit = !GUILayout.Button("确认", GUILayout.Width(50));
            GenGrid(config);
        }
        else
        {
            isEdit = GUILayout.Button("编辑", GUILayout.Width(50));
        }
        if (isEdit)
        {
            int owidth  = config.WidthMap[m_StrSelect];
            int oheight = config.FillTypeMap[m_StrSelect].Length / owidth;

            GUILayout.Label("宽度:", GUILayout.Width(50));
            string tempx  = GUILayout.TextField(owidth.ToString(), GUILayout.Width(50));
            int    fwidth = int.Parse(tempx);
            config.WidthMap[m_StrSelect] = fwidth;
            GUILayout.Space(10f);

            GUILayout.Label("高度:", GUILayout.Width(50));
            tempx = GUILayout.TextField(oheight.ToString(), GUILayout.Width(50));
            int fheight = int.Parse(tempx);
            GUILayout.Space(10f);

            config.FitArray(owidth, oheight, fwidth, fheight, m_StrSelect);

            GUILayout.Label("格子大小:", GUILayout.Width(50));
            tempx    = GUILayout.TextField(CellSize.ToString(), GUILayout.Width(50));
            CellSize = int.Parse(tempx);
            GUILayout.Label("间距:", GUILayout.Width(50));
            tempx      = GUILayout.TextField(CellOffset.ToString(), GUILayout.Width(50));
            CellOffset = int.Parse(tempx);
        }
        else
        {
            int width  = config.WidthMap[m_StrSelect];
            int height = config.FillTypeMap[m_StrSelect].Length / width;
            GUILayout.Label("宽度:", GUILayout.Width(50));
            GUILayout.Label("" + width, GUILayout.Width(50));
            GUILayout.Space(10f);
            GUILayout.Label("高度:", GUILayout.Width(50));
            GUILayout.Label("" + height, GUILayout.Width(50));
        }



        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("生成"))
        {
            GenGrid(config);
        }
        if (GUILayout.Button("读取底图"))
        {
            MapEditor.BgTexture = EditorTool.LoadTexture();
        }
        if (GUILayout.Button("保存"))
        {
            wind.SaveEdit();
        }
        if (GUILayout.Button("返回总览"))
        {
            IsInit        = false;
            wind.Pagetype = MapEditor.PageType.Total;
            return;
        }
        if (!isShowbg && GUILayout.Button("显示底图"))
        {
            isShowbg = true;
        }
        if (isShowbg && GUILayout.Button("显示网格"))
        {
            isShowbg = false;
        }
        GUILayout.EndHorizontal();
    }