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

namespace Utils.UI {
	public class UICircleSegment : UISegment {


	  /// <summary>
	  /// The rotation of the UICircleSegment in segments
	  /// </summary>
	  public int segmentRotation = 0;

	  private float segRot {
		get { 
		  return (360F / TotalSegments) * segmentRotation;
		}
	  }

	  /// <summary>
	  /// Spawns a segment.
	  /// </summary>
	  /// <param name="prefab">Prefab.</param>
	  /// <param name="yRotation">Y rotation.</param>
	  public override void SpawnSegment(GameObject prefab,int segmentIndex) {
		GameObject segment = Instantiate (prefab, Container.transform.position, prefab.transform.rotation) as GameObject;
		RectTransform rect = segment.GetComponent<RectTransform> ();

		segment.transform.SetParent (Container, true);
		segment.transform.localScale = Vector3.one;
		Image img = segment.GetComponent<Image> ();
		//rect.rotation = Quaternion.Euler (0, 0, -(segmentIndex * (partL+(2*Padding))*360)+segRot);


	 	rect.RotateAroundLocal(Vector3.forward,(-(segmentIndex * (partL+(2*Padding))*360)+segRot)*Mathf.Deg2Rad);

		ApplyColor (segment, segmentIndex);

		img.fillAmount = partL;
		Segments.Add (img);
		OriginalPositions.Add (img.rectTransform.localScale);
	  }

	}

}
