예제 #1
0
        private void OnDestroy()
        {
            SaveChunkData();

            PathFinding.Dispose();
            WorldSettings.Dispose();

            // dispose native containers
            pendingJobs.Dispose();
            meshBakingJobs.Dispose();
        }
        private void Awake()
        {
            // Singleton
            if (Instance)
            {
                Destroy(this);
            }
            else
            {
                Instance = this;
            }

            WorldSettings.Init();

            // instantiate player gameobject
            GameObject playerObject = Instantiate(Instance.playerPrefab);

            playerObject.SetActive(false);

            RenderDistance         = (int)Settings.GetSetting(SettingsType.RENDER_DISTANCE);
            maxChunksToBuildAtOnce = (int)Settings.GetSetting(SettingsType.MAX_CHUNKS_TO_BUILD_AT_ONCE);

            TotalChunks = 4 * RenderDistance * RenderDistance;

            PathFinding.Init();

            // TODO: enable this later
            //LoadChunkData();

            // TODO: enable this later
            //player.eulerAngles = new Vector3(player.eulerAngles.x, worldSave.playerEulerY, player.eulerAngles.z);
            //player.position = worldSave.playerPosition.ToVector3();

            // TODO: seed is always the same
            Seed = UnityEngine.Random.Range(0, int.MaxValue);
            //Seed = 420;
            FastNoise = new FastNoise(Seed, 0.005f);

            // init native conainters
            chunkBuildingJobs = new NativeQueue <JobHandle>(Allocator.Persistent);
            meshBakingJobs    = new NativeQueue <JobHandle>(Allocator.Persistent);
        }
        public void DisposeAndSave()
        {
            SaveChunkData();

            // dispose all active & pooled chunks
            foreach (var chunk in Chunks.Values)
            {
                chunk.Dispose();
            }
            foreach (var chunk in pooledChunks)
            {
                chunk.Dispose();
            }

            PathFinding.Dispose();
            WorldSettings.Dispose();

            // dispose native containers
            chunkBuildingJobs.Dispose();
            meshBakingJobs.Dispose();
        }