using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RadarPolygon : GamePolygon {

	private Color color;
	private string name;
	private float minDistance;
	private float maxDistance;
	private Vector3 origin;

	public RadarPolygon(SlicedPolygon sliced, string name, float minDistance, float maxDistance, Vector3 origin, Color color) : base(sliced) {
		this.color = color;
		this.name = name;
		this.minDistance = minDistance;
		this.maxDistance = maxDistance * 1.1f;
		this.origin = origin;

		addToGame();
	}

	public override void addToGame() {
		base.addToGame();

		renderer.material = new Material(GameController.fadeMaterial); //TODO : optimize
		renderer.material.color = color;

		gameObject.name = name;
	}

	override protected Vector2[] generateUV(List<Vector3> vertices) {
		Vector2[] uv = new Vector2[vertices.Count];
		for (int j = 0; j < uv.Length; j++) {
			float dist = Mathf.Sqrt(Mathf.Pow(vertices[j].x - origin.x, 2) + Mathf.Pow(vertices[j].y - origin.y, 2));
			uv[j] = new Vector2((dist-minDistance) / (maxDistance - minDistance), 0.5f);

		}

		return uv;
	}
}
