private void Update() { if (!clickFlg) { return; } /* 上方向のマウス移動が一定以上であればコマを生成する */ if (nowPos.y - initPos.y > 10) { clickFlg = false; //コマを生成 GameObject itemObj = Instantiate(itemPref); Material[] mats = itemObj.GetComponent <MeshRenderer>().materials; mats[0] = Resources.Load <Material>("Materials/" + topTableList.Find(topTable => topTable.Id == topId).AssetName); itemObj.GetComponent <MeshRenderer>().materials = mats; PrepareTopCtrl prepareTopCtrl = itemObj.GetComponent <PrepareTopCtrl>(); prepareTopCtrl.topId = topId; prepareTopCtrl.movePermitFlg = true; //Viewportのスクロールを停止する gameObject.transform.parent.parent.parent.GetComponent <ScrollRect>().horizontal = false; } /* 横方向のマウス移動が一定以上であればコマを生成できないようにする */ if (Mathf.Abs(nowPos.x - initPos.x) > 20) { clickFlg = false; } }
private GameObject[,] yellowCellObj; /* 黄色いセル */ void Start() { /* 変数初期化 */ List <TopTable> topTableList = new List <TopTable>(); GameManager.Instance.RefTopTableList(ref topTableList); /* 初期情報登録 */ topDic = GameManager.Instance.GetPossessingTops(); GameManager.Instance.RefTopAlignInfo(ref topArignInfo); board = new ShogiBoard(GameDef.BOARD_CELLS, shogiBoard.transform.position); topCntText = new Text[topTableList.Count + 1]; redCellObj = new GameObject[GameDef.BOARD_CELLS + 1, GameDef.BOARD_CELLS + 1]; yellowCellObj = new GameObject[GameDef.BOARD_CELLS + 1, GameDef.BOARD_CELLS + 1]; /* ロードリソース */ GameObject image = Resources.Load <GameObject>("GameObjects/Image"); GameObject itemPref = Resources.Load <GameObject>("GameObjects/PrepareScene/Tops/Top"); GameObject topCntTextObj = Resources.Load <GameObject>("UI/Text"); GameObject redCellPref = Resources.Load <GameObject>("GameObjects/PrepareScene/RedCellObject"); GameObject yellowCellPref = Resources.Load <GameObject>("GameObjects/PrepareScene/YellowCellObject"); /* 所持コマ情報をもとにScrollViewにコマを格納する */ foreach (TopTable top in topTableList) { //所持コマ0個の場合はimageを生成しない if (topDic[top.Id] == 0) { continue; } //imageを生成する GameObject tmp = Instantiate(image); Sprite itemSprite = Resources.Load <Sprite>("Images/" + top.AssetName); tmp.GetComponent <Image>().sprite = itemSprite; tmp.transform.SetParent(content); tmp.transform.localPosition = new Vector3(tmp.transform.position.x, tmp.transform.position.y, 0); tmp.transform.localScale = new Vector3(1, 1, 1); tmp.AddComponent <ContentClickListener>().topId = top.Id; //textを生成する GameObject tmpTextObj = Instantiate(topCntTextObj); topCntText[top.Id] = tmpTextObj.GetComponent <Text>(); tmpTextObj.transform.SetParent(tmp.transform); tmpTextObj.transform.localScale = new Vector3(1, 1, 1); tmpTextObj.GetComponent <RectTransform>().anchoredPosition3D = new Vector3(0, 7.6f, 0); topCntText[top.Id].text = "× " + topDic[top.Id]; } /* コマ配置情報をもとにコマを再配置する */ for (int i = 1; i <= GameDef.BOARD_CELLS; i++) { if (topArignInfo[i] == 0) { continue; } GameObject top = Instantiate(itemPref); //マテリアル設定 Material[] mats = top.GetComponent <MeshRenderer>().materials; mats[0] = Resources.Load <Material>("Materials/" + topTableList.Find(topTable => topTable.Id == topArignInfo[i]).AssetName); top.GetComponent <MeshRenderer>().materials = mats; BoardIndex index = new BoardIndex(i, GameDef.BOARD_CELLS); Vector2 tmpVec = board.GetBoardPosByIndex(index); top.transform.position = new Vector3(tmpVec.x, tmpVec.y, -6.85f); PrepareTopCtrl prepareTopCtrl = top.GetComponent <PrepareTopCtrl>(); prepareTopCtrl.topId = topArignInfo[i]; prepareTopCtrl.movePermitFlg = false; prepareTopCtrl.SetTopIndex(index); board.SetBoardInf(topArignInfo[i], top, true, index); } /* カラーセルを配置する */ for (int i = 1; i <= GameDef.BOARD_CELLS; i++) { for (int j = 1; j <= GameDef.BOARD_CELLS; j++) { BoardIndex index = new BoardIndex(i, j); Vector2 tmpVal = board.GetBoardPosByIndex(index); Vector3 tmpVal2 = new Vector3(tmpVal.x, tmpVal.y, -6.85f); //色付きセル(黄色、赤)を配置する GameObject redCell = Instantiate(redCellPref, tmpVal2, Quaternion.identity); redCellObj[i, j] = redCell; GameObject yellowCell = Instantiate(yellowCellPref, tmpVal2, Quaternion.identity); yellowCellObj[i, j] = yellowCell; //赤セルのみを少し下げておく redCellObj[i, j].transform.position = new Vector3(redCellObj[i, j].transform.position.x, redCellObj[i, j].transform.position.y, -6.0f); } } }