public void RotatePuzzle() { //Debug.Log("origin pcenter:" + MatrixUtil.PrintIntArray(pcenter)); int[] afterRotateLayout = new int[pwidth * pheight]; for (int i = 0; i < playout.Length; ++i) { int x = i % pwidth; int y = i / pwidth; int arx = pheight - 1 - y; int ary = x; afterRotateLayout[ary * pheight + arx] = playout[i]; } playout = afterRotateLayout; int[] tempPcenter = MatrixUtil.ArrayCopy(pcenter); pcenter = new int[2] { pheight - 1 - tempPcenter[1], tempPcenter[0] }; int temp = pheight; pheight = pwidth; pwidth = temp; //Debug.Log("new pcenter:" + MatrixUtil.PrintIntArray(pcenter)); }
private void SaveOperation() { Recorder rec = operationHistoryRecorder.Recoder; rec.LevelId = levelID; rec.layout = MatrixUtil.ArrayCopy(generalPanelUI.generalPanelData.Playout); // rec.TimeCount = levelTimer.Time; if (!rec.isFilled()) { XPlayerPrefs.DelRec(rec.LevelId); return; } //todo 保存广告格子的个数 XPlayerPrefs.SetRec(rec); }
// Coroutine deleteAreaCorou; // public Coroutine DeleteAreaCorou // { // get { return deleteAreaCorou; } // set { deleteAreaCorou = value; } // } public int InteractWithPuzzle(PuzzleItemUI puzzleItemUI, out int panelGridIndex, out int[] outputBlankLayout) { //关于返回值:0表示拼图在面板中的位置是满足填充条件的位置,可以填充;1表示拼图在面板中,但不满足填充条件;2表示拼图不在面板中,也不在删除区;3表示拼图在删除区 PuzzleItemData puzzleItemData = puzzleItemUI.puzzleItemData; PointerEventData pointerData = new PointerEventData(EventSystem.current); // Debug.Log("grid index of puzzle:" + (puzzleItemData.Pcenter[0] + puzzleItemData.Pwidth * puzzleItemData.Pcenter[1]).ToString());//!Test //!show precheck grid不正确对应的bug发生原因:原本通过centerx和centery寻找下标,实际上并不需要寻找,因为顺序是固定的,下标不改变 pointerData.position = Camera.main.WorldToScreenPoint(puzzleItemUI.transform.GetChild((int)(puzzleItemData.PcenterOrigin)).position); List <RaycastResult> results = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointerData, results); if (results.Count > 0) { //此时results[0]是当前拼图上的格子,results[...]才是底下的东西 //如果射到的是格子,其父对象必为当前脚本挂载的对象,即GeneralPanel面板 GameObject hitObj = results.Find((RaycastResult a) => a.gameObject.transform.parent == this.transform).gameObject; if (hitObj != null) { int gridIndex = hitObj.transform.GetSiblingIndex(); int[] blankLayout; bool isFit = generalPanelData.IsFit(puzzleItemData, gridIndex, out blankLayout); panelGridIndex = gridIndex; outputBlankLayout = MatrixUtil.ArrayCopy(blankLayout); onDeleteAreaFlag = false; //TODO:deleteArea缩小为1 StartCoroutine(DeleteAreaLinearScaleDown()); if (isFit) { return(0); } else { return(1); } } // 输出射线射到的所有对象: // string allhit = "hit:::\n"; // foreach (RaycastResult r in results) // { // allhit += r.gameObject.name + "\n"; // } // Debug.Log(allhit); if (DetectDeleteArea(puzzleItemUI)) { panelGridIndex = -1; outputBlankLayout = null; return(3); } } panelGridIndex = -1; outputBlankLayout = null; return(2); }
//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)); } } }
public void InitGeneralPanelData(bool isReGen = false) { //将数据读入,获得面板的长度和宽度(两个方向的格子数量),以及将面板基础格子的信息保存进一个一维int数组 //FINISH:读入数据,获取面板的宽度和长度 uint curLevelID = LevelMgr.GetInstance().CurLevelID; //Debug.Log("id = " + curLevelID); LevelData curLevelData = LevelMgr.GetInstance().GetLevelConfig(curLevelID); //插入逻辑判断是否有存档,有的话就直接读取,返回 if (isReGen) { Recorder rec = XPlayerPrefs.GetRec(curLevelID); pwidth = curLevelData.Map.MapWidth + 2; pheight = curLevelData.Map.MapHeight + 2; //保存数据进一个一维int数组 playout = MatrixUtil.ArrayCopy(rec.layout); } else if (curLevelData == null || curLevelData.Map == null || curLevelID == 0) { Debug.Log("Sim"); //!模拟读入长宽 pwidth = 15; pheight = 15; //!模拟读入一个一维数组 playout = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; } else { pwidth = curLevelData.Map.MapWidth + 2; pheight = curLevelData.Map.MapHeight + 2; //保存数据进一个一维int数组 int[] tempLayout = curLevelData.Map.MapArray; playout = new int[pwidth * pheight]; // FINISH:扩充int数组的边界 // UPDATE for (int i = 0; i < playout.Length; ++i) { int x = i % (pwidth); int y = i / (pwidth); if (x != 0 && x != pwidth - 1 && y != 0 && y != pheight - 1) { playout[y * (pwidth) + x] = tempLayout[(y - 1) * (pwidth - 2) + (x - 1)]; } else { playout[y * (pwidth) + x] = (int)GridType.Non; } } // pwidth = curLevelData.Map.MapWidth; // pheight = curLevelData.Map.MapHeight; // playout = MatrixUtil.ArrayCopy(curLevelData.Map.MapArray); } }