public Computer BuildComputer(ComputerDescriptor descriptor, ComputerSizeType size) { Computer computer = ComputerManager.InstantiatePrefab(size); if (computer != null) { bool pieceAdded = false; for (int i = 0; i < descriptor.CPUS; i++) { PieceContainer container = computer.gameObject.AddComponent <PieceContainer>(); container.AllowedPieceTypes.Add(PieceManager.CPU); Piece piece = PieceManager.InstantiatePiece(PieceManager.CPU); piece.Health = 0; container.disablePiece = true; container.AddPiece(piece); computer.PieceContainers.Add(container); pieceAdded = true; } for (int i = 0; i < descriptor.GTX; i++) { PieceContainer container = computer.gameObject.AddComponent <PieceContainer>(); container.AllowedPieceTypes.Add(PieceManager.GTX); Piece piece = PieceManager.InstantiatePiece(PieceManager.GTX); piece.Health = 0; container.disablePiece = true; container.AddPiece(piece); computer.PieceContainers.Add(container); pieceAdded = true; } for (int i = 0; i < descriptor.HDD; i++) { PieceContainer container = computer.gameObject.AddComponent <PieceContainer>(); container.AllowedPieceTypes.Add(PieceManager.HDD); Piece piece = PieceManager.InstantiatePiece(PieceManager.HDD); piece.Health = 0; container.disablePiece = true; container.AddPiece(piece); computer.PieceContainers.Add(container); pieceAdded = true; } for (int i = 0; i < descriptor.PS; i++) { PieceContainer container = computer.gameObject.AddComponent <PieceContainer>(); container.AllowedPieceTypes.Add(PieceManager.PS); Piece piece = PieceManager.InstantiatePiece(PieceManager.PS); piece.Health = 0; container.disablePiece = true; container.AddPiece(piece); computer.PieceContainers.Add(container); pieceAdded = true; } if (!pieceAdded) { PieceContainer container = computer.gameObject.AddComponent <PieceContainer>(); container.AllowedPieceTypes.Add(PieceManager.PS); Piece piece = PieceManager.InstantiatePiece(PieceManager.PS); piece.Health = 0; container.disablePiece = true; container.AddPiece(piece); computer.PieceContainers.Add(container); } } computer.ui.SetIcons(computer.PieceContainers); return(computer); }