/// <summary> /// Instantiates a blueprint into the game /// </summary> /// <param name="blueprint">The blueprint to instantiate</param> /// <param name="parent">The parent transform of the blueprint</param> /// <returns></returns> public List <GridBlockBase> InstantiateBlueprint(BlueprintModel blueprint, Transform parent) { List <GridBlockBase> blocks = new List <GridBlockBase>(); // Loop over each block in the blueprint foreach (BlueprintBlock blueprintBlock in blueprint.Blocks) { // Instantiate the block by prefab block type try { var block = Instantiate(BlockPrefabProvider.Instance.GetPrefab(blueprintBlock.BlockTypeID)); GridBlockBase blockBase = (GridBlockBase)block.GetComponent(typeof(GridBlockBase)); // Set the parent of the block block.transform.SetParent(parent); // Set the position of the block Vector2 position = GetBlockPosition(blueprintBlock.VectorPosition, blockBase.Size); block.transform.localPosition = new Vector3( position.x, position.y, 0); // Set the rotation of the block block.transform.localRotation = Quaternion.Euler(0f, 0f, blueprintBlock.RotationInDegs); // Add the block to the list blocks.Add(blockBase); } catch (PrefabNotFoundException) { } } return(blocks); }
public BlockPrefab(GameObject prefab, GridBlockBase gridBlockBase) { this.prefab = prefab; this.gridBlockBase = gridBlockBase; }