private void Awake() { foreach (PieceConnections pc in connections) { PieceLocation loc = pc.getLocation(); if (loc == PieceLocation.NORTH) { pc.setPieceId(pieceNumber - 4); } if (loc == PieceLocation.SOUTH) { pc.setPieceId(pieceNumber + 4); } if (loc == PieceLocation.EAST) { pc.setPieceId(pieceNumber + 1); } if (loc == PieceLocation.WEST) { pc.setPieceId(pieceNumber - 1); } //Debug.Log("Piece " + this.name +" has connection to: " + pc.getPieceId ()); } }
private GameObject GetPieceFromPieceTable(PieceLocation location, string pieceName) { PieceTable pieceTable = GetPieceTable(location); int currentPosition = pieceTable.m_pieces.FindIndex(piece => piece.name == pieceName); if (currentPosition >= 0) { logger.LogInfo("Found Piece " + pieceName + " at position " + currentPosition); GameObject @object = pieceTable.m_pieces[currentPosition]; pieceTable.m_pieces.RemoveAt(currentPosition); return(@object); } return(null); }
public List<PieceLocation> DeserializePieces (string json) { List<PieceLocation> pieces_list = new List<PieceLocation> (); SerializablePieceLocation[] sp_array = LitJson.JsonMapper.ToObject<SerializablePieceLocation[]> (json); foreach (SerializablePieceLocation spl in sp_array) { PieceLocation p = new PieceLocation (); p.parseSerializable (spl); p.piece = (GameObject)Instantiate (Resources.Load (spl.piece_name), p.position, p.rotation); pieces_list.Add (p); } return pieces_list; }
private PieceTable GetPieceTable(PieceLocation location) { string pieceTableName = $"_{location}PieceTable"; Object[] array = Resources.FindObjectsOfTypeAll(typeof(PieceTable)); for (int i = 0; i < array.Length; i++) { PieceTable pieceTable = (PieceTable)array[i]; string name = pieceTable.gameObject.name; if (pieceTableName == name) { return(pieceTable); } } return(null); }
public void InstantiatePiece (GameObject prefab) { Vector3 finalPos = Camera.mainCamera.ScreenToWorldPoint (Input.mousePosition); finalPos.z = 0; int x = (int)(finalPos.x / 16) * 16; int y = (int)(finalPos.y / 16) * 16; finalPos.x = x; finalPos.y = y; if (!isPositionOccupied (finalPos)) { Debug.Log ("world pos:" + finalPos); if (prefab != null) { GameObject p = (GameObject)Instantiate (prefab, finalPos, Quaternion.identity); p.rigidbody2D.isKinematic = true; PieceLocation pl = new PieceLocation (); pl.piece = p; pl.position = finalPos; pieces.Add (pl); } } }