当前位置: 首页>>代码示例>>C#>>正文


C# Vector3.Round方法代码示例

本文整理汇总了C#中System.Vector3.Round方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.Round方法的具体用法?C# Vector3.Round怎么用?C# Vector3.Round使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Vector3的用法示例。


在下文中一共展示了Vector3.Round方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RoundTest

        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);
            }
        }
开发者ID:wtfcolt,项目名称:game,代码行数:15,代码来源:Vector3Tests.cs

示例2: MoveCursor

        /// <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();
        }
开发者ID:syeager,项目名称:Space-CUBEs,代码行数:43,代码来源:ConstructionGrid.cs

示例3: RemoveCUBE

        /// <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;
        }
开发者ID:syeager,项目名称:Space-CUBEs,代码行数:89,代码来源:ConstructionGrid.cs

示例4: RotateGrid

 /// <summary>
 /// Rotate the grid.
 /// </summary>
 /// <param name="plane"></param>
 public void RotateGrid(Vector3 plane)
 {
     viewAxis = plane.Round();
     MoveCursor(Vector3.zero);
 }
开发者ID:syeager,项目名称:Space-CUBEs,代码行数:9,代码来源:ConstructionGrid.cs


注:本文中的System.Vector3.Round方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。