/// <summary> /// ターンスタート可能か確認する /// </summary> /// <returns></returns> private bool IsAbleTurnStart() { int indexListCnt = 0; List <GameObject> myObjList = myTopStage.GetGameObjectAll(); List <BoardIndex> boardObjList = board.GetMyTopBoardIndex(); foreach (BoardIndex index in boardObjList) { int id = board.GetTopIdByIndex(index); List <BoardIndex> indexList = board.GetMovableIndex(id, index); foreach (BoardIndex index2 in indexList) { indexListCnt++; } } if (myObjList.Count == 0 && indexListCnt == 0) { return(false); } else { return(true); } }
void Update() { //レイを飛ばして当たっていれば移動許可フラグを立てる if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (hit.transform.gameObject == this.gameObject) { movePermitFlg = true; board.DelBoardInf(index); indexies = board.GetMovableIndex(topId, index); prepareSceneManager.CellHighLight(indexies); foreach (BoardIndex index in indexies) { Vector2 tmpVal = board.GetBoardPosByIndex(index); Vector3 tmpVal2 = new Vector3(tmpVal.x, tmpVal.y, -6.85f); } } } } if (Input.GetMouseButton(0)) { if (movePermitFlg) { Vector2 tmpPos = Input.mousePosition; Vector3 pos = Camera.main.WorldToScreenPoint(transform.position); Vector3 a = new Vector3(tmpPos.x, tmpPos.y, pos.z); pos = Camera.main.ScreenToWorldPoint(a); tmpPos = board.GetCellPosByPos(pos, ref index); transform.position = new Vector3(tmpPos.x, tmpPos.y, pos.z); indexies = board.GetMovableIndex(topId, index); prepareSceneManager.CellHighLight(indexies); //持っている間少しでかくする transform.localScale = 1.2f * scale; //位置が下すぎる場合はホバーする if (pos.y < 0.58f) { hideFlg = true; transform.position = pos; } else { hideFlg = false; } } } if (Input.GetMouseButtonUp(0)) { if (movePermitFlg) { //離したら大きさを戻す transform.localScale = scale; //盤面も初期化しておく prepareSceneManager.CellHighLight(new List <BoardIndex>()); //非表示状態のときは削除する if (hideFlg) { //コマをしまった prepareSceneManager.EndOutATop(topId); Destroy(gameObject); } //ドロップ位置が5行目ではない場合は削除する else if (index.yIndex != 5) { //コマをしまった prepareSceneManager.EndOutATop(topId); Destroy(gameObject); } //ドロップ位置にコマがない場合、盤面情報に登録する else if (!board.ChkBoardTop(index)) { prepareSceneManager.PutATop(topId, gameObject, index); } //コマがある場合はそのコマを削除し、上書きする else { int delId = board.GetTopIdByIndex(index); //コマをしまった prepareSceneManager.EndOutATop(delId); GameObject obj = board.DelBoardInf(index); Destroy(obj); prepareSceneManager.PutATop(topId, gameObject, index); } movePermitFlg = false; } } }
// Update is called once per frame void Update() { /* 自分のターンかつ自分のコマのみ移動可能 */ if (!isMyTurn || !isMine) { return; } //レイを飛ばして当たっていれば移動許可フラグを立てる if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (hit.transform.gameObject == this.gameObject) { movePermitFlg = true; befIndex = index; if (isBring) { battleSceneManager.UseATop(index); //空のインデックスをすべて取得する indexies = board.GetEmptyBoardIndex(); } //盤面上のコマを動かしたとき else { board.DelBoardInf(index); //可動インデックスをすべて取得する indexies = board.GetMovableIndex(topId, index); } //取得したインデックスをすべてハイライトする battleSceneManager.CellHighLight(indexies); } } } if (Input.GetMouseButton(0)) { if (movePermitFlg) { inputPos = Input.mousePosition; this.pos = Camera.main.WorldToScreenPoint(transform.position); Vector3 a = new Vector3(inputPos.x, inputPos.y, pos.z); this.pos = Camera.main.ScreenToWorldPoint(a); tmpPos = board.GetCellPosByPos(new Vector2(this.pos.x, this.pos.z), ref index); transform.position = new Vector3(tmpPos.x, 1, tmpPos.y); //持っている間少しでかくする transform.localScale = 1.2f * scale; //範囲外の場合、またはコマを置くことができない場合はセルフィットしない if (this.pos.x < -1.0f || this.pos.x > 1.0f || this.pos.z < -1.0f || this.pos.z > 1.0f) { reverseFlg = true; transform.position = this.pos; } else if (!ChkIsMovableIndex(index)) { reverseFlg = true; transform.position = this.pos; } else { reverseFlg = false; } } } if (Input.GetMouseButtonUp(0)) { if (movePermitFlg) { //離したら大きさを戻す transform.localScale = scale; //盤面のハイライトを初期化しておく battleSceneManager.CellHighLight(new List <BoardIndex>()); //リバース状態のときは元の位置に戻す if (reverseFlg) { index = befIndex; //コマ置き場→盤面 if (isBring) { battleSceneManager.GetATop(gameObject); } //盤面→盤面 else { battleSceneManager.PutATop(topId, gameObject, befIndex); Vector2 tmpVec = board.GetBoardPosByIndex(befIndex); gameObject.transform.position = new Vector3(tmpVec.x, gameObject.transform.position.y, tmpVec.y); } } //ドロップ位置にコマがない場合、盤面情報に登録する else if (!board.ChkBoardTop(index)) { battleSceneManager.PutATop(topId, gameObject, index); //ターンエンド手続き battleSceneManager.TurnEnd(befIndex, index, isBring); //とびがないかチェック(狙撃手はとび確認不要) if (topId != 9) { List <BoardIndex> indexList = board.GetCellIndexBitweenCells(befIndex, index); foreach (BoardIndex index in indexList) { battleSceneManager.PaintCell(index, true); } } battleSceneManager.PaintCell(index, true); //持ち駒を置くことができるのはここのパスのみ if (isBring) { isBring = false; } } //コマがある場合はそのコマを削除し、上書きする else { GameObject obj = board.DelBoardInf(index); battleSceneManager.GetATop(obj); battleSceneManager.PutATop(topId, gameObject, index); //ターンエンド手続き battleSceneManager.TurnEnd(befIndex, index, false); //とびがないかチェック(狙撃手はとび確認不要) if (topId != 9) { List <BoardIndex> indexList = board.GetCellIndexBitweenCells(befIndex, index); foreach (BoardIndex index in indexList) { battleSceneManager.PaintCell(index, true); } } battleSceneManager.PaintCell(index, true); } movePermitFlg = false; } } }