using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class BorderController : MonoBehaviour {
	public bool createBackground = true;

	private LineRenderer line;
	private EdgeCollider2D edge;
	private ObstacleController obstacle;

	// Use this for initialization
	void Start () {
		this.line = this.GetComponent<LineRenderer> ();
		this.edge = this.GetComponent<EdgeCollider2D> ();
		this.obstacle = this.GetComponent<ObstacleController> ();

		this.line.sharedMaterial = GameManager.Instance.lineMaterials [this.obstacle.allowedWaveColor];

		var points = edge.points.Select(p => p + edge.offset).ToArray();
		this.line.positionCount = points.Length;
		for (int i = 0; i < points.Length; i++) {
			this.line.SetPosition (i, points[i]);
		}

		if (this.createBackground == true) {
			var meshFilter = this.GetComponentInChildren<MeshFilter> ();
			var mesh = new Mesh ();
			Triangulator.CreateMeshCool (points, mesh);
			meshFilter.mesh = mesh;
		}
	}
}
