CeilToInt() public static method

public static CeilToInt ( float f ) : int
f float
return int
示例#1
0
    void FixedUpdate()
    {
        if (IsRunning)
        {
            if (curCount > 0.0f)
            {
                curCount -= Time.fixedDeltaTime;
                StepEvent?.Invoke(curCount);

                if (lastIntCount > Mathf.CeilToInt(curCount))
                {
                    lastIntCount = Mathf.CeilToInt(curCount);
                    WholeStepEvent?.Invoke(lastIntCount);
                }
            }
            else
            {
                curCount  = 0.0f;
                IsRunning = false;
                FinishedEvent?.Invoke();
            }

            UpdateText();
        }
    }
        /** Requests an update to all tiles which touch the specified bounds */
        public void ScheduleUpdate(Bounds bounds)
        {
            if (graph == null)
            {
                // If no graph has been set, use the first graph available
                if (AstarPath.active != null)
                {
                    SetGraph(AstarPath.active.data.recastGraph);
                }

                if (graph == null)
                {
                    Debug.LogError("Received tile update request (from RecastTileUpdate), but no RecastGraph could be found to handle it");
                    return;
                }
            }

            // Make sure that tiles which do not strictly
            // contain this bounds object but which still
            // might need to be updated are actually updated
            int voxelCharacterRadius = Mathf.CeilToInt(graph.characterRadius / graph.cellSize);
            int borderSize           = voxelCharacterRadius + 3;

            // Expand borderSize voxels on each side
            bounds.Expand(new Vector3(borderSize, 0, borderSize) * graph.cellSize * 2);

            var touching = graph.GetTouchingTiles(bounds);

            if (touching.Width * touching.Height > 0)
            {
                if (!anyDirtyTiles)
                {
                    earliestDirty = Time.time;
                    anyDirtyTiles = true;
                }

                for (int z = touching.ymin; z <= touching.ymax; z++)
                {
                    for (int x = touching.xmin; x <= touching.xmax; x++)
                    {
                        dirtyTiles[z * graph.tileXCount + x] = true;
                    }
                }
            }
        }
示例#3
0
        void GenerateTerrainChunks(Terrain terrain, Bounds bounds, float desiredChunkSize, List <RasterizationMesh> result)
        {
            var terrainData = terrain.terrainData;

            if (terrainData == null)
            {
                throw new System.ArgumentException("Terrain contains no terrain data");
            }

            Vector3 offset = terrain.GetPosition();
            Vector3 center = offset + terrainData.size * 0.5F;

            // Figure out the bounds of the terrain in world space
            var terrainBounds = new Bounds(center, terrainData.size);

            // Only include terrains which intersects the graph
            if (!terrainBounds.Intersects(bounds))
            {
                return;
            }

            // Original heightmap size
            int heightmapWidth = terrainData.heightmapWidth;
            int heightmapDepth = terrainData.heightmapHeight;

            // Sample the terrain heightmap
            float[, ] heights = terrainData.GetHeights(0, 0, heightmapWidth, heightmapDepth);

            Vector3 sampleSize = terrainData.heightmapScale;

            sampleSize.y = terrainData.size.y;

            // Make chunks at least 12 quads wide
            // since too small chunks just decreases performance due
            // to the overhead of checking for bounds and similar things
            const int MinChunkSize = 12;

            // Find the number of samples along each edge that corresponds to a world size of desiredChunkSize
            // Then round up to the nearest multiple of terrainSampleSize
            var chunkSizeAlongX = Mathf.CeilToInt(Mathf.Max(desiredChunkSize / (sampleSize.x * terrainSampleSize), MinChunkSize)) * terrainSampleSize;
            var chunkSizeAlongZ = Mathf.CeilToInt(Mathf.Max(desiredChunkSize / (sampleSize.z * terrainSampleSize), MinChunkSize)) * terrainSampleSize;

            for (int z = 0; z < heightmapDepth; z += chunkSizeAlongZ)
            {
                for (int x = 0; x < heightmapWidth; x += chunkSizeAlongX)
                {
                    var width       = Mathf.Min(chunkSizeAlongX, heightmapWidth - x);
                    var depth       = Mathf.Min(chunkSizeAlongZ, heightmapDepth - z);
                    var chunkMin    = offset + new Vector3(z * sampleSize.x, 0, x * sampleSize.z);
                    var chunkMax    = offset + new Vector3((z + depth) * sampleSize.x, sampleSize.y, (x + width) * sampleSize.z);
                    var chunkBounds = new Bounds();
                    chunkBounds.SetMinMax(chunkMin, chunkMax);

                    // Skip chunks that are not inside the desired bounds
                    if (chunkBounds.Intersects(bounds))
                    {
                        var chunk = GenerateHeightmapChunk(heights, sampleSize, offset, x, z, width, depth, terrainSampleSize);
                        result.Add(chunk);
                    }
                }
            }
        }
示例#4
0
 public static Vector2Int CeilToInt(Vector2 v)
 {
     return(new Vector2Int(Mathf.CeilToInt(v.x), Mathf.CeilToInt(v.y)));
 }
示例#5
0
 public void Reset()
 {
     curCount     = StartCount;
     lastIntCount = Mathf.CeilToInt(curCount) + 1;
     UpdateText();
 }
示例#6
0
 void Start()
 {
     curCount     = StartCount;
     lastIntCount = Mathf.CeilToInt(curCount) + 1;
 }
示例#7
0
 private void UpdateText()
 {
     Text = Mathf.CeilToInt(curCount).ToString();
 }