/// <summary>
        /// Adds the passed tile to the active tiles list. If
        /// the passed tile is not active, it is made active.
        /// </summary>
        /// <param name="tile">Tile to activate</param>
        public void AddActiveTile(Tile tile)
        {
            tile.gameObject.SetActive(true);
            ActiveTiles.Add(tile);

            TerraEvent.TriggerOnTileActivated(tile);
        }
        /// <summary>
        /// Adds the passed Tile to the tile cache. This
        /// deactivates the passed tile and will no longer be rendered
        /// until pulled from the cache.
        /// </summary>
        /// <param name="tile">Tile to cache</param>
        public void CacheTile(Tile tile)
        {
            tile.gameObject.SetActive(false);
            _cachedTiles.AddFirst(tile);
            EnforceCacheSize();

            TerraEvent.TriggerOnTileDeactivated(tile);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Applies the custom material specified in TerraSettings to the associated TerrainObject.
        /// </summary>
        /// <param name="mat">Custom material to apply</param>
        public void ApplyCustomMaterial()
        {
            TerraEvent.TriggerOnCustomMaterialWillApply(gameObject);

            MeshRenderer mr = GetComponent <MeshRenderer>();

            mr.sharedMaterial = Settings.CustomMaterial;
            TerraEvent.TriggerOnCustomMaterialDidApply(gameObject);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Generates and applies new MeshCollider for the tile if no collider
        /// exists currently or <code>IsColliderDirty</code> is true.
        /// </summary>
        public void GenerateCollider()
        {
            if (gameObject.GetComponent <MeshCollider>() == null || IsColliderDirty)
            {
                MeshCollider collider = gameObject.AddComponent <MeshCollider>();
                collider.sharedMesh = Terrain;

                TerraEvent.TriggerOnMeshColliderDidForm(gameObject, collider);
            }
        }
        /// <summary>
        /// Calculates and applies a new MeshCollider for the tile if no collider
        /// exists currently or <code>IsColliderDirty</code> is true.
        /// </summary>
        public void CalculateCollider()
        {
            if (_tile.GetComponent <MeshCollider>() == null || _tile.IsColliderDirty)
            {
                MeshCollider collider = _tile.gameObject.AddComponent <MeshCollider>();
                collider.sharedMesh = ActiveMesh;

                TerraEvent.TriggerOnMeshColliderDidForm(_tile.gameObject, collider);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a Mesh with the length and resolution specified in
        /// TerraSettings. Applies heights found in the passed Generator param.
        /// To generate a mesh off of the main thread, use <see cref="CreateRawMesh(Vector2, Generator)"/>
        /// <list type="bullet">
        /// <item><description>Cannot be called off of the main thread</description></item>
        /// <item><description>Does not generate a MeshCollider, call <code>GenerateCollider</code> instead.</description></item>
        /// <item><description>Creates and attaches a MeshRenderer</description></item>
        /// </list>
        /// </summary>
        /// <param name="position">Position to place Mesh in the tile grid</param>
        /// <param name="generator">CoherentNoise generator used for applying noise values</param>
        /// <param name="renderOnCreation">If true, the attached MeshRenderer will be enabled after the mesh has been formed.
        /// Otherwise, the attached MeshRenderer will be disabled by default.</param>
        public void CreateMesh(Vector2 position, Generator generator, bool renderOnCreation = true)
        {
            TerraEvent.TriggerOnMeshWillForm(gameObject);

            MeshRenderer renderer = gameObject.AddComponent <MeshRenderer>();

            renderer.material = new Material(Shader.Find("Diffuse"));
            renderer.enabled  = renderOnCreation;
            Terrain           = gameObject.AddComponent <MeshFilter>().mesh;

            MeshData md = CreateRawMesh(position, generator);

            Terrain.vertices  = md.vertices;
            Terrain.triangles = md.triangles;
            Terrain.uv        = md.uvs;
            Terrain.normals   = md.normals;

            UpdatePosition(position);
        }