本文整理汇总了C#中Piece.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Piece.GetComponent方法的具体用法?C# Piece.GetComponent怎么用?C# Piece.GetComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piece
的用法示例。
在下文中一共展示了Piece.GetComponent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public void Init(Piece piece)
{
if (!IsShowing)
return;
Sprite promoted = piece.GetPromotedSprite ();
RectTransform rect;
Image image = piece.GetComponent<Image> ();
Sprite cancel = image.sprite;
image = promoteButton.GetComponent<Image> ();
image.sprite = promoted;
if (!piece.Owner.IsFirst) {
rect = promoteButton.GetComponent<RectTransform> ();
rect.Rotate (0, 0, 180f);
}
image = cancelButton.GetComponent<Image> ();
image.sprite = cancel;
if (!piece.Owner.IsFirst) {
rect = cancelButton.GetComponent<RectTransform> ();
rect.Rotate (0, 0, 180f);
}
promoteButton.onClick.RemoveAllListeners ();
promoteButton.onClick.AddListener (() => {
piece.Promote ();
Close ();
});
cancelButton.onClick.RemoveAllListeners ();
cancelButton.onClick.AddListener (() => this.Close ());
gameObject.SetActive (true);
}
示例2: OnPieceTouch
private void OnPieceTouch(Piece currentPiece, string id)
{
//Debug.Log("PositionOnBoard: " + currentPiece.tile.posOnBoard);
MeshRenderer mrCurrent = currentPiece.GetComponent<MeshRenderer>();
string selectedPieceColor = mrCurrent.material.color.ToHexStringRGB();
Debug.Log("currentPiece-> color: " + currentPiece.color + " size: " + currentPiece.size + " symbol: " + currentPiece.symbol);
if(selectedPiece != null)
{
if(currentPiece.MeetsPreconditions(selectedPiece)){
//Debug.Log("MeetsPreconditions...");
if(IsValidMove(currentPiece)){
/***if level = hard ****
MakeMovement(selectedPiece, currentPiece.tile);
MeshRenderer mr = selectedPiece.GetComponent<MeshRenderer>();
mr.material = currentMaterial;
*/
//if level = easy
MakeMovementPath(currentPiece.tile);
}
}
}
else
{
if(selectedPieceColor.Equals(activeBoardColor)){
if(currentPiece.MeetsPreconditions(selectedPiece))
{
selectedPiece = currentPiece;
initialPieceTile = currentPiece.tile;
initialPiece = currentPiece;
/* Set piece transparency*/
selectedPiece.SetSelectionTransparency();
MeshRenderer mr = selectedPiece.GetComponent<MeshRenderer>();
currentMaterial = mr.material;
/* Set selected color to piece*/
/*MeshRenderer mr = selectedPiece.GetComponent<MeshRenderer>();
currentMaterial = mr.material;
mr.material = Resources.Load("Material/OriginalTheme/selected") as Material;*/
}
}
}
}
示例3: GenerateBoard
void GenerateBoard()
{
Quaternion rotation = new Quaternion();
int n = 0;
RectTransform containerRectTransform = GameObject.Find("GameBoard").GetComponent<RectTransform>();
rotation.eulerAngles = new Vector3(ROTATION_X, ROTATION_Y, ROTATION_Z);
gameBoard.tiles = new List<Tile>();
remainingPieces = new List<Material>(allPieces.GetRange(0,30));
remainingRepetedPieces = new List<Material>(allPieces.GetRange(31,9));
int posOnBoard = 1;
for(int i = 1; i < positionXY.Count-1; i++)
{
for(int j = 1; j < positionXY[i].Count-1; j++)
{
tile = ((GameObject)Instantiate(tilePrefab, positionXY[i][j], rotation)).GetComponent<Tile>();
tile.id = "Tile_" + i + "_" + j;
tile.gameObject.name = "Tile_" + i + "_" + j;
tile.posX = i;
tile.posY = j;
tile.tileHeight = 1;
tile.posOnBoard = posOnBoard;
tile.TileTouch += OnTileTouch;
posOnBoard++;
//Add Pieces to tile
//AddPiecesToTile(tile, i, j, false);
///////////////////// implementado en el método AddPiecesToTile()/////////
//Vector3 initialPos = new Vector3(0.0f, 0.0f, -0.3f); //Piece prefab
Vector3 initialPos = new Vector3(0.0f, -0.3f, 0.0f);
piece = ((GameObject)Instantiate(piecePrefab, initialPos, Quaternion.identity)).GetComponent<Piece>();
piece.id = "Piece_" + i + "_" + j;
piece.gameObject.name = "Piece_" + i + "_" + j;
MeshRenderer mr = piece.GetComponent<MeshRenderer>();
if(remainingPieces.Count > 0){
n = UnityEngine.Random.Range(0, remainingPieces.Count);
mr.material = remainingPieces[n];
remainingPieces.RemoveAt(n);
}else{
n = UnityEngine.Random.Range(0, remainingRepetedPieces.Count-4);
mr.material = remainingRepetedPieces[n];
remainingRepetedPieces.RemoveAt(n);
}
string[] properties = mr.material.name.Split('_');
piece.size = properties[0];
piece.color = properties[1];
piece.symbol = properties[2];
piece.tile = tile;
piece.PieceTouch += OnPieceTouch;
//Debug.Log("Piece color: "+ piece.color + " symbol: " + piece.symbol + " size: " + piece.size + "pos(x,y) " + "(" + piece.tile.posX + "," + piece.tile.posY + ")");
tile.pieces.Add(piece);
piece.transform.SetParent(tile.transform, false);
////////////////////////////////////////////////////////////////////////
tile.transform.SetParent(containerRectTransform.transform, false);
gameBoard.tiles.Add(tile);
}
}
//Make a for operator until player count
GeneratePlayerHomeTile(1, containerRectTransform.transform, rotation);
GeneratePlayerHomeTile(2, containerRectTransform.transform, rotation);
}
示例4: AddPiecesToHomeTile
private Tile AddPiecesToHomeTile(Tile currentTile, int i, int j, bool isPlayerHome)
{
//Vector3 initialPos = new Vector3(0.0f, 0.0f, -0.3f);
Vector3 initialPos = new Vector3(0.0f, -0.3f, 0.0f);
Quaternion rotation = new Quaternion();
currentTile.pieces = new List<Piece>();
piece = ((GameObject)Instantiate(piecePrefab, initialPos, rotation)).GetComponent<Piece>();
piece.id = "Piece_" + i + "_" + j;
piece.gameObject.name = "Piece_" + i + "_" + j;
piece.tile = currentTile;
MeshRenderer mr = piece.GetComponent<MeshRenderer>();
int n = UnityEngine.Random.Range(0,remainingRepetedPieces.Count);
mr.material = remainingRepetedPieces[n];
remainingRepetedPieces.RemoveAt(n);
string[] properties = mr.material.name.Split('_');
piece.size = properties[0];
piece.color = properties[1];
piece.symbol = properties[2];
piece.PieceTouch += OnPieceTouch;
currentTile.pieces.Add(piece);
if(isPlayerHome)
piece.isHome = true;
else
piece.isHome = false;
piece.transform.SetParent(currentTile.transform, false);
return currentTile;
}
示例5: SelectPiece
public void SelectPiece(Piece piece)
{
this.StopParticlesAnimation();
foreach (Transform child in transform) {
Behaviour otherHalo = child.gameObject.GetComponent("Halo") as Behaviour;
if(otherHalo == null)
continue;
otherHalo.enabled = false;
}
Behaviour halo = piece.GetComponent("Halo") as Behaviour;
halo.enabled = true;
selectedObject = pieceObjects [piece.name];
selectedPiece = piece;
int[][] availablePositionList = selectedObject.GetAvailableListToGo ();
for(int i = 0; i < availablePositionList.Length; i++){
ParticleSystem pSystem = GameObject.Find ("light_" + availablePositionList[i][0] + "/" + availablePositionList[i][1])
.GetComponentInChildren<ParticleSystem>();
if(pSystem == null) continue;
pSystem.Play();
}
}
示例6: DeselectPiece
public void DeselectPiece(Piece piece)
{
Behaviour halo = piece.GetComponent("Halo") as Behaviour;
halo.enabled = false;
selectedObject = null;
selectedPiece = null;
this.StopParticlesAnimation ();
}