using UnityEngine;
using UnityEditor;
using System.Collections;

public class EditorStuff {
	
	[MenuItem ("Window/Spline Tools/Smooth Spline &s")]
	public static void SmoothSplinePositions()
	{
		GameObject go = Selection.activeGameObject;
		if(go == null) { return; }
		CurvySpline spline = go.GetComponent<CurvySpline> ();
		if(spline == null) { return; }
		Vector3[] splineSegmentPositions = new Vector3[spline.transform.childCount];
		for (int i=0; i<spline.transform.childCount; i++) {
			splineSegmentPositions[i] = spline.transform.GetChild(i).position;
		}
		
		splineSegmentPositions = SplineGenerator.SmoothSplinePositions (splineSegmentPositions, 0.5f);
		
		for(int i=0; i<splineSegmentPositions.Length; i++)
		{
			spline.transform.GetChild(i).position = splineSegmentPositions[i];
		}
	}

	[MenuItem ("Window/Spline Tools/Smooth Spline &r")]
	public static void RelaxSplinePositions()
	{
		GameObject go = Selection.activeGameObject;
		if(go == null) { return; }
		CurvySpline spline = go.GetComponent<CurvySpline> ();
		if(spline == null) { return; }
		Vector3[] splineSegmentPositions = new Vector3[spline.transform.childCount];
		for (int i=0; i<spline.transform.childCount; i++) {
			splineSegmentPositions[i] = spline.transform.GetChild(i).position;
		}
		
		splineSegmentPositions = SplineGenerator.RelaxSplinePositions (splineSegmentPositions, 0.5f);
		
		for(int i=0; i<splineSegmentPositions.Length; i++)
		{
			spline.transform.GetChild(i).position = splineSegmentPositions[i];
		}
	}
}
