Пример #1
0
        /// <summary>
        /// Create the terrain defined by these settings - and apply the resources to it
        /// </summary>
        public void CreateTerrain(GaiaResource resources)
        {
            Terrain[,] world;

            //Update the resouces ny associating them with their assets
            resources.AssociateAssets();

            //Update the session
            GaiaSessionManager sessionMgr = GaiaSessionManager.GetSessionManager();

            if (sessionMgr != null && sessionMgr.IsLocked() != true)
            {
                //Update terrain settings in session
                sessionMgr.m_session.m_terrainWidth  = m_tilesX * m_terrainSize;
                sessionMgr.m_session.m_terrainDepth  = m_tilesZ * m_terrainSize;
                sessionMgr.m_session.m_terrainHeight = m_terrainHeight;

                //Add the defaults
                sessionMgr.AddDefaults(this);

                //Set the sea level - but only if it is zero - if not zero then its been deliberately set
                if (Gaia.GaiaUtils.Math_ApproximatelyEqual(sessionMgr.m_session.m_seaLevel, 0f))
                {
                    sessionMgr.SetSeaLevel(m_seaLevel);
                }

                //Grab the resources scriptable object
                sessionMgr.AddResource(resources);

                //Adjust them if they are different to the defaults
                resources.ChangeSeaLevel(sessionMgr.m_session.m_seaLevel);

                //Then add the operation
                sessionMgr.AddOperation(GetTerrainCreationOperation(resources));
            }

            //Create the terrains array
            world = new Terrain[m_tilesX, m_tilesZ];

            //And iterate through and create each terrain
            for (int x = 0; x < m_tilesX; x++)
            {
                for (int z = 0; z < m_tilesZ; z++)
                {
                    CreateTile(x, z, ref world, resources);
                }
            }

            //Now join them together and remove their seams
            RemoveWorldSeams(ref world);
        }