/// <summary> /// places the brick in voxel space and snaps to voxel values /// </summary> /// <param name="brick"></param> /// <param name="position"></param> /// <param name="orientation"></param> public static void PlaceBrick(PhysicsBrick brick, Vector3 position, Vector3 orientation) { Vector3 pos = new Voxel(position).getCenter(); Quaternion rot = Quaternion.LookRotation(orientation); brick.transform.SetPositionAndRotation(pos, rot); }
/// <summary> /// aligns the brick in voxel space, setting position and rotation to the nearest voxel values /// </summary> /// <param name="brick"></param> public static void AlignBrick(PhysicsBrick brick) { Vector3 pos = new Voxel(brick.transform.position).getCenter(); Quaternion rot = Quaternion.LookRotation(brick.GetMajorAxis()); brick.transform.SetPositionAndRotation(pos, rot); }
private void InitBrick(PhysicsBrick brick, int identifier, VoxelReference reference) { brick.SetID(identifier, colorPalette.Colors[identifier]); brick.SetReferenceBrick(reference); BrickUtility.PlaceBrickAbsolute(brick, GetSpawnPosition(identifier), orientation); brick.OnBrickFellDown.AddListener(RespawnBrick); }
private static RecipeBrick[] GetCurrentBricks() { PhysicsBrick[] physicsBricks = Object.FindObjectsOfType <PhysicsBrick>(); RecipeBrick[] recipeBricks = new RecipeBrick[physicsBricks.Length]; for (int i = 0; i < physicsBricks.Length; i++) { PhysicsBrick pBrick = physicsBricks[i]; BrickUtility.AlignBrick(pBrick); RecipeBrick brick = new RecipeBrick(pBrick.GetID(), pBrick.GetVoxels()); recipeBricks[i] = brick; } Debug.Log(recipeBricks.Length + " bricks saved to new recipe."); return(recipeBricks); }
/// <summary> /// places the brick in world space with regular float position values /// </summary> /// <param name="brick"></param> /// <param name="position"></param> /// <param name="orientation"></param> public static void PlaceBrickAbsolute(PhysicsBrick brick, Vector3 position, Vector3 orientation) { Quaternion rot = Quaternion.LookRotation(orientation); brick.transform.SetPositionAndRotation(position, rot); }
private void RespawnBrick(PhysicsBrick brick) { BrickUtility.PlaceBrickAbsolute(brick, GetSpawnPosition(brick.GetID()), orientation); }