Beispiel #1
0
        void SpawnEnemies(MapChunkData chunkData, MapChunk chunk)
        {
            var budget = CurrentLevelBudget;

            if (chunkData.Enemies != null)
            {
                while (budget > 0)
                {
                    var enemy = chunkData.Enemies.Sample(Level, chunkData.Type, budget);
                    if (enemy == null)
                    {
                        Debug.LogWarning("Cant spawn more enemies");
                        break;
                    }
                    chunk.Spawn(enemy.Prefab);
                    budget -= enemy.BudgetConsume;
                }
            }
        }
Beispiel #2
0
        public void SpawnNextChunk(MapChunkData chunkData)
        {
            if (chunkData == null)
            {
                Debug.LogWarningFormat("Chunk is null");
                return;
            }

            // World-spaced entry position and rotation
            Vector3    entryPosition;
            Quaternion entryRotation;

            if (_lastChunk != null)
            {
                entryPosition = _lastChunk.ExitPosition;
                entryRotation = _lastChunk.ExitRotation;
            }
            else
            {
                entryPosition = transform.position;
                entryRotation = transform.rotation;
            }


            var pMapChunk = chunkData.Prefab.GetComponent <MapChunk>();

            // Instantiate new chunk so that exit of the last chunk matches the entry of the new one
            // Assuming that prefabs are at zero

            /*
             * var chunkObject = Instantiate(chunkData.Prefab,
             *  entryPosition - pMapChunk.EntryPosition,
             *  entryRotation * Quaternion.Inverse(pMapChunk.EntryRotation));
             */

            var entryOffset         = pMapChunk.EntryPosition;
            var entryRotationOffset = pMapChunk.EntryRotation;

            var chunkObject = Instantiate(chunkData.Prefab,
                                          entryPosition + entryRotation * Quaternion.Inverse(entryRotationOffset) * (-pMapChunk.EntryPosition),
                                          entryRotation * Quaternion.Inverse(entryRotationOffset));

            var chunk = chunkObject.GetComponent <MapChunk>();

            if (chunk == null)
            {
                Debug.LogWarning("Failed to instantiate next chunk");
                return;
            }

            chunk.name = $"Chunk_{_chunksSpawned}";



            _lastChunk     = chunk;
            _lastChunkData = chunkData;
            Debugger.Default.Display("Last chunk position", _lastChunk.transform.position.ToString());
            Debugger.Default.DrawCircleSphere(chunk.EntryPosition, 2f, Color.blue, 1000f);
            Debugger.Default.DrawAxis(chunk.EntryPosition, chunk.EntryRotation, 1000f);

            Debugger.Default.DrawCircleSphere(chunk.ExitPosition, 2f, Color.red, 1000f);
            Debugger.Default.DrawAxis(chunk.ExitPosition, chunk.ExitRotation, 1000f);

            Debugger.Default.DrawCircleSphere(chunk.transform.position, 2f, Color.white, 1000f);
            Debugger.Default.DrawAxis(chunk.transform.position, chunk.transform.rotation, 1000f);

            _surface.BuildNavMesh();

            SpawnEnemies(_lastChunkData, _lastChunk);
            _chunksSpawned += 1;
        }