private void LayerChange() { LayerController layerController = gameObject.AddComponent <LayerController>(); layerController.SetLayer(this.gameObject, this.gameObject); Destroy(layerController); }
public void PlayerInit(GameObject player) { Transform parent = player.transform; LayerController layerController = gameObject.AddComponent <LayerController>(); GameObject obj = Instantiate(king, parent.transform.TransformPoint(0.5f, -0.25f, -5.5f), parent.rotation, parent); obj.name = "King"; obj = Instantiate(queen, parent.transform.TransformPoint(-0.5f, -0.25f, -5.5f), parent.rotation, parent); obj.name = "Queen"; obj = Instantiate(bishop, parent.transform.TransformPoint(1.5f, -0.25f, -5.5f), parent.rotation, parent); obj.name = "Bishop"; obj = Instantiate(bishop, parent.transform.TransformPoint(-1.5f, -0.25f, -5.5f), parent.rotation, parent); obj.name = "Bishop"; obj = Instantiate(rook, parent.transform.TransformPoint(5.5f, -0.25f, -5.5f), parent.rotation, parent); obj.name = "Rook"; obj = Instantiate(rook, parent.transform.TransformPoint(-5.5f, -0.25f, -5.5f), parent.rotation, parent); obj.name = "Rook"; for (float i = -4.5f; i < 6; i += 2) { obj = Instantiate(archer, parent.transform.TransformPoint(i, -0.25f, -4.5f), parent.rotation, parent); obj.name = "Archer"; } for (float i = -5.5f; i < 6; i += 2) { obj = Instantiate(swordman, parent.transform.TransformPoint(i, -0.25f, -4.5f), parent.rotation, parent); obj.name = "Swordman"; } for (float i = -4.5f; i < -2; i++) { obj = Instantiate(knight, parent.transform.TransformPoint(i, -0.25f, -5.5f), parent.rotation, parent); obj.name = "Knight"; } for (float i = 4.5f; 2 < i; i--) { obj = Instantiate(knight, parent.transform.TransformPoint(i, -0.25f, -5.5f), parent.rotation, parent); obj.name = "Knight"; } layerController.SetLayer(player, player); Destroy(layerController); }
//列移動可能範囲 virtual protected void QueueMovableSS() { int i; bool queueCheck; bool opponentCheck; var parent = playerName.transform; //後方への移動 for (i = nowSquareQueue - 1, queueCheck = true, opponentCheck = true; i >= nowSquareQueue - back; i--) { if (0 <= i && i < 12) { Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(selectedPlayer.transform.localPosition.x, -0.5f, queue[i]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { queueCheck = false; } else { opponentCheck = false; } } if (!queueCheck) { break; } GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(selectedPlayer.transform.localPosition.x, -0.4f, queue[i]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; if (opponentCheck == false) { break; } } } //前方への移動 for (i = nowSquareQueue + 1, queueCheck = true, opponentCheck = true; i <= nowSquareQueue + forward; i++) { if (0 <= i & i < 12) { Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(selectedPlayer.transform.localPosition.x, -0.5f, queue[i]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { queueCheck = false; } else { opponentCheck = false; } } if (!queueCheck) { break; } GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(selectedPlayer.transform.localPosition.x, -0.4f, queue[i]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; if (opponentCheck == false) { break; } } } layerController = gameObject.AddComponent <LayerController>(); foreach (GameObject ss in selectableList) { layerController.SetLayer(parent.gameObject, ss); } Destroy(layerController); }
protected void KnightMovableSS() { var parent = playerName.transform; int i = nowSquareQueue; int ii = nowSquareRow; if (0 <= i + 2 && i + 2 < 12) { if (0 <= ii + 1 && ii + 1 < 12) { bool knightCheck = true; Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(row[ii + 1], -0.5f, queue[i + 2]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { knightCheck = false; } } if (knightCheck) { GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(row[ii + 1], -0.4f, queue[i + 2]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; } } if (0 <= ii - 1 && ii - 1 < 12) { bool knightCheck = true; Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(row[ii - 1], -0.5f, queue[i + 2]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { knightCheck = false; } } if (knightCheck) { GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(row[ii - 1], -0.4f, queue[i + 2]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; } } } if (0 <= i - 2 && i - 2 < 12) { if (0 <= ii + 1 && ii + 1 < 12) { bool knightCheck = true; Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(row[ii + 1], -0.5f, queue[i - 2]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { knightCheck = false; } } if (knightCheck) { GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(row[ii + 1], -0.4f, queue[i - 2]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; } } if (0 <= ii - 1 && ii - 1 < 12) { bool knightCheck = true; Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(row[ii - 1], -0.5f, queue[i - 2]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { knightCheck = false; } } if (knightCheck) { GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(row[ii - 1], -0.4f, queue[i - 2]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; } } } if (0 <= i - 1 && i - 1 < 12) { if (0 <= ii + 2 && ii + 2 < 12) { bool knightCheck = true; Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(row[ii + 2], -0.5f, queue[i - 1]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { knightCheck = false; } } if (knightCheck) { GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(row[ii + 2], -0.4f, queue[i - 1]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; } } if (0 <= ii - 2 && ii - 2 < 12) { bool knightCheck = true; Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(row[ii - 2], -0.5f, queue[i - 1]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent) { knightCheck = false; } } if (knightCheck) { GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(row[ii - 2], -0.4f, queue[i - 1]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; } } } if (0 <= i + 1 && i + 1 < 12) { if (0 <= ii + 2 && ii + 2 < 12) { bool knightCheck = true; Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(row[ii + 2], -0.5f, queue[i + 1]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { knightCheck = false; } } if (knightCheck) { GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(row[ii + 2], -0.4f, queue[i + 1]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; } } if (0 <= ii - 2 && ii - 2 < 12) { bool knightCheck = true; Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(row[ii - 2], -0.5f, queue[i + 1]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { knightCheck = false; } } if (knightCheck) { GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(row[ii - 2], -0.4f, queue[i + 1]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; } } } layerController = gameObject.AddComponent <LayerController>(); foreach (GameObject ss in selectableList) { layerController.SetLayer(parent.gameObject, ss); } Destroy(layerController); }
//斜め移動可能範囲 virtual protected void DiagonalMovableSS() { int i; int ii; bool diagonalCheck; bool opponentCheck; var parent = playerName.transform; //左後方への移動 for (i = nowSquareQueue - 1, ii = nowSquareRow - 1, diagonalCheck = true, opponentCheck = true; i >= nowSquareQueue - diagonal && ii >= nowSquareRow - diagonal; i--, ii--) { if (0 <= i & i < 12 & 0 <= ii & ii < 12) { Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(row[ii], -0.5f, queue[i]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { diagonalCheck = false; } else { opponentCheck = false; } } if (!diagonalCheck) { break; } GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(row[ii], -0.4f, queue[i]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; if (opponentCheck == false) { break; } } } //右後方への移動 for (i = nowSquareQueue - 1, ii = nowSquareRow + 1, diagonalCheck = true, opponentCheck = true; i >= nowSquareQueue - diagonal && ii <= nowSquareRow + diagonal; i--, ii++) { if (0 <= i & i < 12 & 0 <= ii & ii < 12) { Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(row[ii], -0.5f, queue[i]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { diagonalCheck = false; } else { opponentCheck = false; } } if (!diagonalCheck) { break; } GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(row[ii], -0.4f, queue[i]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; if (opponentCheck == false) { break; } } } //左前方への移動 for (i = nowSquareQueue + 1, ii = nowSquareRow - 1, diagonalCheck = true, opponentCheck = true; i <= nowSquareQueue + diagonal && ii >= nowSquareRow - diagonal; i++, ii--) { if (0 <= i & i < 12 & 0 <= ii & ii < 12) { Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(row[ii], -0.5f, queue[i]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { diagonalCheck = false; } else { opponentCheck = false; } } if (!diagonalCheck) { break; } GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(row[ii], -0.4f, queue[i]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; if (opponentCheck == false) { break; } } } //右前方への移動 for (i = nowSquareQueue + 1, ii = nowSquareRow + 1, diagonalCheck = true, opponentCheck = true; i <= nowSquareQueue + diagonal && ii <= nowSquareRow + diagonal; i++, ii++) { if (0 <= i & i < 12 & 0 <= ii & ii < 12) { Collider[] check = Physics.OverlapSphere(parent.transform.TransformPoint(row[ii], -0.5f, queue[i]), 0.1f); foreach (Collider c in check) { if (c.gameObject.transform.parent == parent) { diagonalCheck = false; } else { opponentCheck = false; } } if (!diagonalCheck) { break; } GameObject selectablesquare = (GameObject)Instantiate(selectableSquare, new Vector3(0, 0, 0), rotate); selectablesquare.transform.parent = parent; selectablesquare.transform.rotation = new Quaternion(0, 0, 0, 0); selectablesquare.transform.localPosition = new Vector3(row[ii], -0.4f, queue[i]); selectableList.Add(selectablesquare); selectablesquare.name = selectableSquare.name; if (opponentCheck == false) { break; } } } layerController = gameObject.AddComponent <LayerController>(); foreach (GameObject ss in selectableList) { layerController.SetLayer(parent.gameObject, ss); } Destroy(layerController); }