コード例 #1
0
        /// <summary>
        /// Called by Voxel Play to inform that player has moved onto another chunk so new detail can start generating
        /// </summary>
        /// <param name="currentPosition">Current player position.</param>
        /// <param name="checkOnlyBorders">True means the player has moved to next chunk. False means player position is completely new and all chunks in
        /// range should be checked for detail in this call.</param>
        /// <param name="position">Position.</param>
        public override void ExploreArea(Vector3 position, bool checkOnlyBorders)
        {
            int     explorationRange = env.visibleChunksDistance + 10;
            int     minz             = -explorationRange;
            int     maxz             = +explorationRange;
            int     minx             = -explorationRange;
            int     maxx             = +explorationRange;
            Vector3 pos = position;

            for (int z = minz; z <= maxz; z++)
            {
                for (int x = minx; x < maxx; x++)
                {
                    if (checkOnlyBorders && z > minz && z < maxz && x > minx && x < maxx)
                    {
                        continue;
                    }
                    pos.x = position.x + x * 16;
                    pos.z = position.z + z * 16;
                    pos   = env.GetChunkPosition(pos);
                    if (WorldRand.GetValue(pos) > 0.98f)
                    {
                        BuildingStatus bs;
                        if (!buildingPositions.TryGetValue(pos, out bs))
                        {
                            float h = env.GetTerrainHeight(pos, false);
                            if (h > env.waterLevel)
                            {
                                bs.height          = h;
                                bs.placementStatus = false;

                                // No trees on this chunk
                                VoxelChunk chunk;
                                env.GetChunk(pos, out chunk, false);
                                if (chunk != null)
                                {
                                    chunk.allowTrees = false;
                                }
                            }
                            else
                            {
                                bs.placementStatus = true;
                            }
                            buildingPositions[pos] = bs;
                        }
                    }
                }
            }
        }
コード例 #2
0
        void ManageItem()
        {
            if (env == null)
            {
                return;
            }

            Vector3 currentPosition = transform.position;

            if (lastChunk != null && lastChunk.isRendered)
            {
                if (currentPosition == lastPosition)
                {
                    return;
                }
                lastPosition = currentPosition;
            }

            // Update lighting
            if (mat != null)
            {
                mat.SetFloat("_VoxelLight", env.GetVoxelLight(currentPosition));
            }

            // Update owner chunk
            VoxelChunk currentChunk;

            if (!env.GetChunk(currentPosition, out currentChunk, true))
            {
                return;
            }
            if (currentChunk != lastChunk)
            {
                if (lastChunk != null)
                {
                    lastChunk.RemoveItem(this);
                }
                currentChunk.AddItem(this);
                lastChunk = currentChunk;
            }

            if (currentChunk.isRendered && rb != null && !rb.useGravity)
            {
                rb.useGravity = true;
            }
        }
コード例 #3
0
        IEnumerator Consolidate()
        {
            if (gameObject == null)
            {
                yield break;
            }
            WaitForSeconds       w = new WaitForSeconds(1f);
            VoxelChunk           targetChunk;
            VoxelPlayEnvironment env = VoxelPlayEnvironment.instance;

            if (env.GetChunk(transform.position, out targetChunk, false))
            {
                const float maxDist = 100 * 100;
                while (FastVector.SqrDistanceByValue(targetChunk.position, env.cameraMain.transform.position) < maxDist && env.ChunkIsInFrustum(targetChunk))
                {
                    yield return(w);
                }
                env.VoxelCancelDynamic(this);
            }
        }
コード例 #4
0
        void Start()
        {
            rb = GetComponent <Rigidbody> ();
            if (rb == null || rb.isKinematic)
            {
                return;
            }

            // If chunk is not rendered and have a rigidbody, wait until ready
            env = VoxelPlayEnvironment.instance;
            if (env == null)
            {
                return;
            }

            VoxelChunk chunk;

            if (!env.GetChunk(transform.position, out chunk, false) || !chunk.isRendered)
            {
                rb.isKinematic = true;
                StartCoroutine(WaitForChunk(chunk));
            }
        }
コード例 #5
0
        /// <summary>
        /// Called by Voxel Play to inform that player has moved onto another chunk so new detail can start generating
        /// </summary>
        /// <param name="position">Current player position.</param>
        /// <param name="checkOnlyBorders">True means the player has moved to next chunk. False means player position is completely new and all chunks in
        /// range should be checked for detail in this call.</param>
        /// <param name="endTime">Provides a maximum time frame for execution this frame. Compare this with env.stopwatch milliseconds.</param>
        public override void ExploreArea(Vector3 position, bool checkOnlyBorders, long endTime)
        {
            float prob             = Mathf.Clamp01(1f - spawnProbability);
            int   explorationRange = env.visibleChunksDistance + 10;
            int   minz             = -explorationRange;
            int   maxz             = +explorationRange;
            int   minx             = -explorationRange;
            int   maxx             = +explorationRange;

            position = env.GetChunkPosition(position);
            Vector3 pos  = position;
            bool    temp = true;

            for (int z = minz; z <= maxz; z++)
            {
                for (int x = minx; x < maxx; x++)
                {
                    if (checkOnlyBorders && z > minz && z < maxz && x > minx && x < maxx)
                    {
                        continue;
                    }
                    pos.x = position.x + x * VoxelPlayEnvironment.CHUNK_SIZE;
                    pos.z = position.z + z * VoxelPlayEnvironment.CHUNK_SIZE;
                    temp  = true;
                    foreach (KeyValuePair <Vector3, BuildingStatus> kv in buildingPositions)
                    {
                        if (pos != kv.Key)
                        {
                            if (Vector3.Distance(pos, kv.Key) < spawnDistance)
                            {
                                temp = false;
                                break;
                            }
                        }
                    }
                    if (WorldRand.GetValue(pos) > prob && temp)
                    {
                        BuildingStatus bs;
                        if (!buildingPositions.TryGetValue(pos, out bs))
                        {
                            float h = env.GetTerrainHeight(pos, false);



                            if (h > env.waterLevel)
                            {
                                //added -5
                                bs.height          = h - 5;
                                bs.placementStatus = false;

                                // No trees on this chunk
                                VoxelChunk chunk;
                                env.GetChunk(pos, out chunk, false);
                                if (chunk != null)
                                {
                                    chunk.allowTrees = false;
                                }
                            }
                            else
                            {
                                bs.placementStatus = true;
                            }
                            if (temp)
                            {
                                buildingPositions[pos] = bs;
                            }
                        }
                    }
                }
            }
        }