public void RoundTest() { const int max = 1000; var r = new Random(578); for (var i = 0; i < 30; i++) { var v = new Vector3(r.NextFloat() * max, r.NextFloat() * max, r.NextFloat() * max); var c = v.Round(); Assert.AreEqual(Math.Round(v.X), c.X); Assert.AreEqual(Math.Round(v.Y), c.Y); Assert.AreEqual(Math.Round(v.Z), c.Z); } }
/// <summary> /// Move the cursor to another cell. /// </summary> /// <param name="vector">Vector to move cursor.</param> public void MoveCursor(Vector3 vector) { // get rid of floating points vector = vector.Round(); // reset last cell to open colorIndex cells[(int)cursor.y][(int)cursor.z][(int)cursor.x].renderer.material = CellOpen_Mat; cells[(int)cursor.y][(int)cursor.z][(int)cursor.x].transform.localScale = Vector3.one * cellSize; // contain new position within grid if (cursor.x + vector.x < 0 || cursor.x + vector.x > size - 1) vector.x = 0; if (cursor.y + vector.y < 0 || cursor.y + vector.y > size - 1) vector.y = 0; if (cursor.z + vector.z < 0 || cursor.z + vector.z > size - 1) vector.z = 0; // move cursor cursor += vector; // set new cursor cell to cursor colorIndex cells[(int)cursor.y][(int)cursor.z][(int)cursor.x].renderer.material = CellCursor_Mat; cells[(int)cursor.y][(int)cursor.z][(int)cursor.x].transform.localScale = Vector3.one * cursorSize; // move currently held CUBE if (heldCUBE != null) { heldCUBE.transform.position += vector; SetStatus(CursorStatuses.Holding); } else if (grid[(int)cursor.y][(int)cursor.z][(int)cursor.x] != null) { // set status to hover SetStatus(CursorStatuses.Hover); } else { // set status to none SetStatus(CursorStatuses.None); } UpdateGrid(); }
/// <summary> /// Remove CUBE from grid and all stats. /// </summary> /// <param name="cube"></param> private void RemoveCUBE(CUBE cube) { // get pivotOffset and rotation cursorRotation = Quaternion.Euler(currentBuild[cube].rotation); cursorOffset = currentBuild[cube].position - cursor; Vector3 pivot = cursor + cursorOffset.Round(); pivot = pivot.Round(); cursorOffset = RotateVector(cursorOffset.Round(), true).Round(); // remove all of CUBE's pieces Vector3 bounds = heldInfo.size; for (int x = 0; x < bounds.x; x++) { for (int y = 0; y < bounds.y; y++) { for (int z = 0; z < bounds.z; z++) { Vector3 point = pivot + RotateVector(new Vector3(x, y, z)).Round(); point = point.Round(); grid[(int)point.y][(int)point.z][(int)point.x] = null; cells[(int)point.y][(int)point.z][(int)point.x].SetActive(true); cells[(int)point.y][(int)point.z][(int)point.x].renderer.material = CellOpen_Mat; } } } // remove weapon if applicable if (heldInfo.type == CUBE.Types.Weapon && weapons.Contains(((Weapon)heldCUBE.GetComponent(typeof(Weapon))))) { int index = currentBuild[heldCUBE].weaponMap; if (index < weaponSlots) { // replace with extra if (weapons.Count > weaponSlots) { weapons[index] = weapons[weaponSlots]; weapons.RemoveAt(weaponSlots); } else { weapons[index] = null; } } else { weapons.RemoveAt(index); } } // remove augmentation if applicable if (heldInfo.type == CUBE.Types.Augmentation && augmentations.Contains((Augmentation)heldCUBE.GetComponent(typeof(Augmentation)))) { int index = currentBuild[heldCUBE].augmentationMap; if (index < augmentationSlots) { // replace with extra if (augmentations.Count > augmentationSlots) { augmentations[index] = augmentations[augmentationSlots]; augmentations.RemoveAt(augmentationSlots); } else { augmentations[index] = null; } } else { augmentations.RemoveAt(index); } } // remove CUBE from current build currentBuild.Remove(cube); // remove stats CUBEInfo cubeInfo = CUBE.AllCUBES[cube.ID]; CurrentStats.health -= cubeInfo.health; CurrentStats.shield -= cubeInfo.shield; CurrentStats.speed -= cubeInfo.speed; CurrentStats.damage -= cubeInfo.damage; CorePointsAvailable += cubeInfo.cost; cells[(int)cursor.y][(int)cursor.z][(int)cursor.x].renderer.material = CellCursor_Mat; }
/// <summary> /// Rotate the grid. /// </summary> /// <param name="plane"></param> public void RotateGrid(Vector3 plane) { viewAxis = plane.Round(); MoveCursor(Vector3.zero); }